import { redirect } from "next/navigation";
import { getTranslations } from "next-intl/server";
import { getSessionUser } from "@/lib/session";
import { TicketCreateForm } from "@/components/support/ticket-create-form";
import { BackLink } from "@/components/ui/back-link";

/**
 * /support/new — create ticket form.
 *
 * Platform admins shouldn't open tickets via this UI (they'd be
 * opening one as if from a customer, which is confusing). Redirect
 * them back to the queue. Non-admins of any role can create.
 */
export default async function NewTicketPage() {
  const user = await getSessionUser();
  if (!user) redirect("/login");
  if (user.isPlatform) redirect("/support");
  const t = await getTranslations("support");

  return (
    <main className="max-w-3xl mx-auto px-6 py-8">
      <div className="mb-8 animate-in">
        <BackLink href="/support" label={t("title")} />
        <h1 className="font-display text-2xl font-semibold accent-rule mb-2">
          {t("newTicketTitle")}
        </h1>
        <p className="text-text-secondary text-sm mt-4">
          {t("newTicketSubtitle")}
        </p>
      </div>

      <div className="animate-in animate-in-delay-1">
        <TicketCreateForm />
      </div>
    </main>
  );
}
