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

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();

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

export default Home;
