"use client";

import DynamicFormBuilder from "@/components/forms/DynamicFormBuilder";
import FormFooter from "@/components/ui/FormFooter";
import type { TCreateNotificationCredentials } from "@/lib/api/types/NotificationHistory";
import { createNotificationFormSections } from "./notificationFormSections";
import useCreateNotificationFormPresenter from "./useCreateNotificationFormPresenter";

const CreateNotificationForm = () => {
  const {
    register,
    errors,
    control,
    handleSubmit,
    recipient,
    onSubmit,
    onSelectTarget,
    onSearchRecipient,
    onLoadMoreRecipients,
    hasMoreRecipients,
    isLoadingMoreRecipients,
    isLoadingRecipients,
    priorities,
    targets,
    types,
    channels,
  } = useCreateNotificationFormPresenter();

  return (
    <DynamicFormBuilder<TCreateNotificationCredentials>
      sections={createNotificationFormSections({
        recipient,
        onSelectTarget,
        onSearchRecipient,
        onLoadMoreRecipients,
        hasMoreRecipients,
        isLoadingMoreRecipients,
        isLoadingRecipients,
        priorities,
        targets,
        types,
        channels,
      })}
      register={register}
      control={control}
      errors={errors}
      handleSubmit={handleSubmit}
      onSubmit={onSubmit}
      footer={<FormFooter />}
    />
  );
};

export default CreateNotificationForm;
