"use client";

import DynamicFormBuilder from "@/components/forms/DynamicFormBuilder";
import FormFooter from "@/components/ui/FormFooter";
import { ICreateAdminCredentials } from "@/lib/api";
import type { FC } from "react";
import useCreateAdminPresenter, {
  type CreateAdminFormValues,
} from "./useCreateAdminPresenter";

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

const CreateAdminForm: FC<IProps> = ({ defaultValues, editMode, id }) => {
  const presenter = useCreateAdminPresenter({ editMode, defaultValues, id });
  const { errors, handleSubmit, register, control, onSubmit, sections } =
    presenter;

  return (
    <DynamicFormBuilder<CreateAdminFormValues>
      sections={sections}
      register={register}
      control={control}
      errors={errors}
      handleSubmit={handleSubmit}
      onSubmit={onSubmit}
      dataCy={editMode ? "admin-edit-form" : "admin-create-form"}
      footer={<FormFooter />}
    />
  );
};

export default CreateAdminForm;
