import React from "react";
import GeneralLoading from "../General/GeneralLoading";
import JoSearch from "./JoSearch";
import { SearchJoResultRequest } from "@/app/api/jo/actions";
import { fetchBomCombo } from "@/app/api/bom";
import { fetchPrinterCombo } from "@/app/api/settings/printer";
import { fetchAllJobTypes } from "@/app/api/jo/actions";
interface SubComponents {
    Loading: typeof GeneralLoading;
}

const JoSearchWrapper: React.FC & SubComponents = async () => {
    const today = new Date();
    const todayStr = today.toISOString().split('T')[0];

    const defaultInputs: SearchJoResultRequest = {
        code: "",
        itemName: "",
        planStart: `${todayStr}T00:00`,
        planStartTo: `${todayStr}T23:59:59`,
        joSearchStatus: "all",

    }

    const [
        bomCombo,
        printerCombo,
        jobTypes
    ] = await Promise.all([
        fetchBomCombo(),
        fetchPrinterCombo(),
        fetchAllJobTypes()
    ])
    
    return <JoSearch defaultInputs={defaultInputs} bomCombo={bomCombo} printerCombo={printerCombo} jobTypes={jobTypes}/>
}

JoSearchWrapper.Loading = GeneralLoading;

export default JoSearchWrapper;