import { notFound, redirect } from "next/navigation"
import { LoginForm } from "@/app/login/login-form"
import { resolveRoleFromServerContext } from "@/lib/access-server"
import { resolveSupportLoginKey } from "@/lib/auth/server"

export const dynamic = "force-dynamic"

type Params = Promise<{ key: string }>

export default async function SupportLoginPage({ params }: { params: Params }) {
  const { key } = await params
  const role = await resolveRoleFromServerContext()

  if (role) {
    redirect("/")
  }

  if (key !== resolveSupportLoginKey()) {
    notFound()
  }

  return <LoginForm mode="signin" />
}
