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

interface SubComponents {
  Loading: typeof GenerateCrossTeamChargeReportLoading;
}

const GenerateCrossTeamChargeReportWrapper: React.FC & SubComponents = async () => {

  const [teams, userStaff] = await Promise.all([fetchTeam(), getUserStaff()])

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

GenerateCrossTeamChargeReportWrapper.Loading = GenerateCrossTeamChargeReportLoading;

export default GenerateCrossTeamChargeReportWrapper;