import React from "react";
import GenerateProjectPandLReportLoading from "./GenerateProjectPandLReportLoading";
import { fetchProjects } from "@/app/api/projects";
import GenerateProjectPandLReport from "./GenerateProjectPandLReport";
import { fetchUserStaff } from "@/app/utils/fetchUtil";

interface SubComponents {
  Loading: typeof GenerateProjectPandLReportLoading;
}

const GenerateProjectPandLReportWrapper: React.FC & SubComponents = async () => {
  const [projects, userStaff] = await Promise.all([fetchProjects(), fetchUserStaff()]);

  return <GenerateProjectPandLReport projects={userStaff?.teamId ? projects.filter(project => project.teamId === userStaff.teamId) : projects}/>;
};

GenerateProjectPandLReportWrapper.Loading = GenerateProjectPandLReportLoading;

export default GenerateProjectPandLReportWrapper;