import React from "react";
import { fetchUserAbilities, fetchUserStaff } from "@/app/utils/fetchUtil";
import { VIEW_DASHBOARD_ALL } from "@/middleware";
import CompanyTeamCashFlow from "./CompanyTeamCashFlow";
import dayjs from "dayjs";
import { fetchCompanyTeamCashFlow } from "@/app/api/teamCashflow";
import CompanyTeamCashFlowV2 from "./CompanyTeamCashFlowV2";
import { fetchTeam } from "@/app/api/team";

const CompanyTeamCashFlowWrapper: React.FC = async () => {
      const [abilities, staff] = await Promise.all([fetchUserAbilities(), fetchUserStaff()]);
      const currYear = dayjs().format("YYYY")
      const teamId = abilities.includes(VIEW_DASHBOARD_ALL) ? null : staff.teamId
      const cashflow = await fetchCompanyTeamCashFlow(currYear, teamId)
      const viewAll = abilities.includes(VIEW_DASHBOARD_ALL)
    // own team / all teams depends on abilities
    return <CompanyTeamCashFlow abilities={abilities} staff={staff}/>;
    // return <CompanyTeamCashFlowV2 cashflow={cashflow} teams={viewAll ? await fetchTeam() : []}/>
    // return <CompanyTeamCashFlow2 
    //           viewAll={viewAll} 
    //           _teamId={teamId} 
    //           _manpowerExpense={manhourExpense}
    //           _invoice={invoice}
    //           _projectExpense={projectExpense}
    //           // cashflow={cashflow}
    //         />
};

export default CompanyTeamCashFlowWrapper;