"use client";

import { useState } from "react";
import { useForm } from "react-hook-form";

const useServicesForm = () => {
  const [triggerAlert, setTriggerAlert] = useState(false);
  const [disableScaling, setDisableScaling] = useState(true);
  const [disableReadiness, setDisableReadiness] = useState(true);
  const [disableLiveness, setDisableLiveness] = useState(true);
  const {
    register,
    handleSubmit,
    watch,
    reset,
    formState: { errors },
  } = useForm({
    defaultValues: {
      minPods: "",
      maxPods: "",
      readinessPath: "",
      readinessPort: "",
      livenessPath: "",
      livenessPort: "",
    },
  });

  const minPods = watch("minPods");
  const maxPods = watch("maxPods");
  const readinessPath = watch("readinessPath");
  const readinessPort = watch("readinessPort");
  const livenessPath = watch("livenessPath");
  const livenessPort = watch("livenessPort");

  const onSubmit = (data) => {
    setTriggerAlert(true);

    console.log("Submitted data:", data);
  };

  return {
    register,
    handleSubmit,
    watch,
    errors,
    onSubmit,
    triggerAlert,
    setTriggerAlert,
    setDisableScaling,
    disableScaling,
    setDisableReadiness,
    disableReadiness,
    setDisableLiveness,
    disableLiveness,
    minPods,
    maxPods,
    readinessPath,
    readinessPort,
    livenessPort,
    livenessPath,
  };
};

export default useServicesForm;
