import GeneralLoading from "@/components/General/GeneralLoading";
import DetailedScheduleDetailView from "@/components/DetailedScheduleDetail/DetailedScheduleDetailView";
import { ScheduleType, fetchDetailedProdScheduleDetail } from "@/app/api/scheduling";

interface SubComponents {
  Loading: typeof GeneralLoading;
}

type EditDetailedScheduleDetailProps = {
  id?: number;
  type: ScheduleType;
};

type Props = EditDetailedScheduleDetailProps;

const DetailedScheduleDetailWrapper: React.FC<Props> & SubComponents = async ({
  id,
  type,
}) => {
  // const defaultValues = {
  //   id: 1,
  //   productionDate: "2025-05-07",
  //   totalJobOrders: 13,
  //   totalProductionQty: 21000,
  // };

  const prodSchedule = id ? await fetchDetailedProdScheduleDetail(id) : undefined

  if (prodSchedule) {
    prodSchedule.prodScheduleLines = prodSchedule.prodScheduleLines.sort((a, b) => b.priority - a.priority)
  }
  return (
    <DetailedScheduleDetailView
      isEditMode={Boolean(id)}
      defaultValues={prodSchedule}
      type={type}
      // qcChecks={qcChecks || []}
    />
  );
};

DetailedScheduleDetailWrapper.Loading = GeneralLoading;

export default DetailedScheduleDetailWrapper;
