'use server';
import { AuthLayout } from "@/layouts/auth/layout";
import { AuthServerProps } from "@/validations/mutual/pages/props";
import { LanguageTypes } from "@/validations/mutual/language/validations";
import { checkAccessTokenIsValid } from "@/apifetchers/mutual/cookies/token";
import { getOnlineFromRedis } from "@/apifetchers/mutual/context/page/online/fetch";
import { redirect } from "next/navigation";
import Login from "@/webPages/auth/login/page";

const AuthPageSSR = async ({ params, searchParams }: AuthServerProps) => {
    const awaitedParams = await params;
    const awaitedSearchParams = await searchParams;
    const pageUrlFromParams = `/${awaitedParams.page?.join("/")}` || "/login";
    const tokenValid = await checkAccessTokenIsValid();
    try { const online = await getOnlineFromRedis(); if (tokenValid && online) { redirect("/panel/dashboard") } } catch (error) { }
    return <div className="flex flex-col items-center justify-center"><AuthLayout lang={"en"} page={<Login language={"en"} query={awaitedSearchParams} />} activePageUrl={pageUrlFromParams} /></div>
}

export default AuthPageSSR;
