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

interface SubComponents {
  Loading: typeof GenerateProjectCashFlowReportLoading;
}

const GenerateProjectCashFlowReportWrapper: React.FC & SubComponents = async () => {
  const projects = await fetchProjects();
  const staff = await fetchUserStaff()

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

GenerateProjectCashFlowReportWrapper.Loading = GenerateProjectCashFlowReportLoading;

export default GenerateProjectCashFlowReportWrapper;