import _variants from "@/components/ui/button/_variants";
import { UploadProjectSchema } from "@/schemas/files/_uploadProject";
import { FormBuilderElement } from "@/types/app-component-formbuilder";
import { faHome } from "@fortawesome/free-solid-svg-icons";
import { UseFormReturn } from "react-hook-form";

type Field = FormBuilderElement<UploadProjectSchema, typeof _variants>;

type UploadProjectFormFieldsProps = {
  form: UseFormReturn<UploadProjectSchema>;
  closeModal: (id: string) => void;
  isPending: boolean;
  dict: Dictionary;
};
export default function getUploadProjectFormFields({
  form,
  closeModal,
  isPending,
  dict,
}: UploadProjectFormFieldsProps) {
  const fields = [
    {
      type: "text",
      label: dict.pages.project_list.form.fields.project_name.label,
      required: true,
      className: "w-full",
      name: "name",
      icon: faHome,
      errors: dict.pages.project_list.form.fields.project_name.errors,
    },
    {
      type: "text",
      label: "Email",
      className: "w-full",
      name: "email",
    },
    {
      type: "file",
      label: dict.pages.project_list.form.fields.project_file.label,
      required: true,
      name: "file",
      errors: dict.pages.project_list.form.fields.project_file.errors,
    },
    {
      type: "checkbox",
      label: dict.pages.project_list.form.fields.is_ready.label,
      className: "w-full",
      name: "ready",
    },
    !form.getValues("ready") && {
      type: "textarea",
      label: dict.pages.general.note,
      className:
        "w-full animate-[textarea-h-0-to-min_200ms_linear] [&_textarea]:h-full",
      name: "note",
    },
    {
      type: "group",
      className: "w-full flex justify-end gap-2",
      fields: [
        {
          type: "button",
          label: dict.pages.general.close,
          variant: "solid",
          color: "danger",
          onClick: () => closeModal("upload-project-form"),
          required: true,
        },
        {
          type: "submit",
          label: dict.pages.general.upload,
          variant: "solid",
          color: "primary",
          disabled: isPending,
          required: true,
        },
      ],
    },
  ].filter(Boolean) as Field[];

  return fields;
}
