import React from "react";
import GenerateCrossTeamChargeReportLoading from "./GenerateCrossTeamChargeReportLoading";
import GenerateCrossTeamChargeReport from "./GenerateCrossTeamChargeReport";
import { fetchTeam } from "@/app/api/team";
import { fetchUserStaff } from "@/app/utils/fetchUtil";

interface SubComponents {
  Loading: typeof GenerateCrossTeamChargeReportLoading;
}

const GenerateCrossTeamChargeReportWrapper: React.FC & SubComponents = async () => {
  const [
    teams, 
    userStaff
  ] = await Promise.all([
    fetchTeam(), 
    fetchUserStaff()
  ])

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

GenerateCrossTeamChargeReportWrapper.Loading = GenerateCrossTeamChargeReportLoading;

export default GenerateCrossTeamChargeReportWrapper;