import { Metadata } from "next";
import { I18nProvider } from "@/i18n";
import UserWorkspacePage from "@/components/UserWorkspacePage";
import {
  fetchLeaveTypes,
  fetchLeaves,
  fetchTeamMemberTimesheets,
  fetchTimesheets,
} from "@/app/api/timesheets";
import { authOptions } from "@/config/authConfig";
import { getServerSession } from "next-auth";
import {
  fetchAssignedProjects,
  fetchProjectWithTasks,
} from "@/app/api/projects";
import { fetchHolidays } from "@/app/api/holidays";

export const metadata: Metadata = {
  title: "User Workspace",
};

const Home: React.FC = async () => {
  const session = await getServerSession(authOptions);
  // Get name for caching
  const username = session!.user!.name!;

  fetchTimesheets(username);
  fetchAssignedProjects(username);
  fetchLeaves(username);
  fetchLeaveTypes();
  fetchProjectWithTasks();
  fetchHolidays();
  fetchTeamMemberTimesheets(username);

  return (
    <I18nProvider namespaces={["home", "common"]}>
      <UserWorkspacePage username={username} />
    </I18nProvider>
  );
};

export default Home;
