{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dashboard-records",
  "title": "Records behind a dashboard count",
  "description": "The current records behind one live count, read by the cell the route names, with the register's own columns and record links and a show-more control.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0"
  ],
  "registryDependencies": [
    "@registrystack/dashboard-cells",
    "@registrystack/dashboard-content",
    "@registrystack/ui-button",
    "@registrystack/lib-notice",
    "@registrystack/lib-content",
    "@registrystack/lib-format",
    "@registrystack/record-table",
    "@registrystack/pages-record",
    "@registrystack/pages-register-routes",
    "@registrystack/shell-back-link",
    "@registrystack/shell-empty-state",
    "@registrystack/shell-error-panel",
    "@registrystack/shell-loading",
    "@registrystack/shell-page-heading",
    "@registrystack/shell-routing",
    "@registrystack/shell-content"
  ],
  "files": [
    {
      "path": "dashboard/dashboard-records.tsx",
      "content": "import { unavailableError } from \"@registrystack/app-runtime\";\nimport type { EntityModel, RecordView } from \"@registrystack/app-runtime\";\nimport { useDashboardCohort } from \"@registrystack/app-runtime/react\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  useDashboardContent,\n  type DashboardContent,\n} from \"@/blocks/dashboard/dashboard-content\";\nimport {\n  dashboardTargetOf,\n  dashboardRoute,\n} from \"@/blocks/dashboard/dashboard-target\";\nimport { Notice } from \"@/blocks/lib/notice\";\nimport { useLocale } from \"@/blocks/lib/content\";\nimport { fill } from \"@/blocks/lib/format\";\nimport { RecordTable } from \"@/blocks/record/record-table\";\nimport { BackLink } from \"@/blocks/shell/back-link\";\nimport { EmptyState } from \"@/blocks/shell/empty-state\";\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\";\nimport { useShellContent } from \"@/blocks/shell/shell-content\";\nimport {\n  fieldOf,\n  recordPath,\n  RecordEntityGate,\n  recordTitle,\n  type RegisterEntities,\n} from \"@/blocks/pages/record\";\nimport { useRegisterRoutes } from \"@/blocks/pages/register-routes\";\n\n/** The count line: the plural form and the number written in `locale`. */\nfunction countWords(\n  c: DashboardContent,\n  count: number,\n  locale: string,\n): string {\n  return fill(c.recordsCount, { count }, locale);\n}\n\n/**\n * The current records behind one live count. The target comes from the route;\n * the host rebuilds the filter and refuses a target that no longer matches\n * its widget (the page then shows that refusal with a retry), so nothing\n * here builds or checks a filter.\n */\nexport function DashboardRecordsPage() {\n  const c = useDashboardContent(),\n    target = dashboardTargetOf(splitRoute(useRoute()).query);\n  if (!target)\n    return (\n      <>\n        <BackLink href={dashboardRoute}>{c.recordsBack}</BackLink>\n        <Notice tone=\"warning\" title={c.recordsInvalidTitle}>\n          <p>{c.recordsInvalid}</p>\n        </Notice>\n      </>\n    );\n  return <Cohort target={target} />;\n}\n\ntype Target = NonNullable<ReturnType<typeof dashboardTargetOf>>;\n\nfunction Cohort({ target }: { target: Target }) {\n  const c = useDashboardContent(),\n    locale = useLocale(),\n    query = useDashboardCohort(target),\n    entityId = query.data?.pages[0]?.entity;\n  const back = <BackLink href={dashboardRoute}>{c.recordsBack}</BackLink>;\n  if (query.isPending)\n    return (\n      <>\n        {back}\n        <Loading />\n      </>\n    );\n  if (query.error || !query.cohort || !entityId)\n    return (\n      <>\n        {back}\n        <ErrorPanel\n          error={query.error ?? unavailableError(c.unavailable)}\n          retry={() => void query.refetch()}\n        />\n      </>\n    );\n  const cohort = query.cohort,\n    cell = cohort.cellLabel ?? cohort.title;\n  return (\n    <>\n      {back}\n      <PageHeading\n        eyebrow={c.recordsEyebrow}\n        title={\n          cell === cohort.title\n            ? cohort.title\n            : fill(c.recordsTitle, { title: cohort.title, cell }, locale)\n        }\n        description={c.recordsDescription}\n      />\n      <p role=\"status\">\n        {countWords(c, cohort.observedCount, locale)}\n      </p>\n      <p className=\"dashboard-note\">{c.recordsLiveHelp}</p>\n      <RecordEntityGate entity={entityId}>\n        {(entities, entity) => (\n          <CohortList\n            entities={entities}\n            entity={entity}\n            cell={cell}\n            records={query.items ?? []}\n          />\n        )}\n      </RecordEntityGate>\n      {query.hasNextPage && (\n        <Button\n          variant=\"outline\"\n          disabled={query.isFetchingNextPage}\n          onClick={() => void query.fetchNextPage()}\n        >\n          {c.recordsMore}\n        </Button>\n      )}\n    </>\n  );\n}\n\nfunction CohortList({\n  entities,\n  entity,\n  cell,\n  records,\n}: {\n  entities: RegisterEntities;\n  entity: EntityModel;\n  cell: string;\n  records: readonly RecordView[];\n}) {\n  const c = useDashboardContent(),\n    routes = useRegisterRoutes(),\n    locale = useLocale();\n  if (records.length === 0)\n    return <EmptyState title={c.recordsEmpty}>{\"\"}</EmptyState>;\n  const columns = entity.list.columns.flatMap((id) => {\n    const field = fieldOf(entity, id);\n    return field ? [field] : [];\n  });\n  return (\n    <RecordTable\n      caption={fill(c.recordsListCaption, { cell }, locale)}\n      columns={columns}\n      linkColumn={\n        columns.find((field) => field.id === entity.title) ?? columns[0]\n      }\n      records={records}\n      recordHref={(record) => {\n        const path = recordPath(routes, entities, entity.id, record.id);\n        return path ? `#${path}` : \"#\";\n      }}\n      viewLabel={(record) => recordTitle(entity, record, locale) ?? record.id}\n    />\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/dashboard/dashboard-records.tsx"
    }
  ],
  "type": "registry:block"
}