{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages-landing-starts",
  "title": "Landing starts",
  "description": "What a landing page offers to start: the creates and immediate actions the UI model names, kept to those the session's own BReg profile may invoke.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0"
  ],
  "registryDependencies": [
    "@registrystack/pages-record-route-query",
    "@registrystack/pages-content",
    "@registrystack/pages-record",
    "@registrystack/pages-register-routes",
    "@registrystack/ui-button",
    "@registrystack/lib-content"
  ],
  "files": [
    {
      "path": "pages/landing-starts.tsx",
      "content": "import type { RecordActionReference } from \"@registrystack/app-runtime\";\nimport { useStarts } from \"@registrystack/app-runtime/react\";\nimport { Button } from \"@/components/ui/button\";\nimport { useLocale } from \"@/blocks/lib/content\";\nimport { createWords, usePagesContent } from \"@/blocks/pages/pages-content\";\nimport { formRoute } from \"@/blocks/pages/record-route-query\";\nimport { useRegisterRoutes } from \"@/blocks/pages/register-routes\";\nimport {\n  entityRoutes,\n  requestRoute,\n  type RegisterEntities,\n} from \"@/blocks/pages/record\";\n\n/**\n * What a landing page offers to start: the creates and immediate actions the\n * UI model names by record type, request type or action id, kept to those the\n * session's own BReg profile may invoke. A request create opens the request\n * form the app names (`createRequest`), the way the start place opens it. A\n * start is offered once, and only where the app has a page for it, and not\n * again where the page already links it (`shown`);\n * BReg still decides the call when it is made. Nothing is shown while the\n * starts are unread or refused, since the landing page does not depend on them.\n * A start opened from the page at `from` leads back there.\n */\nexport function LandingStarts({\n  entities,\n  ids,\n  shown = [],\n  from,\n}: {\n  entities: RegisterEntities;\n  ids: readonly string[];\n  /** The links the page already offers, as `#` routes. */\n  shown?: readonly string[];\n  /** The route of the page that offers the starts, its query included. */\n  from?: string;\n}) {\n  const pages = usePagesContent(),\n    locale = useLocale(),\n    routes = useRegisterRoutes(),\n    starts = useStarts();\n  if (!routes || !starts.data) return null;\n  const seen = new Set<string>();\n  const links = starts.data.flatMap((start: RecordActionReference) => {\n    const key = start.name === \"invoke\" ? start.actionId : start.entity;\n    // An action and a create may share an id, so each kind is kept apart.\n    const kept = `${start.name}:${key}`;\n    if (!key || !ids.includes(key) || seen.has(kept)) return [];\n    const requested =\n      start.name === \"invoke\"\n        ? undefined\n        : entities.requests?.find((entity) => entity.id === start.entity);\n    const at = entityRoutes(routes, entities, start.entity);\n    const path =\n      start.name === \"invoke\"\n        ? start.actionId && at?.recordAction?.(start.actionId)\n        : requested\n          ? routes.createRequest &&\n            requestRoute(entities, routes.createRequest, requested.id)\n          : at?.createRecord;\n    if (!path || shown.includes(`#${path}`)) return [];\n    seen.add(kept);\n    // A create the registry left unlabelled is worded as the record list\n    // words it, and a request create as the start place words it.\n    const created = [entities.record, ...(entities.records ?? [])].find(\n      (entity) => entity.id === start.entity,\n    );\n    const label = requested\n      ? createWords(\n          pages,\n          \"requestChangeOf\",\n          start.label,\n          requested.label,\n          locale,\n        )\n      : start.name === \"invoke\" || !created\n        ? (start.label ?? key)\n        : createWords(\n            pages,\n            created.id === entities.record.id ? \"createRecord\" : \"addRecord\",\n            start.label,\n            created.label,\n            locale,\n          );\n    return [{ key: kept, label, href: `#${formRoute(path, {}, undefined, from)}` }];\n  });\n  if (links.length === 0) return null;\n  return (\n    <section className=\"landing-starts\" aria-labelledby=\"landing-starts\">\n      <h2 id=\"landing-starts\">{pages.startsHeading}</h2>\n      <div className=\"actions\">\n        {links.map((link) => (\n          <Button key={link.key} variant=\"outline\" render={<a href={link.href} />}>\n            {link.label}\n          </Button>\n        ))}\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/pages/landing-starts.tsx"
    }
  ],
  "type": "registry:block"
}