import { fetchAllItems } from "@/app/api/settings/item";
// import ItemsSearch from "./ItemsSearch";
// import ItemsSearchLoading from "./ItemsSearchLoading";
import { SearchParams } from "@/app/utils/fetchUtil";
import { TypeEnum } from "@/app/utils/typeEnum";
import { notFound } from "next/navigation";
import PoSearchLoading from "./PoSearchLoading";
import PoSearch from "./PoSearch";
import { fetchPoList, PoResult } from "@/app/api/po";
import dayjs from "dayjs";
import arraySupport from "dayjs/plugin/arraySupport";
import { OUTPUT_DATE_FORMAT } from "@/app/utils/formatUtil";
import { fetchWarehouseList } from "@/app/api/warehouse";
dayjs.extend(arraySupport);

interface SubComponents {
  Loading: typeof PoSearchLoading;
}

type Props = {
  // type: TypeEnum;
};

const PoSearchWrapper: React.FC<Props> & SubComponents = async (
  {
    // type,
  }
) => {
  const [
    po,
    warehouse,
  ] = await Promise.all([
    fetchPoList(),
    fetchWarehouseList(),
  ]);
  console.log(po)
  const fixPoDate = po.map((p) => {
    return ({
      ...p,
      orderDate: dayjs(p.orderDate).format(OUTPUT_DATE_FORMAT)
    })
  })
  return <PoSearch po={fixPoDate} warehouse={warehouse}/>;
};

PoSearchWrapper.Loading = PoSearchLoading;

export default PoSearchWrapper;
