import BreadCrumbLink from "@/layouts/shared/page.breadcrumbLink";
import { createRoleProtectedLoader } from "@/lib/features/protectedFetcher";
import { FEATURE_SLUGS, getCheckedAccess } from "@/lib/role-helpers";
import type { AccessScope } from "@/lib/features/types";
import type { Route } from "./+types/page";
import KevoPublishClientPage from "./_client";

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

export const loader = createRoleProtectedLoader(
  FEATURE_SLUGS.kevo,
  "read",
  async ({ request }) => ({
    // Publishing itself is gated by the separate kevo-publish feature.
    publishScope: getCheckedAccess(request, FEATURE_SLUGS.kevoPublish),
  }),
);

const Page: React.FC<Route.ComponentProps> = ({ loaderData }) => {
  const { publishScope } = loaderData as unknown as {
    publishScope: AccessScope;
  };
  return <KevoPublishClientPage publishScope={publishScope} />;
};

export default Page;
