import { getTranslations } from "next-intl/server"

import { Link } from "@/i18n/navigation"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { getAccountServer } from "@/lib/auth/account-server"
import { getFirstAllowedHref } from "@/lib/auth/permissions"

export async function generateMetadata() {
  const t = await getTranslations("Auth.Forbidden")
  return { title: t("title") }
}

export default async function ForbiddenPage() {
  const t = await getTranslations("Auth.Forbidden")
  const user = await getAccountServer()
  const href = getFirstAllowedHref(user.permissionType, user.permissions)

  return (
    <div className="flex flex-1 items-center justify-center p-6">
      <Card className="max-w-md w-full">
        <CardHeader>
          <CardTitle>{t("title")}</CardTitle>
        </CardHeader>
        <CardContent className="flex flex-col gap-4">
          <p className="text-muted-foreground text-sm">{t("description")}</p>
          <Button asChild>
            <Link href={href}>{t("backToAllowed")}</Link>
          </Button>
        </CardContent>
      </Card>
    </div>
  )
}
