"use client";
import { forwardRef, useImperativeHandle } from "react";
import SectionStep from "./SectionStep";
import useFeaturesStepPresenter, {
  IFeaturesStepFields,
} from "./useFeaturesStepPresenter";

interface FeaturesStepProps {
  initialData?: IFeaturesStepFields;
}

const FeaturesStep = forwardRef<unknown, FeaturesStepProps>(
  ({ initialData }, ref) => {
    const {
      errors,
      handleSubmit,
      onSubmit,
      register,
      fields,
      append,
      remove,
      control,
      getValues,
    } = useFeaturesStepPresenter(initialData);

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

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

FeaturesStep.displayName = "FeaturesStep";

export default FeaturesStep;
