{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pages-casework-my-decisions",
  "title": "Casework my decisions page",
  "description": "The reviews the signed-in officer has decided, with the outcome label each decision's pinned policy names and when it was decided, and recovery when a list position has expired.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/casework-shared",
    "@registrystack/lib-content",
    "@registrystack/lib-format",
    "@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"
  ],
  "files": [
    {
      "path": "pages/casework-my-decisions.tsx",
      "content": "import { ScrollRegion } from \"@/blocks/lib/scroll-region\";\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\nimport { problemView } from \"@registrystack/app-runtime\";\nimport { useOwnReviewDecisions } 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 { caseworkDateTime, Notice } from \"@/blocks/casework/shared\";\nimport { fill } from \"@/blocks/lib/format\";\nimport { useBlockContent, useLocale } from \"@/blocks/lib/content\";\nimport { tabCursors, useTabCursors } from \"@/blocks/lib/tab-memory\";\nimport { WhenProfile } from \"@/blocks/pages/casework-landing\";\nimport { useReviewPageContent } 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 { navigate, splitRoute, useRoute } from \"@/blocks/shell/routing\";\n\nconst DECISIONS_PATH = \"/casework/decisions\";\nconst decisionCursors = tabCursors(\"casework.decisions.cursors\");\n\ninterface DecisionsView {\n  cursor?: string;\n  page: number;\n}\n\nfunction parseDecisionsView(query: URLSearchParams): DecisionsView {\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 writeDecisionsView(view: DecisionsView): 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 `${DECISIONS_PATH}${search ? `?${search}` : \"\"}`;\n}\n\nfunction DecisionsList() {\n  const r = useReviewPageContent();\n  const pagerWords = useBlockContent();\n  const locale = useLocale();\n  const view = parseDecisionsView(splitRoute(useRoute()).query);\n  const read = useOwnReviewDecisions(view.cursor ? { cursor: view.cursor } : {});\n  const cursors = useTabCursors(decisionCursors, 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 expired = problemView(read.error).code === \"review.result-expired\";\n\n  /** Reads the first page again, withholding what an earlier read cached. */\n  function reset() {\n    // Reset before the route remounts, so a refused continuation cannot show\n    // cached decisions while the fresh first page is pending.\n    void read.resetFirstPage({});\n    cursors.restart();\n  }\n  function restart() {\n    reset();\n    navigate(writeDecisionsView({ page: 1 }));\n  }\n\n  return (\n    <>\n      {read.error ? (\n        expired && view.cursor ? (\n          <Notice>\n            <p>{r.decisionsPositionExpired}</p>\n            <Button\n              variant=\"outline\"\n              render={\n                <a\n                  href={`#${writeDecisionsView({ page: 1 })}`}\n                  onClick={reset}\n                />\n              }\n            >\n              {r.decisionsFirstPage}\n            </Button>\n          </Notice>\n        ) : (\n          <ErrorPanel\n            error={read.error}\n            retry={() => (view.cursor ? restart() : void read.refetch())}\n          />\n        )\n      ) : !read.data ? (\n        <Loading />\n      ) : items.length === 0 ? (\n        <section>\n          <h2>\n            {partial || nextCursor ? r.decisionsEmptyPage : r.decisionsEmpty}\n          </h2>\n          <p className=\"muted\">\n            {nextCursor\n              ? r.decisionsNextPageHint\n              : partial\n                ? r.decisionsPartial\n                : r.decisionsEmptyHint}\n          </p>\n        </section>\n      ) : (\n        <ScrollRegion\n          className=\"table-wrap casework-reviews\"\n          label={r.decisionsCaption}\n        >\n          <Table>\n            <TableCaption>{r.decisionsCaption}</TableCaption>\n            <TableHeader>\n              <TableRow>\n                <TableHead>{r.decisionsOutcome}</TableHead>\n                <TableHead>{r.decisionsDecidedAt}</TableHead>\n              </TableRow>\n            </TableHeader>\n            <TableBody>\n              {items.map((row) => {\n                // The outcome is the label the decision's pinned policy\n                // names, never a word inferred from a code.\n                const outcome =\n                  row.decisionReceipt.outcomeLabel?.trim() ||\n                  r.decisionsOutcomeUnavailable;\n                const when = caseworkDateTime(\n                  row.decisionReceipt.decidedAt,\n                  locale,\n                );\n                return (\n                  <TableRow key={row.taskId}>\n                    <TableCell>\n                      <a\n                        className=\"row-link\"\n                        href={`#/casework/reviews/${encodeURIComponent(row.taskId)}`}\n                        aria-label={fill(\n                          r.decisionsRowName,\n                          { outcome, time: when },\n                          locale,\n                        )}\n                      >\n                        {outcome}\n                      </a>\n                    </TableCell>\n                    <TableCell>\n                      <time dateTime={row.decisionReceipt.decidedAt}>{when}</time>\n                    </TableCell>\n                  </TableRow>\n                );\n              })}\n            </TableBody>\n          </Table>\n        </ScrollRegion>\n      )}\n      {partial && items.length > 0 && <p className=\"muted\">{r.decisionsPartial}</p>}\n      {read.data && !read.error && items.length > 0 && (\n        <p className=\"result-count\">{fill(r.decisionsCount, { count: items.length }, locale)}</p>\n      )}\n      {!read.error && (previous || nextCursor) && (\n        <div className=\"actions w-auto gap-1\">\n          {previous && (\n            <Button\n              render={\n                <a\n                  href={`#${writeDecisionsView({ 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={`#${writeDecisionsView({ 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 * The reviews the signed-in officer has decided, from Casework's own\n * decisions read: each with the outcome label its pinned policy names, its\n * queue and when it was decided. A decided review stays here, with its\n * history and notes, after the approved change is applied. The keyed\n * requester reference the read carries is never shown.\n */\nexport function CaseworkMyDecisionsPage() {\n  const r = useReviewPageContent();\n  return (\n    <WhenProfile profiles={[\"staff\", \"supervisor\"]}>\n      <PageHeading title={r.decisionsTitle} description={r.decisionsDescription} />\n      <DecisionsList />\n    </WhenProfile>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/pages/casework-my-decisions.tsx"
    }
  ],
  "type": "registry:block"
}