{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages-casework-team-reviews",
  "title": "Casework team reviews page",
  "description": "A supervisor's accountability list of every review in the queues they supervise: its queue, whether it is open, held or decided, and any staffing diagnostic Casework states.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/lib-content",
    "@registrystack/lib-scroll-region",
    "@registrystack/lib-tab-memory",
    "@registrystack/pages-casework-landing",
    "@registrystack/pages-casework-review-content",
    "@registrystack/shell-error-panel",
    "@registrystack/shell-loading",
    "@registrystack/shell-page-heading",
    "@registrystack/shell-routing",
    "@registrystack/ui-button",
    "@registrystack/ui-table",
    "@registrystack/lib-format"
  ],
  "files": [
    {
      "path": "pages/casework-team-reviews.tsx",
      "content": "import { ScrollRegion } from \"@/blocks/lib/scroll-region\";\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\nimport type {\n  ReviewTaskStatus,\n  SupervisoryReviewTask,\n} from \"@registrystack/app-runtime\";\nimport { useSupervisoryReviews } from \"@registrystack/app-runtime/react\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  Table,\n  TableBody,\n  TableCaption,\n  TableCell,\n  TableHead,\n  TableHeader,\n  TableRow,\n} from \"@/components/ui/table\";\nimport { useBlockContent, useLocale } from \"@/blocks/lib/content\";\nimport { fill } from \"@/blocks/lib/format\";\nimport { tabCursors, useTabCursors } from \"@/blocks/lib/tab-memory\";\nimport { WhenProfile } from \"@/blocks/pages/casework-landing\";\nimport {\n  useReviewPageContent,\n  type ReviewPageContent,\n} from \"@/blocks/pages/casework-review-content\";\nimport { ErrorPanel } from \"@/blocks/shell/error-panel\";\nimport { Loading } from \"@/blocks/shell/loading\";\nimport { PageHeading } from \"@/blocks/shell/page-heading\";\nimport { splitRoute, useRoute } from \"@/blocks/shell/routing\";\n\nconst TEAM_REVIEWS_PATH = \"/casework/team-reviews\";\nconst teamCursors = tabCursors(\"casework.team-reviews.cursors\");\n\n/** Where the list stands: its place, in the hash query. */\ninterface TeamView {\n  cursor?: string;\n  page: number;\n}\n\nfunction parseTeamView(query: URLSearchParams): TeamView {\n  const cursor = query.get(\"cursor\") || undefined;\n  // A page number means nothing without the cursor that reached it.\n  return {\n    cursor,\n    page: cursor ? Math.max(2, Number(query.get(\"page\")) || 2) : 1,\n  };\n}\n\nfunction writeTeamView(view: TeamView): string {\n  const params = new URLSearchParams();\n  if (view.cursor) params.set(\"cursor\", view.cursor);\n  if (view.cursor && view.page > 1) params.set(\"page\", String(view.page));\n  const search = params.toString();\n  return `${TEAM_REVIEWS_PATH}${search ? `?${search}` : \"\"}`;\n}\n\nfunction stateWord(r: ReviewPageContent, state: ReviewTaskStatus): string {\n  switch (state) {\n    case \"open\":\n      return r.teamStateOpen;\n    case \"held\":\n      return r.teamStateHeld;\n    case \"decided\":\n      return r.teamStateDecided;\n  }\n}\n\nfunction TeamRow({ row }: { row: SupervisoryReviewTask }) {\n  const r = useReviewPageContent();\n  return (\n    <TableRow>\n      <TableCell>{row.queueLabel}</TableCell>\n      <TableCell>\n        {stateWord(r, row.state)}\n        {row.staffingDiagnostic === \"no-cover-available\" && (\n          <span className=\"muted block\">{r.teamNoCover}</span>\n        )}\n        {row.staffingDiagnostic === \"insufficient-distinct-approvers\" && (\n          <span className=\"muted block\">{r.teamTooFewApprovers}</span>\n        )}\n      </TableCell>\n    </TableRow>\n  );\n}\n\n/**\n * The queues with reviews still waiting for a decision (open or held), in the\n * order their first review appears, each with its count. Counts are only true\n * of the whole list, so none is made from a page that is not all of it.\n */\nfunction waitingByQueue(items: SupervisoryReviewTask[]) {\n  const counts = new Map<string, { label: string; count: number }>();\n  for (const row of items) {\n    if (row.state === \"decided\") continue;\n    const entry = counts.get(row.queue);\n    if (entry) entry.count += 1;\n    else counts.set(row.queue, { label: row.queueLabel, count: 1 });\n  }\n  return [...counts];\n}\n\nfunction TeamReviewsList() {\n  const r = useReviewPageContent();\n  const locale = useLocale();\n  const pagerWords = useBlockContent();\n  const view = parseTeamView(splitRoute(useRoute()).query);\n  const read = useSupervisoryReviews(view.cursor ? { cursor: view.cursor } : {});\n  const cursors = useTabCursors(teamCursors, view);\n  const previous = cursors.previous;\n  const items = read.data?.items ?? [];\n  const nextCursor = read.data?.nextCursor;\n  const partial = read.data !== undefined && read.data.status !== \"complete\";\n  const wholeList =\n    read.data !== undefined && !partial && !view.cursor && !nextCursor;\n  const waiting = wholeList ? waitingByQueue(items) : [];\n  return (\n    <>\n      {waiting.length > 0 && (\n        <div>\n          <p>{r.teamWaitingIntro}</p>\n          <ul>\n            {waiting.map(([queue, { label, count }]) => (\n              <li key={queue}>\n                <a\n                  href={`#/casework/reviews?${new URLSearchParams({ queue })}`}\n                >\n                  {fill(r.teamWaitingLine, { queue: label, count }, locale)}\n                </a>\n              </li>\n            ))}\n          </ul>\n        </div>\n      )}\n      {read.error ? (\n        <ErrorPanel error={read.error} retry={() => void read.refetch()} />\n      ) : !read.data ? (\n        <Loading />\n      ) : items.length === 0 ? (\n        // A page cut short can be empty and still continue; only the end of\n        // the list says nothing is there.\n        !nextCursor && !partial && <p className=\"muted\">{r.teamEmpty}</p>\n      ) : (\n        <ScrollRegion\n          className=\"table-wrap casework-reviews\"\n          label={r.teamCaption}\n        >\n          <Table>\n            <TableCaption>{r.teamCaption}</TableCaption>\n            <TableHeader>\n              <TableRow>\n                <TableHead>{r.teamQueue}</TableHead>\n                <TableHead>{r.teamState}</TableHead>\n              </TableRow>\n            </TableHeader>\n            <TableBody>\n              {items.map((row) => (\n                <TeamRow key={row.taskId} row={row} />\n              ))}\n            </TableBody>\n          </Table>\n        </ScrollRegion>\n      )}\n      {partial && <p className=\"muted\">{r.teamPartial}</p>}\n      {read.data && items.length > 0 && (\n        <p className=\"result-count\">{fill(r.teamCount, { count: items.length }, locale)}</p>\n      )}\n      {(previous || nextCursor) && (\n        <div className=\"actions w-auto gap-1\">\n          {previous && (\n            <Button\n              render={\n                <a\n                  href={`#${writeTeamView({ cursor: previous.cursor, page: previous.page })}`}\n                  onClick={cursors.back}\n                />\n              }\n              variant=\"outline\"\n              size=\"icon-sm\"\n            >\n              <ChevronLeft aria-hidden=\"true\" />\n              <span className=\"sr-only\">{pagerWords.previous}</span>\n            </Button>\n          )}\n          {nextCursor && (\n            <Button\n              render={\n                <a\n                  href={`#${writeTeamView({ cursor: nextCursor, page: view.page + 1 })}`}\n                  onClick={() => cursors.next(nextCursor, view.page + 1)}\n                />\n              }\n              variant=\"outline\"\n              size=\"icon-sm\"\n            >\n              <ChevronRight aria-hidden=\"true\" />\n              <span className=\"sr-only\">{pagerWords.next}</span>\n            </Button>\n          )}\n        </div>\n      )}\n    </>\n  );\n}\n\n/**\n * A supervisor's accountability list: every review in the queues they\n * supervise, as Casework's supervision read carries it. A row shows its queue,\n * whether it is open, held or decided, and Casework's own statement that no\n * one is available to take it. The read carries no reviewer, age, due date or\n * stage, so the page shows none, and no row opens a review.\n */\nexport function CaseworkTeamReviewsPage() {\n  const r = useReviewPageContent();\n  return (\n    <WhenProfile profiles={[\"supervisor\"]}>\n      <PageHeading\n        title={r.teamTitle}\n        description={r.teamDescription}\n        action={\n          <Button\n            variant=\"outline\"\n            render={<a href=\"#/casework/staffing\" />}\n          >\n            {r.teamStaffingLink}\n          </Button>\n        }\n      />\n      <TeamReviewsList />\n    </WhenProfile>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/pages/casework-team-reviews.tsx"
    }
  ],
  "type": "registry:block"
}