import { fetchTeamProjects } from "@/app/api/teamprojects";
import React from "react";
import ProgressByTeamSearch from "./ProgressByTeamSearch";
import ProgressByTeamSearchLoading from "./ProgressByTeamSearchLoading";

interface SubComponents {
  Loading: typeof ProgressByTeamSearchLoading;
}

const ProgressByTeamSearchWrapper: React.FC & SubComponents = async () => {
  const teamprojects = await fetchTeamProjects();

  const _teamprojects = teamprojects.length > 1 ? [{id: 0, teamId: 0, teamLeadId: 0, teamCode: "All", teamName: "", projectNo: teamprojects.reduce((acc, cur) => acc + cur.projectNo, 0)}, ...teamprojects] : teamprojects

  return <ProgressByTeamSearch projects={_teamprojects} />;
};

ProgressByTeamSearchWrapper.Loading = ProgressByTeamSearchLoading;

export default ProgressByTeamSearchWrapper;
