{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-data-pagination",
  "type": "registry:block",
  "title": "App, pagination",
  "description": "A pagination row: a summary built from the page, rows per page and the total (it changes with the page and is read out politely), previous and next, numbered pages with a gap marker, and aria-current. It moves the marker and the summary; the rows are the host's.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-data-pagination/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-data-pagination/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t, req } from '../_shared/schema';\n\nconst schema = z.object({\n  /** Names the navigation landmark; not shown. */\n  title: t(40),\n  /** The line \"Showing 11 to 20 of 210 bookings\" is built from these words and the numbers, so it follows the page. */\n  summary: z.object({ showing: t(20), to: t(10), of: t(10), noun: t(30) }),\n  /** Rows per page and rows in all, as plain numbers written as text. */\n  perPage: t(6),\n  total: t(10),\n  /** Page labels in order. Use '…' for a gap; it is not a link. */\n  pages: z.array(req(6)).min(3).max(9),\n  /** The label of the current page (matches one of `pages`). */\n  active: t(6),\n  previous: req(20),\n  next: req(20),\n});\n\nexport const spec = defineSpec({\n  type: 'app-data-pagination',\n  headingSlot: false, // the title is the pager's label, not a section heading\n  aliases: ['app/data-pagination'],\n  name: 'App, pagination',\n  category: 'app',\n  role: 'body',\n  description: 'A pagination row: a summary built from the page, rows per page and the total (it changes with the page and is read out politely), previous and next, numbered pages with a gap marker, and aria-current. It moves the marker and the summary; the rows are the host\\'s.',\n  schema,\n  defaults: {\n    \"title\": \"Pagination\",\n    \"summary\": {\n      \"showing\": \"Showing\",\n      \"to\": \"to\",\n      \"of\": \"of\",\n      \"noun\": \"items\"\n    },\n    \"perPage\": \"10\",\n    \"total\": \"210\",\n    \"pages\": [\n      \"1\",\n      \"2\",\n      \"3\",\n      \"…\",\n      \"21\"\n    ],\n    \"active\": \"2\",\n    \"previous\": \"Previous\",\n    \"next\": \"Next\"\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-data-pagination/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-data-pagination/index.tsx",
      "content": "import { useId } from 'react';\nimport { ChevronLeft, ChevronRight } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { cn } from '../../lib/utils';\nimport { Button } from '../../ui/button';\nimport { Container, Section } from '../_shared/kit';\nimport { parseAmount, useSynced } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppDataPagination({ props }: BlockProps<Props>) {\n  const id = useId();\n  const [current, setCurrent] = useSynced(props.active);\n  const real = props.pages.map((p, i) => ({ p, i })).filter(({ p }) => p !== '…');\n  const at = real.findIndex(({ p }) => p === current);\n  const page = parseAmount(current) ?? 1;\n  const per = Math.max(1, parseAmount(props.perPage) ?? 10);\n  const total = Math.max(0, parseAmount(props.total) ?? 0);\n  const from = total === 0 ? 0 : Math.min(total, (page - 1) * per + 1);\n  const until = Math.min(total, page * per);\n  const go = (to: number) => real[to] && setCurrent(real[to].p);\n  return (\n    <Section className=\"py-8\">\n      <Container className=\"flex flex-col items-center gap-4 @xl:flex-row @xl:justify-between\">\n        <p role=\"status\" className=\"text-kh-small tabular-nums text-kh-muted\">\n          <Text path={['summary', 'showing']} value={props.summary.showing} as=\"span\" /> {from} <Text path={['summary', 'to']} value={props.summary.to} as=\"span\" /> {until}{' '}\n          <Text path={['summary', 'of']} value={props.summary.of} as=\"span\" /> {total} <Text path={['summary', 'noun']} value={props.summary.noun} as=\"span\" />\n        </p>\n        <nav aria-labelledby={id}>\n          <span id={id} className=\"sr-only\">\n            <Text path={['title']} value={props.title} as=\"span\" />\n          </span>\n          <ul className=\"flex flex-wrap items-center justify-center gap-1\">\n            <li>\n              <Button variant=\"ghost\" disabled={at <= 0} onClick={() => go(at - 1)} icon={<ChevronLeft aria-hidden className=\"size-4\" />}>\n                <Text path={['previous']} value={props.previous} as=\"span\" />\n              </Button>\n            </li>\n            {props.pages.map((p, i) => (\n              <li key={i}>\n                {p === '…' ? (\n                  <span aria-hidden className=\"inline-flex min-h-11 min-w-8 items-center justify-center text-kh-muted\">\n                    <Text path={['pages', i]} value={p} as=\"span\" />\n                  </span>\n                ) : (\n                  <button\n                    type=\"button\"\n                    aria-current={p === current ? 'page' : undefined}\n                    onClick={() => setCurrent(p)}\n                    className={cn(\n                      'inline-flex min-h-11 min-w-11 items-center justify-center rounded-kh px-2 text-kh-small font-medium tabular-nums focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus)',\n                      p === current ? 'bg-kh-ink text-kh-on-ink' : 'text-kh-ink-2 hover:bg-kh-surface-2 hover:text-kh-ink',\n                    )}\n                  >\n                    <Text path={['pages', i]} value={p} as=\"span\" />\n                  </button>\n                )}\n              </li>\n            ))}\n            <li>\n              <Button variant=\"ghost\" disabled={at < 0 || at >= real.length - 1} onClick={() => go(at + 1)} iconEnd={<ChevronRight aria-hidden className=\"size-4\" />}>\n                <Text path={['next']} value={props.next} as=\"span\" />\n              </Button>\n            </li>\n          </ul>\n        </nav>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppDataPagination);\n"
    }
  ]
}
