{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages-staff-app",
  "title": "Staff app",
  "description": "The officer-facing composition of a register's staff work: the work shell's places, the register's own records and requests, and Casework's review queue, review task, staffing and setup pages. 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/casework-content",
    "@registrystack/casework-work-shell",
    "@registrystack/dashboard-routes",
    "@registrystack/document-preview",
    "@registrystack/pages-casework-how-review-works",
    "@registrystack/pages-casework-landing",
    "@registrystack/pages-casework-my-decisions",
    "@registrystack/pages-casework-review",
    "@registrystack/pages-casework-setup",
    "@registrystack/pages-casework-staffing",
    "@registrystack/pages-casework-team-reviews",
    "@registrystack/pages-change-request-form",
    "@registrystack/pages-content",
    "@registrystack/pages-create-record",
    "@registrystack/pages-default-notices",
    "@registrystack/pages-default-tasks",
    "@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-content",
    "@registrystack/shell-error-panel",
    "@registrystack/shell-help-page",
    "@registrystack/shell-introduction",
    "@registrystack/shell-loading",
    "@registrystack/shell-public",
    "@registrystack/shell-routing",
    "@registrystack/shell-session-boundary",
    "@registrystack/shell-work-frame",
    "@registrystack/field-renderers",
    "@registrystack/pages-record-route-query"
  ],
  "files": [
    {
      "path": "pages/staff-app.tsx",
      "content": "import { Suspense, useCallback, useEffect, useMemo, type ReactNode } from \"react\";\nimport {\n  ClipboardList,\n  FileCheck2,\n  HelpCircle,\n  Library,\n  Play,\n  ScrollText,\n  Users,\n} from \"lucide-react\";\nimport type {\n  AuthenticatedSession,\n  EntityModel,\n  RegistryModel,\n} from \"@registrystack/app-runtime\";\nimport {\n  useAuthority,\n  useDashboard,\n  useModel,\n  useStarts,\n} from \"@registrystack/app-runtime/react\";\nimport { unavailableError } from \"@registrystack/app-runtime\";\nimport {\n  dashboardNavEntry,\n  dashboardRoutes,\n  useDashboardNav,\n  type DashboardNavContext,\n} from \"@/blocks/dashboard/dashboard-routes\";\nimport { ReferenceHrefProvider } from \"@/blocks/fields/reference-value\";\nimport { BackLink } from \"@/blocks/shell/back-link\";\nimport { ErrorPanel } from \"@/blocks/shell/error-panel\";\nimport { HelpPage } from \"@/blocks/shell/help-page\";\nimport { Introduction } from \"@/blocks/shell/introduction\";\nimport { PublicShell } from \"@/blocks/shell/public\";\nimport { Loading } from \"@/blocks/shell/loading\";\nimport { navigate, splitRoute, useRoute } from \"@/blocks/shell/routing\";\nimport { useShellContent } from \"@/blocks/shell/shell-content\";\nimport { WorkFrame } from \"@/blocks/shell/work-frame\";\nimport type { NavItem } from \"@/blocks/casework/work-shell\";\nimport {\n  caseworkContent,\n  useCaseworkContent,\n  type CaseworkContent,\n} from \"@/blocks/casework/casework-content\";\nimport {\n  dashboardLanding,\n  landingPath,\n  workKind,\n} from \"@/blocks/pages/casework-landing\";\nimport {\n  entityPath,\n  exactPath,\n  navGroups,\n  registerPath,\n  renderRoute,\n  route,\n  type AppParts,\n  type AppRoute,\n  type NavEntry,\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 {\n  entityRoutes,\n  navigationRequests,\n  recordPath,\n  registerEntities,\n  useRegister,\n  type RegisterEntities,\n} from \"@/blocks/pages/record\";\nimport { listRoute } from \"@/blocks/pages/record-route-query\";\nimport {\n  listsRecords,\n  matchStartRoute,\n  opensOnStarts,\n  startsPath,\n  unlistedStarts,\n} from \"@/blocks/pages/start-places\";\nimport {\n  CaseworkHowReviewWorksPage,\n  CaseworkMyDecisionsPage,\n  CaseworkReviewPage,\n  CaseworkReviewsPage,\n  CaseworkSetupPage,\n  CaseworkStaffingPage,\n  CaseworkTeamReviewsPage,\n  ChangeRequestFormPage,\n  CreateRecordPage,\n  RecordActionPage,\n  RecordDetailPage,\n  RecordListPage,\n  RequestDetailPage,\n  RequestQueuePage,\n  ReviewDecisionPendingNotice,\n  StaffingPendingNotice,\n  StartPage,\n} from \"@/blocks/pages/lazy-pages\";\nimport {\n  decodeSegment,\n  useRegisterRoutes,\n  type RegisterRoutes,\n} 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 staff app names its records and requests places with. */\nexport interface StaffAppLabels {\n  records: string;\n  requests: string;\n  /** The requests place's label for a reviewer, who works the queue rather than \"their own\" requests. */\n  reviewQueue: 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 StaffAppProps {\n  labels?: StaffAppLabels;\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, `staffRoutes`. */\n  routes?: readonly AppRoute[];\n  /** The places in the nav; left out, `staffNavigation`. */\n  navigation?: NavTable<StaffNavContext, NavItem>;\n}\n\n/**\n * The record entities the model offers as places: one nav item each, in the\n * model's order, and whether the register has requests to offer beside them.\n * No items means the labels name the one place: the only record entity\n * offered is the register's own, or the model names places it reads none of.\n * `found` holds the places a session that opens on the start place keeps:\n * each one it may open a record of or look one up in, on its own route, the\n * register's own included.\n */\ninterface RecordPlaces {\n  items: NavItem[];\n  found: NavItem[];\n  hasRequests: boolean;\n}\n\n/**\n * The start place's nav item, when the session has starts no record list\n * offers or opens on the start place, and whether it opens there, in which\n * case the records place keeps only the pages that find a record, since the\n * session would be refused a list.\n */\ninterface StartPlace {\n  items: NavItem[];\n  landing: boolean;\n}\n\n/**\n * The record entities the staff app offers as places, in the model's order:\n * the ones the model's `places` names, else every record entity the session\n * can list or look up. Only a session that can do neither is offered the\n * entities it reads by identifier, since a get-only type is often only a\n * reference or join target that staff would have to paste an id to reach.\n */\nfunction placeEntities(\n  entities: RegisterEntities | null,\n  model: RegistryModel | undefined,\n): EntityModel[] {\n  if (!entities?.records) return [];\n  const records = entities.records;\n  const places = model?.places;\n  if (places) {\n    return places.flatMap((id) => records.filter((entity) => entity.id === id));\n  }\n  const found = records.filter(\n    (entity) => entity.operations?.list || entity.operations?.lookup,\n  );\n  return found.length > 0\n    ? found\n    : records.filter((entity) => entity.operations?.get);\n}\n\n/** One nav item per record entity place, each on its own list route. */\nfunction recordPlaces(\n  routes: RegisterRoutes,\n  entities: RegisterEntities | null,\n  model: RegistryModel | undefined,\n): RecordPlaces {\n  // The register's own record entity, offered alone without `places`, keeps\n  // the one place the labels name.\n  const named = placeEntities(entities, model);\n  const ownOnly =\n    !model?.places &&\n    named.length === 1 &&\n    named[0]!.id === entities?.record.id;\n  const places = ownOnly ? [] : named;\n  // The root, where it is no other place, is the register's own list.\n  const items = places.flatMap((entity) => {\n    const at = entities && entityRoutes(routes, entities, entity.id);\n    return at\n      ? [\n          {\n            path: at.records,\n            label: entity.pluralLabel,\n            icon: Library,\n            ...(entity.id === entities.record.id ? { under: [\"/\"] } : {}),\n          },\n        ]\n      : [];\n  });\n  // The root is the start place for a session that opens there, so no place\n  // stands under it.\n  const found = named.flatMap((entity) => {\n    const at =\n      entities &&\n      (entity.operations?.get || entity.operations?.lookup) &&\n      entityRoutes(routes, entities, entity.id);\n    return at\n      ? [{ path: at.records, label: entity.pluralLabel, icon: Library }]\n      : [];\n  });\n  return {\n    items,\n    found,\n    hasRequests: Boolean(entities && navigationRequests(entities).length > 0),\n  };\n}\n\n/**\n * The route the root stands for when the model names where a session opens:\n * its `home` list, else the first place. Null where it names neither, and for\n * a casework session, which opens on the review task queue.\n */\nexport function modelHomeRoute(\n  session: AuthenticatedSession,\n  routes: RegisterRoutes,\n  entities: RegisterEntities | null,\n  model: RegistryModel | undefined,\n): string | null {\n  if (session.caseworkProfile || !entities) return null;\n  const home = model?.home;\n  const at = home && entityRoutes(routes, entities, home.entity);\n  if (home && at) return listRoute(at.records, { filters: home.filters });\n  const first = model?.places && placeEntities(entities, model)[0];\n  return first ? (entityRoutes(routes, entities, first.id)?.records ?? null) : null;\n}\n\n/**\n * Where the root sends a session, or null to stay. A registrar goes to the\n * dashboard where `dashboardLanding` names one. Nothing else is decided while\n * the model is still being read, so a reviewer is not sent to a queue the\n * model's home would have replaced. Without a model home, a reviewer goes to\n * the request queue where the register has requests, or where no model could\n * be read. A session with no home list that can list no record opens on the\n * start place (`startsLanding`) in place of a list it would be refused,\n * including the first configured place.\n */\nexport function rootRedirect(\n  session: AuthenticatedSession,\n  routes: RegisterRoutes,\n  entities: RegisterEntities | null,\n  model: RegistryModel | undefined,\n  pending: boolean,\n  dashboard: string | null = null,\n  startsLanding: string | null = null,\n): string | null {\n  if (dashboard) return dashboard;\n  if (pending) return null;\n  // A configured place the session cannot list is not a landing; the model\n  // names a home only for a list the session can run, so a home still wins.\n  if (startsLanding && !model?.home) return startsLanding;\n  const home = modelHomeRoute(session, routes, entities, model);\n  if (home) return home;\n  return session.decidesRequests &&\n    !session.caseworkProfile &&\n    (!entities || navigationRequests(entities).length > 0)\n    ? routes.requests\n    : null;\n}\n\n/** What the staff navigation entries read to decide their items. */\nexport interface StaffNavContext extends DashboardNavContext {\n  session: AuthenticatedSession;\n  casework: CaseworkContent;\n  labels: StaffAppLabels;\n  routes: RegisterRoutes;\n  record: RecordPlaces;\n  starts: StartPlace;\n}\n\ntype StaffNavEntry = NavEntry<StaffNavContext, NavItem>;\n\nconst reviewer = (context: StaffNavContext) =>\n  context.session.decidesRequests;\n\n/** The request queue's place, worded for who works it. */\nfunction requestsItem(\n  { routes, labels, record }: StaffNavContext,\n  label: string,\n): NavItem[] {\n  return record.hasRequests\n    ? [{ path: routes.requests, label, icon: FileCheck2 }]\n    : [];\n}\n\n/** The records place: one item per model place, else the one place the labels name. */\nfunction recordsItems(context: StaffNavContext): NavItem[] {\n  const { session, casework, labels, routes, record, starts } = context;\n  if (starts.landing) {\n    // With no items, the labels name the register's own record entity.\n    return record.found.map((item) =>\n      record.items.length === 0 && item.path === routes.records\n        ? { ...item, label: labels.records }\n        : item,\n    );\n  }\n  if (record.items.length > 0) return [...record.items];\n  if (session.caseworkProfile) {\n    // The records place carries the name a registrar's nav and the records\n    // page give it, unless the app's own content words it.\n    const label =\n      casework.navRecords === caseworkContent.navRecords\n        ? labels.records\n        : casework.navRecords;\n    return [{ path: routes.records, label, icon: Library }];\n  }\n  return [\n    {\n      path: reviewer(context) ? routes.records : \"/\",\n      label: labels.records,\n      icon: Library,\n      under: [routes.records],\n    },\n  ];\n}\n\n/**\n * The places a session can go, as data: groups drawn between dividers, each\n * a list of entries that give their items to the sessions that have them.\n */\nexport const staffNavigation: NavTable<StaffNavContext, NavItem> = [\n  [\n    {\n      id: \"reviews\",\n      items: ({ session, casework }) =>\n        session.caseworkProfile && session.caseworkProfile !== \"administrator\"\n          ? [{ path: \"/casework\", label: casework.navReviews, icon: ClipboardList }]\n          : [],\n    },\n    {\n      id: \"team-reviews\",\n      items: ({ session, casework }) =>\n        session.caseworkProfile === \"supervisor\"\n          ? [\n              {\n                path: \"/casework/team-reviews\",\n                label: casework.navTeamReviews,\n                icon: ClipboardList,\n              },\n            ]\n          : [],\n    },\n    {\n      id: \"my-decisions\",\n      items: ({ session, casework }) =>\n        session.caseworkProfile === \"staff\" ||\n        session.caseworkProfile === \"supervisor\"\n          ? [\n              {\n                path: \"/casework/decisions\",\n                label: casework.navMyDecisions,\n                icon: FileCheck2,\n              },\n            ]\n          : [],\n    },\n    {\n      id: \"staffing\",\n      items: ({ session, casework }) =>\n        session.caseworkProfile === \"supervisor\"\n          ? [\n              {\n                path: \"/casework/staffing\",\n                label: casework.navStaffing,\n                icon: Users,\n              },\n            ]\n          : [],\n    },\n    {\n      id: \"setup\",\n      items: ({ session, casework }) =>\n        session.caseworkProfile === \"administrator\"\n          ? [{ path: \"/casework/setup\", label: casework.navSetup, icon: FileCheck2 }]\n          : [],\n    },\n  ],\n  [\n    dashboardNavEntry,\n    {\n      id: \"review-queue\",\n      items: (context) =>\n        !context.session.caseworkProfile && reviewer(context)\n          ? requestsItem(context, context.labels.reviewQueue)\n          : [],\n    },\n    {\n      id: \"records\",\n      items: (context) =>\n        context.session.caseworkProfile === \"administrator\"\n          ? []\n          : recordsItems(context),\n    },\n    {\n      id: \"start\",\n      items: (context) => context.starts.items,\n    },\n    {\n      // A Casework reviewer's reviews are the Casework list above, so the\n      // request queue is not offered beside it. A reviewer BReg alone knows\n      // has the queue as the \"review-queue\" place.\n      id: \"requests\",\n      items: (context) =>\n        context.session.caseworkProfile === \"administrator\" ||\n        context.session.caseworkProfile === \"staff\" ||\n        (!context.session.caseworkProfile && reviewer(context))\n          ? []\n          : requestsItem(context, context.labels.requests),\n    },\n  ],\n  [\n    {\n      id: \"how-review-works\",\n      items: ({ session, casework }) =>\n        session.caseworkProfile\n          ? [\n              {\n                path: \"/casework/how-review-works\",\n                label: casework.navHowReviewWorks,\n                icon: ScrollText,\n              },\n            ]\n          : [],\n    },\n    {\n      id: \"help\",\n      items: ({ casework }) => [\n        { path: \"/help\", label: casework.navHelp, icon: HelpCircle },\n      ],\n    },\n  ],\n];\n\n/** The place the root route stands for, so it is marked current there. */\nfunction homeOf(\n  session: AuthenticatedSession,\n  routes: RegisterRoutes,\n  modelHome: string | null,\n  dashboard: string | null,\n): string {\n  if (session.caseworkProfile) return landingPath(session);\n  if (dashboard) return dashboard;\n  if (modelHome) return splitRoute(modelHome).path;\n  return session.decidesRequests ? routes.requests : \"/\";\n}\n\n/**\n * The staff app's routes, in the order they are tried. An app replaces one\n * with `replaceRoute(staffRoutes, route(\"record\", ...))` or adds a page by\n * listing its own route beside these.\n */\nexport const staffRoutes: AppRoute[] = [\n  route(\"home\", exactPath(\"/\"), (_, { session, redirecting }) => {\n    switch (workKind(session)) {\n      case \"administrator\":\n        return <CaseworkSetupPage />;\n      case \"supervisor\":\n        return <CaseworkTeamReviewsPage />;\n      case \"reviewer\":\n        return <CaseworkReviewsPage />;\n      case \"registrar\":\n        return redirecting ? <Loading /> : <RecordListPage />;\n    }\n  }),\n  route(\"records\", registerPath(\"records\"), () => <RecordListPage />),\n  route(\"start\", matchStartRoute, (m, c) => (\n    <StartPage actionId={m.actionId} useTask={c.useCreateTask} />\n  )),\n  route(\"help\", exactPath(\"/help\"), () => <HelpPage />),\n  ...dashboardRoutes,\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(\"action\", registerPath(\"action\"), (m, c) => (\n    <RecordActionPage actionId={m.actionId} recordId={m.id} useTask={c.useCreateTask} />\n  )),\n  route(\"entity-records\", entityPath(\"entityRecords\"), (m) => (\n    <RecordListPage entity={m.entity} />\n  )),\n  route(\"entity-create-record\", entityPath(\"entityCreateRecord\"), (m, c) => (\n    <CreateRecordPage entity={m.entity} useTask={c.useCreateTask} />\n  )),\n  route(\"entity-record-action\", entityPath(\"entityRecordAction\"), (m, c) => (\n    <RecordActionPage entity={m.entity} actionId={m.actionId} useTask={c.useCreateTask} />\n  )),\n  route(\"entity-action\", entityPath(\"entityAction\"), (m, c) => (\n    <RecordActionPage\n      entity={m.entity}\n      actionId={m.actionId}\n      recordId={m.id}\n      useTask={c.useCreateTask}\n    />\n  )),\n  route(\"entity-record\", entityPath(\"entityRecord\"), (m) => (\n    <RecordDetailPage entity={m.entity} id={m.id} />\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(\"casework-reviews\", exactPath(\"/casework\", \"/casework/reviews\"), () => (\n    <CaseworkReviewsPage />\n  )),\n  route(\"casework-team-reviews\", exactPath(\"/casework/team-reviews\"), () => (\n    <CaseworkTeamReviewsPage />\n  )),\n  route(\"casework-my-decisions\", exactPath(\"/casework/decisions\"), () => (\n    <CaseworkMyDecisionsPage />\n  )),\n  route(\n    \"casework-how-review-works\",\n    exactPath(\"/casework/how-review-works\"),\n    () => <CaseworkHowReviewWorksPage />,\n  ),\n  route(\"casework-staffing\", exactPath(\"/casework/staffing\"), () => (\n    <CaseworkStaffingPage />\n  )),\n  route(\"casework-setup\", exactPath(\"/casework/setup\"), () => <CaseworkSetupPage />),\n  route(\n    \"casework-review\",\n    (path) => {\n      const parts = path.split(\"/\").filter(Boolean).map(decodeSegment);\n      return parts[0] === \"casework\" &&\n        parts[1] === \"reviews\" &&\n        parts.length === 3 &&\n        parts[2] !== null\n        ? { taskId: parts[2] }\n        : null;\n    },\n    (m) => <CaseworkReviewPage taskId={m.taskId} />,\n  ),\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];\n\n/**\n * The places named by the model's plural labels, and by the pages' own titles\n * while the model is not read yet; the reviewer's queue is always named as\n * that page is.\n */\nfunction ModelLabelledStaffApp(props: StaffAppProps) {\n  const pages = usePagesContent();\n  const entities = useRegister().entities;\n  const records = entities?.record.pluralLabel ?? pages.recordListTitle;\n  const requestEntities = entities ? navigationRequests(entities) : [];\n  const requests =\n    requestEntities.length === 1\n      ? requestEntities[0]!.pluralLabel\n      : pages.requestListTitle;\n  const labels = useMemo(\n    () => ({ records, requests, reviewQueue: pages.queueTitle }),\n    [records, requests, pages.queueTitle],\n  );\n  return <StaffWork {...props} labels={labels} />;\n}\n\nfunction ProtectedStaffApp(props: StaffAppProps) {\n  return props.labels ? (\n    <StaffWork {...props} labels={props.labels} />\n  ) : (\n    <ModelLabelledStaffApp {...props} />\n  );\n}\n\nfunction StaffWork(props: StaffAppProps & { labels: StaffAppLabels }) {\n  const session = useAuthority();\n  const route = useRoute();\n  // A queue view carries its filters in the hash query string; the page is\n  // decided by the path portion alone.\n  const { path } = splitRoute(route);\n  const routes = useRegisterRoutes();\n  const casework = useCaseworkContent();\n  const shell = useShellContent();\n  // The model is read here, not through `useRegister`, so an app that names\n  // its labels reads nothing it does not use.\n  const modelRead = useModel();\n  const model = modelRead.data;\n  const entities = useMemo(\n    () => (model ? registerEntities(model.entities) : null),\n    [model],\n  );\n  const modelHome = modelHomeRoute(session, routes, entities, model);\n  // The starts are read once the model is, since a session that lists no\n  // record may still start something. A Casework session has no registry\n  // profile to read them for.\n  const startsRead = useStarts({\n    enabled: Boolean(model) && !session.caseworkProfile,\n  });\n  const pages = usePagesContent();\n  // A session that decides requests opens on their queue only where it may\n  // list one; otherwise it opens where any session that lists nothing does.\n  const queuesRequests =\n    session.decidesRequests &&\n    Boolean(entities && navigationRequests(entities).length > 0);\n  const startsLanding =\n    !session.caseworkProfile &&\n    !queuesRequests &&\n    opensOnStarts(\n      model,\n      startsRead.data,\n      startsRead.isError && !startsRead.data,\n      routes,\n    )\n      ? startsPath\n      : null;\n  // A session that lists no record waits for its starts before it is sent anywhere.\n  const startsPending =\n    startsRead.isPending &&\n    Boolean(model) &&\n    !session.caseworkProfile &&\n    !queuesRequests &&\n    !model?.home &&\n    !(model && listsRecords(model.entities));\n  // A registrar opens on the dashboard where the host serves one. The root\n  // holds on its loading state until that read settles, so the landing is\n  // decided once.\n  // A read that has failed once is settled: a later refetch of it must not\n  // send a registrar back to the loading state.\n  const dashboardRead = useDashboard();\n  const dashboard = dashboardLanding(session, {\n    isPending: dashboardRead.isPending && !dashboardRead.errorUpdateCount,\n    data: dashboardRead.data,\n  });\n  // One page, one URL: the home the model names, or else the reviewer's\n  // request queue, is reached by redirect instead of rendering the same page\n  // twice in history.\n  const redirect = rootRedirect(\n    session,\n    routes,\n    entities,\n    model,\n    modelRead.isPending || startsPending,\n    dashboard,\n    startsLanding,\n  );\n  useEffect(() => {\n    if (path === \"/\" && redirect) navigate(redirect);\n  }, [path, redirect]);\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 ?? staffRoutes, path, routes, {\n    ...parts,\n    session,\n    redirecting: Boolean(redirect) || dashboard === undefined,\n  }) ?? (\n    <ErrorPanel\n      error={unavailableError(shell.unavailable)}\n      unavailableTitle={shell.unavailable}\n    />\n  );\n  const dashboardNav = useDashboardNav();\n  const groups = useMemo(\n    () =>\n      navGroups(props.navigation ?? staffNavigation, {\n        session,\n        casework,\n        labels: props.labels,\n        routes,\n        record: recordPlaces(routes, entities, model),\n        starts: {\n          items:\n            startsLanding ||\n            (model &&\n              unlistedStarts(startsRead.data ?? [], model.entities, routes)\n                .length > 0)\n              ? [{ path: startsPath, label: pages.startsHeading, icon: Play }]\n              : [],\n          landing: startsLanding !== null,\n        },\n        dashboard: dashboardNav,\n      }),\n    [\n      props.navigation,\n      session,\n      casework,\n      props.labels,\n      routes,\n      entities,\n      model,\n      startsRead.data,\n      startsLanding,\n      pages.startsHeading,\n      dashboardNav,\n    ],\n  );\n  // A record a field refers to opens on its own page where the app has one.\n  const referenceHref = useCallback(\n    (entity: string, id: string) => {\n      const target = entities && recordPath(routes, entities, entity, id);\n      return target ? `#${target}` : null;\n    },\n    [entities, routes],\n  );\n  return (\n    <WorkFrame\n      displayName={session.displayName}\n      app={session.app ?? \"staff\"}\n      brand={shell.brand}\n      groups={groups}\n      homePath={homeOf(session, routes, modelHome, dashboard ?? null)}\n      route={route}\n    >\n      {props.recoveryNotice === undefined ? <RecoveryNotice /> : props.recoveryNotice}\n      {props.pendingUploadsNotice === undefined ? <PendingUploadsNotice /> : props.pendingUploadsNotice}\n      {session.caseworkProfile && (\n        <Suspense fallback={null}>\n          <ReviewDecisionPendingNotice />\n          <StaffingPendingNotice />\n        </Suspense>\n      )}\n      <ReferenceHrefProvider href={referenceHref}>\n        <Suspense fallback={<Loading />}>\n          <div key={route}>{page}</div>\n        </Suspense>\n      </ReferenceHrefProvider>\n    </WorkFrame>\n  );\n}\n\n/**\n * A staff register work app: the work shell's places, the register's own\n * record and request pages, the pages of every other record entity under\n * `routes.entity`, and Casework's review task queue, review, staffing and\n * setup pages. A model that names `places` gets one nav item per place, and\n * one that names a `home` or places opens there; a register with no request\n * entity offers no requests place. It takes no register nouns of its own;\n * `useRegisterRoutes()` supplies the register's 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 StaffApp(props: StaffAppProps) {\n  const route = useRoute();\n  return (\n    <SessionBoundary\n      audience=\"staff\"\n      introduction={\n        splitRoute(route).path === \"/help\" ? (\n          <StaffHelpIntroduction />\n        ) : (\n          <Introduction audience=\"staff\" />\n        )\n      }\n    >\n      <ProtectedStaffApp {...props} />\n    </SessionBoundary>\n  );\n}\n\nfunction StaffHelpIntroduction() {\n  const shell = useShellContent();\n  return (\n    <PublicShell audience=\"staff\">\n      <BackLink href=\"/\">{shell.back}</BackLink>\n      <HelpPage />\n    </PublicShell>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/pages/staff-app.tsx"
    }
  ],
  "type": "registry:block"
}