// components/header/settingsModal/hooks/useSystemSettings.ts
import { useState, useEffect } from "react";
import { useSelector } from "react-redux";
import { RootState } from "../../../../redux/store";
export function useSystemSettings(showModal: boolean) {
  const settings = useSelector((state: RootState) => state.systemSettings);
  const [formValues, setFormValues] = useState(settings);
  const [originalValues, setOriginalValues] = useState({});

  useEffect(() => {
    if (showModal) {
      setFormValues(settings);
      setOriginalValues({
        name: settings.deviceName,
        mac1: settings.mac1,
        ip: settings.ip,
        subnet: settings.subnet,
        gateway: settings.gateway,
        systemUhr: settings.cplInternalTimestamp,
        ntp1: settings.ntp1,
        ntp2: settings.ntp2,
        ntp3: settings.ntp3,
        ntpTimezone: settings.ntpTimezone,
        active: settings.ntpActive,
      });
    }
  }, [showModal, settings]);

  return { formValues, setFormValues, originalValues };
}
