import { getTranslations, setRequestLocale } from "next-intl/server";
import { FullpageTool } from "@/components/fullpage-tool";
import { ensurePublisherKeys } from "@/lib/links";
import { publicAppUrl, requireUser } from "@/lib/session";
import { prisma } from "@/lib/prisma";

export default async function FullpageToolPage({
  params,
}: {
  params: Promise<{ locale: string }>;
}) {
  const { locale } = await params;
  setRequestLocale(locale);
  const session = await requireUser();
  const user = await ensurePublisherKeys(session.user.id);
  const fresh = user ?? (await prisma.user.findUniqueOrThrow({ where: { id: session.user.id } }));
  const t = await getTranslations("tools");
  const origin = await publicAppUrl();
  return (
    <div className="space-y-4">
      <h1 className="page-title">{t("fullpage")}</h1>
      <p className="text-muted">{t("fullpageHelp")}</p>
      <FullpageTool origin={origin} apiKey={fresh.apiKey ?? ""} />
    </div>
  );
}
