import { VisibilityRule } from "./visibility.js";
import { AnyRouteMatch } from "@tanstack/react-router";

//#region src/route/page.d.ts
/** The part of TanStack's `head` context a page setting can read. */
type HeadContext = {
  match: {
    id: string;
  };
  matches: ReadonlyArray<{
    id: string;
  }>;
  loaderData?: AnyRouteMatch["loaderData"];
};
type HeadSetting<T> = T | ((ctx: HeadContext) => T | undefined);
type PageSettings = {
  /** Studio's label for the page, separate from its title. */
  name?: string;
  visibility?: VisibilityRule;
  title?: HeadSetting<string>;
  description?: HeadSetting<string>;
  searchEngineIndexing?: HeadSetting<boolean>;
  canonicalUrl?: HeadSetting<string>;
  socialTitle?: HeadSetting<string>;
  socialDescription?: HeadSetting<string>;
  socialImage?: HeadSetting<string>;
};
declare const pageBrand: unique symbol;
/** The settings {@link definePage} has produced. */
type Page<S extends PageSettings = PageSettings> = S & {
  readonly [pageBrand]: "page";
};
/**
 * Declares a route's settings: its name in Studio, who may open it, its title and its SEO tags.
 *
 * One call per route file, at module scope, with an object literal. Studio
 * reads and rewrites each setting written out as a literal; a computed one is
 * changed in the code. A head setting that depends on the route's data is a
 * function of its head context. The route's `beforeLoad` and `head` apply it.
 *
 * @example
 * const pageSettings = definePage({
 *   visibility: { userGroupTypes: ["LOGGED_IN_USERS"] },
 *   title: ({ loaderData }) => loaderData?.name,
 * })
 *
 * export const Route = createFileRoute("/_app/projects/$projectId")({
 *   beforeLoad: guardRoute(pageSettings),
 *   loader: ({ params }) => loadProject({ data: params.projectId }),
 *   head: pageHead(pageSettings),
 *   component: Project,
 * })
 */
declare function definePage<const S extends PageSettings>(settings: S & { [K in Exclude<keyof S, keyof PageSettings>]: never }): Page<S>;
type Meta = NonNullable<AnyRouteMatch["meta"]>;
type Links = NonNullable<AnyRouteMatch["links"]>;
/**
 * The router keeps the deepest route's tag for each title, name and property,
 * so a layout's settings reach every page under it that does not state its own.
 * A canonical URL names one page, so only the page the visitor is on renders
 * its own.
 *
 * Returned rather than called with the route's context: a `head` written as
 * `(ctx) => …` before `loader` stops TypeScript inferring the loader's types.
 *
 * @example
 * head: pageHead(pageSettings)
 */
declare function pageHead(page: Page): (ctx: HeadContext) => {
  meta: Meta;
  links: Links;
};
//#endregion
export { Page, PageSettings, definePage, pageHead };