import { Outlet, redirect, createFileRoute } from "@tanstack/react-router";
import { msg } from "@lingui/core/macro";
import type { HeaderConfig } from "@/features/core/types/header-config";

export const Route = createFileRoute("/_authed/admin")({
  component: Outlet,
  beforeLoad: ({ context }) => {
    if (!context.auth?.roles?.includes("Admin")) {
      throw redirect({ to: "/" });
    }

    const header: HeaderConfig = {
      ...context.header,
      title: msg`Admin`,
      withBackButton: true,
    };

    return { header };
  },
});
