import { fetchCompanyDetails, fetchCompanys } from "@/app/api/companys";
import CreateCompany from "./CreateCompany";

type CreateCompanyProps = { isEdit: false }
interface EditCompanyProps {
    isEdit: true;
    companyId?: string;
}

type Props = CreateCompanyProps | EditCompanyProps;

const CreateCompanyWrapper: React.FC<Props> = async (props) => {

    // console.log(props)

    const companyDetails = props.isEdit
        ? await fetchCompanyDetails(props.companyId!)
        : undefined;
    const [company] = await Promise.all([fetchCompanys()])
    console.log(company)
    return (
        <CreateCompany companyCodes={Boolean(companyDetails) ? company.map(c => c.companyCode.toLowerCase().trim()).filter(ele => ele !== companyDetails?.companyCode.toLowerCase().trim()) : company.map(c => c.companyCode.toLowerCase().trim())} isEdit company={companyDetails}
        />
    )
}

export default CreateCompanyWrapper;