import { ForwardedRef, useImperativeHandle } from "react";
import { useForm } from "react-hook-form";
import useReportStepValidity from "./useReportStepValidity";

interface FooterFormValues {
  email: string;
  phone: string;
  location: string;
  tagline: string;
  copyright: string;
}

const useFooterStepPresenter = (
  initialData?: FooterFormValues,
  ref?: ForwardedRef<unknown>,
  onValidityChange?: (valid: boolean) => void,
) => {
  const {
    register,
    handleSubmit,
    formState: { errors, isValid },
    getValues,
    trigger,
  } = useForm<FooterFormValues>({
    defaultValues: initialData,
    mode: "onChange",
  });

  useReportStepValidity(isValid, onValidityChange);

  const onSubmit = (data: FooterFormValues) => {
    console.log(data);
  };

  useImperativeHandle(ref, () => ({
    getData: () => getValues(),
    validate: () => trigger(),
  }));

  return {
    register,
    handleSubmit,
    onSubmit,
    errors,
  };
};

export default useFooterStepPresenter;
