import {
  fetchAssignedProjects,
  fetchProjectWithTasks,
} from "@/app/api/projects";
import UserWorkspacePage from "./UserWorkspacePage";
import {
  fetchLeaveTypes,
  fetchLeaves,
  fetchTeamMemberTimesheets,
  fetchTimesheets,
} from "@/app/api/timesheets";
import { fetchHolidays } from "@/app/api/holidays";

interface Props {
  username: string;
}

const UserWorkspaceWrapper: React.FC<Props> = async ({ username }) => {
  const [
    teamTimesheets,
    assignedProjects,
    allProjects,
    timesheets,
    leaves,
    leaveTypes,
    holidays,
  ] = await Promise.all([
    fetchTeamMemberTimesheets(username),
    fetchAssignedProjects(username),
    fetchProjectWithTasks(),
    fetchTimesheets(username),
    fetchLeaves(username),
    fetchLeaveTypes(),
    fetchHolidays(),
  ]);

  return (
    <UserWorkspacePage
      teamTimesheets={teamTimesheets}
      allProjects={allProjects}
      assignedProjects={assignedProjects}
      username={username}
      defaultTimesheets={timesheets}
      defaultLeaveRecords={leaves}
      leaveTypes={leaveTypes}
      holidays={holidays}
      // Change to access check
      fastEntryEnabled={true}
    />
  );
};

export default UserWorkspaceWrapper;
