import { TypeEnum } from "@/app/utils/typeEnum";
import CreateEquipmentType from "./CreateEquipmentType";
import CreateEquipmentTypeLoading from "./CreateEquipmentTypeLoading";
import { CreateEquipmentTypeInputs } from "@/app/api/settings/equipmentType/actions";
import { notFound } from "next/navigation";
import { fetchEquipmentType } from "@/app/api/settings/equipmentType";
interface SubComponents {
  Loading: typeof CreateEquipmentTypeLoading;
}

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

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

  return (
    <CreateEquipmentType
      isEditMode={Boolean(id)}
      defaultValues={defaultValues}
    />
  );
};
CreateEquipmentTypeWrapper.Loading = CreateEquipmentTypeLoading;

export default CreateEquipmentTypeWrapper;
