{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages-service-app",
  "title": "Service app",
  "description": "The holder-facing composition of a register's public service: introduction, session boundary, public help, the register's own records and requests. It takes no register nouns of its own; `useRegisterRoutes()` supplies the paths, the model's plural labels name the nav places, and the task, upload and removal hooks and the notices are the default ones. A caller may pass its own nav labels, hooks and notices in their place.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/pages-app-routes",
    "@registrystack/pages-lazy-pages",
    "@registrystack/document-preview",
    "@registrystack/pages-change-request-form",
    "@registrystack/pages-content",
    "@registrystack/pages-create-record",
    "@registrystack/pages-default-notices",
    "@registrystack/pages-default-tasks",
    "@registrystack/request-holder-steps",
    "@registrystack/pages-record",
    "@registrystack/pages-record-action",
    "@registrystack/pages-record-attachments",
    "@registrystack/pages-record-detail",
    "@registrystack/pages-record-list",
    "@registrystack/pages-register-routes",
    "@registrystack/pages-request-detail",
    "@registrystack/pages-request-queue",
    "@registrystack/pages-start-places",
    "@registrystack/request-attachment-slots",
    "@registrystack/shell-back-link",
    "@registrystack/shell-chrome",
    "@registrystack/shell-content",
    "@registrystack/shell-error-panel",
    "@registrystack/shell-help-page",
    "@registrystack/shell-introduction",
    "@registrystack/shell-loading",
    "@registrystack/shell-navigation",
    "@registrystack/shell-public",
    "@registrystack/shell-routing",
    "@registrystack/shell-session-boundary"
  ],
  "files": [
    {
      "path": "pages/service-app.tsx",
      "content": "import { Suspense, useMemo, type ReactNode } from \"react\";\nimport { FileCheck2, HelpCircle, Library } from \"lucide-react\";\nimport { useAuthority } from \"@registrystack/app-runtime/react\";\nimport { unavailableError } from \"@registrystack/app-runtime\";\nimport { BackLink } from \"@/blocks/shell/back-link\";\nimport { Navigation, type ShellNavItem } from \"@/blocks/shell/navigation\";\nimport { ErrorPanel } from \"@/blocks/shell/error-panel\";\nimport { HelpPage } from \"@/blocks/shell/help-page\";\nimport { Introduction } from \"@/blocks/shell/introduction\";\nimport { Loading } from \"@/blocks/shell/loading\";\nimport { PublicShell } from \"@/blocks/shell/public\";\nimport { Shell } from \"@/blocks/shell/chrome\";\nimport { splitRoute, useRoute } from \"@/blocks/shell/routing\";\nimport { useShellContent, type ShellContent } from \"@/blocks/shell/shell-content\";\nimport {\n  exactPath,\n  navGroups,\n  registerPath,\n  renderRoute,\n  route,\n  type AppParts,\n  type AppRoute,\n  type NavTable,\n} from \"@/blocks/pages/app-routes\";\nimport type { ChangeRequestTask } from \"@/blocks/pages/change-request-form-page\";\nimport type { CreateRecordTask } from \"@/blocks/pages/create-record-page\";\nimport {\n  PendingUploadsNotice,\n  RecoveryNotice,\n} from \"@/blocks/pages/default-notices\";\nimport * as defaultTasks from \"@/blocks/pages/default-tasks\";\nimport { usePagesContent } from \"@/blocks/pages/pages-content\";\nimport { navigationRequests, useRegister } from \"@/blocks/pages/record\";\nimport {\n  ChangeRequestFormPage,\n  CreateRecordPage,\n  HolderChooseChangePage,\n  HolderChooseRecordPage,\n  HolderDocumentsPage,\n  HolderRecordListPage,\n  HolderReviewPage,\n  RecordActionPage,\n  RecordDetailPage,\n  RequestDetailPage,\n  RequestQueuePage,\n} from \"@/blocks/pages/lazy-pages\";\nimport {\n  matchHolderStep,\n  type HolderStepMatch,\n} from \"@/blocks/pages/holder-step-routes\";\nimport { useRegisterRoutes, type RegisterRoutes } from \"@/blocks/pages/register-routes\";\nimport type { RequestDecisionTask } from \"@/blocks/pages/request-detail-page\";\nimport { SessionBoundary } from \"@/blocks/shell/session-boundary\";\nimport type { DocumentSource } from \"@/blocks/documents/document-view\";\nimport type { RemovalOutcome } from \"@/blocks/pages/record-attachments\";\nimport type { UploadOutcome } from \"@/blocks/request/attachment-slots\";\n\n/** Labels the register's own service names its two nav places with. */\nexport interface ServiceAppLabels {\n  records: string;\n  requests: string;\n}\n\n/**\n * Every part an app may bind itself. Each one it leaves out is the blocks'\n * own: the nav names its places by the model's plural labels, the pages use\n * `@/blocks/pages/default-tasks` and the notices come from\n * `@/blocks/pages/default-notices`. A notice passed as `null` or `false`\n * renders none.\n */\nexport interface ServiceAppProps {\n  labels?: ServiceAppLabels;\n  useCreateTask?: () => CreateRecordTask;\n  useChangeTask?: () => ChangeRequestTask;\n  useRequestTask?: () => RequestDecisionTask;\n  useUpload?: (slot: string) => UploadOutcome;\n  useRemoval?: (slot: string) => RemovalOutcome;\n  openPdf?: (bytes: ArrayBuffer, signal: AbortSignal) => Promise<DocumentSource>;\n  /**\n   * Rendered ahead of the page on every route. Left out, it is\n   * `RecoveryNotice` from `@/blocks/pages/default-notices`; `null` or\n   * `false` renders none.\n   */\n  recoveryNotice?: ReactNode;\n  /**\n   * Rendered ahead of the page on every route. Left out, it is\n   * `PendingUploadsNotice` from `@/blocks/pages/default-notices`; `null` or\n   * `false` renders none.\n   */\n  pendingUploadsNotice?: ReactNode;\n  /** The pages, tried in order; left out, `serviceRoutes`. */\n  routes?: readonly AppRoute[];\n  /** The places in the nav; left out, `serviceNavigation`. */\n  navigation?: NavTable<ServiceNavContext, ShellNavItem>;\n}\n\n/** What the service navigation entries read to decide their items. */\nexport interface ServiceNavContext {\n  shell: ShellContent;\n  labels: ServiceAppLabels;\n  routes: RegisterRoutes;\n  hasRequests: boolean;\n}\n\n/** The places a holder can go, as data: one group of entries, in order. */\nexport const serviceNavigation: NavTable<ServiceNavContext, ShellNavItem> = [\n  [\n    {\n      id: \"records\",\n      items: ({ labels, routes }) => [\n        { path: \"/\", label: labels.records, icon: Library, under: [routes.records] },\n      ],\n    },\n    {\n      id: \"requests\",\n      items: ({ labels, routes, hasRequests }) =>\n        hasRequests\n          ? [{ path: routes.requests, label: labels.requests, icon: FileCheck2 }]\n          : [],\n    },\n    {\n      id: \"help\",\n      items: ({ shell }) => [{ path: \"/help\", label: shell.help, icon: HelpCircle }],\n    },\n  ],\n];\n\n/**\n * The service app's routes, in the order they are tried. An app replaces one\n * with `replaceRoute(serviceRoutes, route(\"record\", ...))` or adds a page by\n * listing its own route beside these.\n */\nexport const serviceRoutes: AppRoute[] = [\n  route(\"help\", exactPath(\"/help\"), () => <HelpPage />),\n  route(\"records\", (path, routes) => (path === \"/\" || path === routes.records ? {} : null), () => (\n    <HolderRecordListPage />\n  )),\n  route(\"create-record\", registerPath(\"createRecord\"), (_, c) => (\n    <CreateRecordPage useTask={c.useCreateTask} />\n  )),\n  route(\"record-action\", registerPath(\"recordAction\"), (m, c) => (\n    <RecordActionPage actionId={m.id} useTask={c.useCreateTask} />\n  )),\n  route(\"change-record\", registerPath(\"changeRecord\"), (m, c) => (\n    <ChangeRequestFormPage recordId={m.id} useTask={c.useChangeTask} />\n  )),\n  route(\"create-request\", registerPath(\"createRequest\"), (_, c) => (\n    <ChangeRequestFormPage useTask={c.useChangeTask} />\n  )),\n  route(\"record\", registerPath(\"record\"), (m) => <RecordDetailPage id={m.id} />),\n  route(\"requests\", registerPath(\"requests\"), () => <RequestQueuePage />),\n  route(\"edit-request\", registerPath(\"editRequest\"), (m, c) => (\n    <ChangeRequestFormPage requestId={m.id} useTask={c.useChangeTask} />\n  )),\n  route(\"request\", registerPath(\"request\"), (m, c) => (\n    <RequestDetailPage\n      id={m.id}\n      useTask={c.useRequestTask}\n      useUpload={c.useUpload}\n      useRemoval={c.useRemoval}\n      openPdf={c.openPdf}\n    />\n  )),\n  // Last, so a path the app's own routes answer is never taken by a step.\n  route(\n    \"holder-step\",\n    (path, routes): HolderStepMatch | null => matchHolderStep(routes, path),\n    (m, c) =>\n      m.kind === \"chooseRecord\" ? (\n        <HolderChooseRecordPage />\n      ) : m.kind === \"chooseChange\" ? (\n        <HolderChooseChangePage id={m.id} />\n      ) : m.kind === \"documents\" ? (\n        <HolderDocumentsPage id={m.id} />\n      ) : (\n        <HolderReviewPage id={m.id} useTask={c.useChangeTask} />\n      ),\n  ),\n];\n\n/**\n * The places named by the model's plural labels, and by the pages' own\n * titles while the model is not read yet.\n */\nfunction ModelLabelledServiceApp(props: ServiceAppProps) {\n  const pages = usePagesContent();\n  const entities = useRegister().entities;\n  const records = entities?.record.pluralLabel ?? pages.ownRecordListTitle;\n  const requestEntities = entities ? navigationRequests(entities) : [];\n  const requests =\n    requestEntities.length === 1\n      ? requestEntities[0]!.pluralLabel\n      : pages.holderRequestsTitle;\n  const labels = useMemo(() => ({ records, requests }), [records, requests]);\n  return <ServiceWork {...props} labels={labels} />;\n}\n\nfunction ProtectedServiceApp(props: ServiceAppProps) {\n  return props.labels ? (\n    <ServiceWork {...props} labels={props.labels} />\n  ) : (\n    <ModelLabelledServiceApp {...props} />\n  );\n}\n\nfunction ServiceWork(props: ServiceAppProps & { labels: ServiceAppLabels }) {\n  const session = useAuthority();\n  const entities = useRegister().entities;\n  const route = useRoute();\n  const { path } = splitRoute(route);\n  const routes = useRegisterRoutes();\n  const shell = useShellContent();\n  const parts: AppParts = {\n    useCreateTask: props.useCreateTask ?? defaultTasks.useCreateTask,\n    useChangeTask: props.useChangeTask ?? defaultTasks.useChangeTask,\n    useRequestTask: props.useRequestTask ?? defaultTasks.useRequestTask,\n    useUpload: props.useUpload ?? defaultTasks.useUpload,\n    useRemoval: props.useRemoval ?? defaultTasks.useRemoval,\n    openPdf: props.openPdf,\n  };\n  const page = renderRoute(props.routes ?? serviceRoutes, path, routes, {\n    ...parts,\n    session,\n    redirecting: false,\n  }) ?? (\n    <ErrorPanel\n      error={unavailableError(shell.unavailable)}\n      unavailableTitle={shell.unavailable}\n    />\n  );\n  const items = navGroups(props.navigation ?? serviceNavigation, {\n    shell,\n    labels: props.labels,\n    routes,\n    hasRequests: Boolean(entities && navigationRequests(entities).length > 0),\n  }).flat();\n  return (\n    <Shell\n      audience=\"service\"\n      session={session}\n      navigation={<Navigation items={items} current={path} />}\n    >\n      {props.recoveryNotice === undefined ? <RecoveryNotice /> : props.recoveryNotice}\n      {props.pendingUploadsNotice === undefined ? <PendingUploadsNotice /> : props.pendingUploadsNotice}\n      <Suspense fallback={<Loading />}>\n        <div key={route}>{page}</div>\n      </Suspense>\n    </Shell>\n  );\n}\n\n/**\n * A holder-facing register service: introduction, session boundary, public\n * help, the register's own records and requests. It takes no register nouns\n * of its own; `useRegisterRoutes()` supplies the paths and `labels`, or the\n * model without them, supplies the nav wording, so an app names both once\n * and this composes the rest.\n */\nexport function ServiceApp(props: ServiceAppProps) {\n  const route = useRoute();\n  return (\n    <SessionBoundary\n      audience=\"service\"\n      introduction={\n        splitRoute(route).path === \"/help\" ? (\n          <ServiceHelpIntroduction />\n        ) : (\n          <Introduction audience=\"service\" />\n        )\n      }\n    >\n      <ProtectedServiceApp {...props} />\n    </SessionBoundary>\n  );\n}\n\nfunction ServiceHelpIntroduction() {\n  const shell = useShellContent();\n  return (\n    <PublicShell audience=\"service\">\n      <BackLink href=\"/\">{shell.back}</BackLink>\n      <HelpPage />\n    </PublicShell>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/pages/service-app.tsx"
    }
  ],
  "type": "registry:block"
}