import { fetchProjectsLateStart } from "@/app/api/report";
import React from "react";
import LateStartReportGen from "./LateStartReportGen";
import LateStartReportGenLoading from "./LateStartReportGenLoading";
import { fetchAllCustomers } from "@/app/api/customer";
import { fetchAllSubsidiaries } from "@/app/api/subsidiary";
import { fetchUserStaff } from "@/app/utils/fetchUtil";
import { fetchTeam } from "@/app/api/team";

interface SubComponents {
  Loading: typeof LateStartReportGenLoading;
}

const LateStartReportGenWrapper: React.FC & SubComponents = async () => {
  const [clentprojects, customers, subsidiaries, userStaff, teams] = await Promise.all([
    fetchProjectsLateStart(), 
    fetchAllCustomers(),
    fetchAllSubsidiaries(),
    fetchUserStaff(),
    fetchTeam(),
  ]);

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

LateStartReportGenWrapper.Loading = LateStartReportGenLoading;

export default LateStartReportGenWrapper;