{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dashboard-cells",
  "title": "Dashboard counts",
  "description": "How a count is worded as BReg disclosed it (exact, rounded, withheld), the link to the records behind a live count, and the route that link writes and reads.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/lib-format",
    "@registrystack/dashboard-content",
    "@registrystack/lib-content"
  ],
  "files": [
    {
      "path": "dashboard/dashboard-values.ts",
      "content": "import type {\n  DashboardCell,\n  DashboardWidgetContext,\n} from \"@registrystack/app-runtime\";\nimport { fill } from \"@/blocks/lib/format\";\nimport type { DashboardContent } from \"@/blocks/dashboard/dashboard-content\";\n\n/**\n * A count in the words of its disclosure, exactly as BReg disclosed it, its\n * numbers written in `locale`: a rounded count is approximate, a withheld one\n * names the minimum BReg reports. Nothing here rounds or recomputes.\n */\nexport function disclosedValue(\n  c: DashboardContent,\n  locale: string,\n  cell: Pick<DashboardCell, \"value\" | \"status\">,\n  minimumCount?: number,\n): string {\n  const number = new Intl.NumberFormat(locale);\n  if (cell.value === null)\n    return minimumCount === undefined\n      ? c.withheldWithoutMinimum\n      : fill(c.belowMinimum, { count: number.format(minimumCount) }, locale);\n  const value = number.format(cell.value);\n  return cell.status === \"rounded\" ? fill(c.approximately, { value }, locale) : value;\n}\n\n/** The status column's word for a disclosure state. */\nexport function statusLabel(\n  c: DashboardContent,\n  status: DashboardCell[\"status\"],\n): string {\n  return status === \"exact\"\n    ? c.exact\n    : status === \"rounded\"\n      ? c.rounded\n      : c.withheld;\n}\n\n/** The minimum count BReg states for a released widget, when it states one. */\nexport function minimumCountOf(\n  context: DashboardWidgetContext | undefined,\n): number | undefined {\n  return context?.disclosure?.minimumCount;\n}\n",
      "type": "registry:block",
      "target": "@components/dashboard/dashboard-values.ts"
    },
    {
      "path": "dashboard/dashboard-target.ts",
      "content": "import type { DashboardCellTarget } from \"@registrystack/app-runtime\";\n\n/** The route of the dashboard and of the records behind one of its counts. */\nexport const dashboardRoute = \"/dashboard\";\nexport const dashboardRecordsPath = \"/dashboard/records\";\n\nconst maximumTargetValueLength = 256;\nconst maximumCodeLength = 1024;\n\n/**\n * The route that opens the records behind a cell. It carries only what the\n * host named for the cell; the host rebuilds the filter from it.\n */\nexport function dashboardRecordsRoute(target: DashboardCellTarget): string {\n  const query = new URLSearchParams({\n    widgetId: target.widgetId,\n    period: target.period,\n    binding: target.binding,\n  });\n  if (target.code !== undefined) query.set(\"code\", target.code);\n  return `${dashboardRecordsPath}?${query}`;\n}\n\n/**\n * The cell a records route names, or null where the query is not exactly the\n * one `dashboardRecordsRoute` writes: an unknown, repeated, missing or\n * oversized member is refused.\n */\nexport function dashboardTargetOf(\n  query: URLSearchParams,\n): DashboardCellTarget | null {\n  const keys = [...query.keys()];\n  if (\n    keys.length !== new Set(keys).size ||\n    keys.some((key) => ![\"widgetId\", \"period\", \"binding\", \"code\"].includes(key))\n  )\n    return null;\n  const widgetId = query.get(\"widgetId\"),\n    period = query.get(\"period\"),\n    binding = query.get(\"binding\"),\n    code = query.get(\"code\");\n  if (\n    !widgetId ||\n    !period ||\n    !binding ||\n    [widgetId, period, binding].some(\n      (value) => value.length > maximumTargetValueLength,\n    ) ||\n    (code !== null && (code.length === 0 || code.length > maximumCodeLength))\n  )\n    return null;\n  return {\n    kind: \"dashboard-cell\",\n    widgetId,\n    period,\n    binding,\n    ...(code === null ? {} : { code }),\n  };\n}\n",
      "type": "registry:block",
      "target": "@components/dashboard/dashboard-target.ts"
    },
    {
      "path": "dashboard/dashboard-cell-link.tsx",
      "content": "import { ArrowUpRight } from \"lucide-react\";\nimport type { DashboardCell } from \"@registrystack/app-runtime\";\nimport { useLocale } from \"@/blocks/lib/content\";\nimport { fill } from \"@/blocks/lib/format\";\nimport { useDashboardContent } from \"@/blocks/dashboard/dashboard-content\";\nimport { dashboardRecordsRoute } from \"@/blocks/dashboard/dashboard-target\";\n\n/**\n * A count that opens the records behind it. Only a cell the host named a\n * target for is a link; any other count is plain text.\n */\nexport function DashboardCellLink({\n  cell,\n  label,\n  value,\n  period,\n}: {\n  cell: DashboardCell;\n  /** What the count is of, read with the link. */\n  label: string;\n  /** The count as shown. */\n  value: string;\n  period: string;\n}) {\n  const c = useDashboardContent(),\n    locale = useLocale();\n  if (!cell.drillthrough) return <>{value}</>;\n  return (\n    <a\n      className=\"dashboard-cell-link\"\n      href={`#${dashboardRecordsRoute(cell.drillthrough)}`}\n      aria-label={fill(c.openRecords, { label, value, period }, locale)}\n    >\n      {value}\n      <ArrowUpRight size={14} aria-hidden=\"true\" />\n    </a>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/dashboard/dashboard-cell-link.tsx"
    }
  ],
  "type": "registry:block"
}