"use server";
import React from "react";
import { redirect } from "next/navigation";
import {
  checkAccessTokenIsValid,
  retrieveAvailableEvents,
} from "@/(apicalls)/cookies/token";
import DashboardPage from "@/components/Dashboards/DashboardPage";
import { retrieveAvailableCategories } from "@/appEvents/categories";

const Dashboard: React.FC = async () => {
  const token_is_valid = await checkAccessTokenIsValid();

  if (!token_is_valid) {
    redirect("/login/email");
  }
  const eventsList = await retrieveAvailableEvents();
  const availableMenu = retrieveAvailableCategories(eventsList || []);
  return (
    <>
      <DashboardPage leftSideMenuContent={availableMenu} />
    </>
  );
};

export default Dashboard;
