"use server";
import React, { FC } from "react";
import Select from "./page";

import { redirect } from "next/navigation";
import { checkAccessTokenIsValid, retrieveUserType } from "@/apicalls/mutual/cookies/token";
import { AuthPageProps } from "@/validations/mutual/auth/props";

const SelectPage: FC<AuthPageProps> = async ({ query, language }) => {
  const token_is_valid = await checkAccessTokenIsValid();
  const selection = await retrieveUserType();
  const isEmployee = selection?.userType == "employee";
  const isOccupant = selection?.userType == "occupant";
  const selectionList = selection?.selectionList;

  if (!selectionList || !token_is_valid) { redirect("/auth/en/login") }
  return <Select selectionList={selectionList} isEmployee={isEmployee} isOccupant={isOccupant} language={language} query={query} />
}

export default SelectPage;
