import { useOrganizations } from "@/super-admin/hooks/useOrganizations";
import { OrganizationPayload } from "@/shared/services/organizationsService";

import OrganizationForm, { FormValues } from "./common/OrganizationForm";

export const NewOrganizationForm = () => {
  const { createOrganization, isCreating } = useOrganizations("Org");

  const onSubmit = (values: FormValues) => {
    const requestData: OrganizationPayload = {
      key: values.key,
      name: values.name,
      organizationTypeId: values.organizationTypeId,
      isGovernmentOrganization: values.isGovernmentOrganization,
    };
    if (values.parentId && values.parentId !== "") {
      requestData["parentId"] = values.parentId;
    }
    createOrganization(requestData);
  };

  return (
    <OrganizationForm
      isLoading={isCreating}
      onSubmit={(values: FormValues) => onSubmit(values)}
      type="Create"
    />
  );
};
