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

interface Props {
  username: string;
}

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

  return (
    <UserWorkspacePage
      assignedProjects={assignedProjects}
      username={username}
      defaultTimesheets={timesheets}
      defaultLeaveRecords={leaves}
      leaveTypes={leaveTypes}
    />
  );
};

export default UserWorkspaceWrapper;
