"use client";
import { forwardRef } from "react";
import SectionStep from "./SectionStep";
import useBenefitsStepPresenter, {
  IBenefitsStepFields,
} from "./useBenefitsStepPresenter";

interface BenefitsStepProps {
  initialData?: IBenefitsStepFields;
  onValidityChange?: (valid: boolean) => void;
}

const BenefitsStep = forwardRef<unknown, BenefitsStepProps>(({ initialData, onValidityChange }, ref) => {
  const {
    errors,
    handleSubmit,
    onSubmit,
    register,
    fields,
    append,
    remove,
    control,
  } = useBenefitsStepPresenter(initialData, ref, onValidityChange);

  return (
    <SectionStep<IBenefitsStepFields>
      title="Benefits"
      fields={fields}
      handleSubmit={handleSubmit}
      onSubmit={onSubmit}
      register={register}
      errors={errors}
      append={append}
      remove={remove}
      control={control}
      fieldName="cards"
      defaultValues={{ icon: "", title: "", description: "" }}
    />
  );
});

BenefitsStep.displayName = "BenefitsStep";

export default BenefitsStep;
