"use client";
import { useFieldArray, useForm } from "react-hook-form";

export interface IChartStepFields {
  chart_title: string;
  lost_amount: number;
  chart_points: { x: string; y: number }[];
}

const useChartStepPresenter = () => {
  const {
    register,
    handleSubmit,
    control,
    watch,
    formState: { errors },
  } = useForm<IChartStepFields>({
    defaultValues: {
      chart_points: [{ x: "", y: 0 }],
    },
  });

  const { fields, append, remove } = useFieldArray({
    control,
    name: "chart_points",
  });

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

  return {
    register,
    handleSubmit,
    errors,
    onSubmit,
    fields,
    append,
    remove,
    control,
    watch,
  };
};

export default useChartStepPresenter;
