import React from "react";
import GenerateProjectPotentialDelayReportLoading from "./GenerateProjectPotentialDelayReportLoading";
import GenerateProjectPotentialDelayReport from "./GenerateProjectPotentialDelayReport";
import { fetchTeam } from "@/app/api/team";
import { fetchAllCustomers } from "@/app/api/customer";
import { fetchAllSubsidiaries } from "@/app/api/subsidiary";
import { fetchUserStaff } from "@/app/utils/fetchUtil";

interface SubComponents {
  Loading: typeof GenerateProjectPotentialDelayReportLoading;
}

const GenerateProjectPotentialDelayReportWrapper: React.FC & SubComponents = async () => {
  const [teams, clients, subsidiaries, userStaff] = await Promise.all([fetchTeam(), fetchAllCustomers(), fetchAllSubsidiaries(), fetchUserStaff()])

  return <GenerateProjectPotentialDelayReport teams={!Boolean(userStaff?.isTeamLead) ? teams : teams.filter(team => team.id === userStaff?.teamId)} clients={clients} subsidiaries={subsidiaries} userStaff={userStaff}/>;
};

GenerateProjectPotentialDelayReportWrapper.Loading = GenerateProjectPotentialDelayReportLoading;

export default GenerateProjectPotentialDelayReportWrapper;