"use client";

import DynamicFormBuilder from "@/components/forms/DynamicFormBuilder";
import FormFooter from "@/components/ui/FormFooter";
import type { TCreateCompanyCategoryCredentials } from "@/lib/api";
import { createCompanyCategoryFormSections } from "./companyCategoryFormSections";
import useCreateCompanyCategoryPresenter from "./useCreateCompanyCategoryPresenter";

interface IProps {
  editMode?: boolean;
  defaultValues?: TCreateCompanyCategoryCredentials;
  id?: string;
}

const CreateCompanyCategoryForm = ({ defaultValues, editMode, id }: IProps) => {
  const { errors, handleSubmit, onSubmit, register, control } =
    useCreateCompanyCategoryPresenter({ defaultValues, editMode, id });

  return (
    <DynamicFormBuilder<TCreateCompanyCategoryCredentials>
      sections={createCompanyCategoryFormSections(editMode)}
      register={register}
      control={control}
      errors={errors}
      handleSubmit={handleSubmit}
      onSubmit={onSubmit}
      dataCy="company-category-form"
      footer={<FormFooter />}
    />
  );
};

export default CreateCompanyCategoryForm;
