import React from "react";
import FinancialSummaryLoading from "./FinancialSummaryLoading";
import FinancialSummary from "./FinancialSummary";
import { fetchUserStaff, searchParamsProps } from "@/app/utils/fetchUtil";
import { fetchFinancialSummaryByProjectV2 } from "@/app/api/financialsummary";
import { Grid } from "@mui/material";
import FinancialStatusByProject from "./FinnancialStatusByProject";

interface SubComponents {
  Loading: typeof FinancialSummaryLoading;
}
// interface SessionWithAbilities extends Session {
//   abilities?: string[]
// }

const FinancialSummaryWrapper: React.FC<searchParamsProps> & SubComponents = async ({
    searchParams,
  }) => {
    const userStaff = await fetchUserStaff();
    const teamId = userStaff?.isTeamLead ? userStaff.teamId : 0;
    const [
      financialSummByProject
    ] = await Promise.all([
      fetchFinancialSummaryByProjectV2(teamId, "", "")
    ]);

  return (
    <Grid>
      <FinancialSummary _teamId={teamId} financialSummByProject={financialSummByProject}/>
    </Grid>
  );
};

FinancialSummaryWrapper.Loading = FinancialSummaryLoading;

export default FinancialSummaryWrapper;
