import { TypeEnum } from "@/app/utils/typeEnum";
import CreateEquipment from "./CreateEquipment";
import CreateEquipmentLoading from "./CreateEquipmentLoading";
import { CreateEquipmentInputs } from "@/app/api/settings/equipment/actions";
import { notFound } from "next/navigation";
import { fetchEquipment } from "@/app/api/settings/equipment";
interface SubComponents {
  Loading: typeof CreateEquipmentLoading;
}

type Props = {
  id?: number;
  // type: TypeEnum;
};

const CreateEquipmentWrapper: React.FC<Props> & SubComponents = async ({
  id,
}) => {
  let result;
  let defaultValues: Partial<CreateEquipmentInputs> | undefined;
  // console.log(type)
  let qcChecks;
  if (id) {
    result = await fetchEquipment(id);
    const equipment = result;
    console.log(equipment);
    defaultValues = {
      id: equipment?.id,
      code: equipment?.code,
      name: equipment?.name,
      description: equipment?.description,
      equipmentTypeId: equipment?.equipmentTypeId,
    };
  }

  return (
    <CreateEquipment isEditMode={Boolean(id)} defaultValues={defaultValues} />
  );
};
CreateEquipmentWrapper.Loading = CreateEquipmentLoading;

export default CreateEquipmentWrapper;
