import BreadCrumbLink from "@/layouts/shared/page.breadcrumbLink";
import { isSuperAdminAccess } from "@/lib/role-helpers";
import { redirect, type LoaderFunctionArgs } from "react-router";
import type { Route } from "./+types/page";
import AccountDeletionClientPage from "./_client";

export const handle = {
  breadcrumb: () => <BreadCrumbLink links={[{ label: "Account Deletion" }]} />,
};

/**
 * Super admin only, checked here as well as in core.
 *
 * Core is the authority — it refuses every endpoint to anyone else, so a user who
 * reached this URL directly could not do anything. The redirect exists so they see
 * a page they can use instead of an empty screen that looks broken.
 *
 * No data is loaded up front: nothing is shown until an account is searched for, and
 * the account is the thing the operator has to supply.
 */
export const loader = async ({ request }: LoaderFunctionArgs) => {
  if (!isSuperAdminAccess(request)) {
    throw redirect("/admin/promo-codes");
  }
  return null;
};

const Page: React.FC<Route.ComponentProps> = () => <AccountDeletionClientPage />;

export default Page;
