import React from "react";
import GeneralLoading from "../General/GeneralLoading";
import { fetchDoDetail } from "@/app/api/do/actions";
import DoDetail from "./DoDetail";

interface SubComponents {
    Loading: typeof GeneralLoading;
}

type DoDetailProps = {
    id?: number;
    /** When true (e.g. `/doworkbench/edit`), Release uses workbench `delivery_order_pick_order` async V2 + job progress. */
    workbenchRelease?: boolean;
}

type Props = DoDetailProps

const DoDetailWrapper: React.FC<Props> & SubComponents = async ({
    id,
    workbenchRelease = false,
}) => {
    const doDetail = id ? await fetchDoDetail(id) : undefined

    return <DoDetail id={id} defaultValues={doDetail} workbenchRelease={workbenchRelease} />
}

DoDetailWrapper.Loading = GeneralLoading;

export default DoDetailWrapper;