{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink/pagination",
  "title": "Pagination",
  "description": "Page navigation with prev/next and jump",
  "dependencies": [
    "ink"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/ink/interaction.json",
    "https://termcn.dev/r/ink/terminal-symbols.json",
    "https://termcn.dev/r/ink/use-theme.json",
    "https://termcn.dev/r/ink/use-unicode.json"
  ],
  "files": [
    {
      "path": "registry/ui/pagination.tsx",
      "content": "import { Box, Text } from \"ink\";\nimport React, { useState } from \"react\";\n\nimport { useInteraction } from \"@/hooks/use-interaction\";\nimport { useTheme } from \"@/hooks/use-theme\";\nimport { useUnicode } from \"@/hooks/use-unicode\";\nimport { resolveTerminalSymbol } from \"@/lib/terminal-symbols\";\n\nexport interface PaginationProps {\n  total: number;\n  current?: number;\n  defaultCurrent?: number;\n  onValueChange?: (page: number) => void;\n  onChange?: (page: number) => void;\n  showEdges?: boolean;\n  siblings?: number;\n  id?: string;\n  autoFocus?: boolean;\n  isActive?: boolean;\n  disabled?: boolean;\n  \"aria-label\"?: string;\n}\n\nconst buildPages = (\n  total: number,\n  current: number,\n  siblings: number\n): (number | \"...\")[] => {\n  if (total <= 7) {\n    return Array.from({ length: total }, (_, i) => i + 1);\n  }\n\n  const pages: (number | \"...\")[] = [1];\n\n  const leftSibling = Math.max(2, current - siblings);\n  const rightSibling = Math.min(total - 1, current + siblings);\n\n  if (leftSibling > 2) {\n    pages.push(\"...\");\n  }\n\n  for (let i = leftSibling; i <= rightSibling; i += 1) {\n    pages.push(i);\n  }\n\n  if (rightSibling < total - 1) {\n    pages.push(\"...\");\n  }\n\n  pages.push(total);\n\n  return pages;\n};\n\nexport const Pagination = ({\n  total,\n  current,\n  defaultCurrent = 1,\n  onValueChange,\n  onChange,\n  showEdges = true,\n  siblings = 1,\n  id,\n  autoFocus = false,\n  isActive = true,\n  disabled = false,\n  \"aria-label\": ariaLabel,\n}: PaginationProps) => {\n  const theme = useTheme();\n  const unicode = useUnicode();\n  const [internalPage, setInternalPage] = useState(defaultCurrent);\n  const activePage = current ?? internalPage;\n\n  const goTo = (page: number) => {\n    const clamped = Math.min(Math.max(1, page), total);\n    if (clamped === activePage) {\n      return;\n    }\n    const changeHandler = onValueChange ?? onChange;\n    if (changeHandler) {\n      changeHandler(clamped);\n    } else {\n      setInternalPage(clamped);\n    }\n  };\n\n  const { isFocused } = useInteraction(\n    (_input, key) => {\n      if (key.leftArrow) {\n        goTo(activePage - 1);\n      }\n      if (key.rightArrow) {\n        goTo(activePage + 1);\n      }\n      if (key.home) {\n        goTo(1);\n      }\n      if (key.end) {\n        goTo(total);\n      }\n    },\n    { autoFocus, disabled, id, isActive }\n  );\n\n  const pages = buildPages(total, activePage, siblings);\n\n  return (\n    <Box\n      aria-role=\"toolbar\"\n      aria-state={{ disabled }}\n      flexDirection=\"row\"\n      alignItems=\"center\"\n      gap={1}\n    >\n      <Text\n        aria-label={ariaLabel ?? `Pagination, page ${activePage} of ${total}`}\n      >\n        {isFocused ? \">\" : \" \"}\n      </Text>\n      <Text\n        aria-hidden\n        color={\n          activePage === 1 ? theme.colors.mutedForeground : theme.colors.primary\n        }\n        dimColor={activePage === 1}\n      >\n        {resolveTerminalSymbol(unicode, \"‹\", \"<\")}\n      </Text>\n\n      {showEdges && total > 7 ? null : null}\n\n      {pages.map((p, idx) => {\n        if (p === \"...\") {\n          return (\n            <Text\n              aria-hidden\n              key={`ellipsis-${idx}`}\n              color={theme.colors.mutedForeground}\n            >\n              {resolveTerminalSymbol(unicode, \"…\", \"...\")}\n            </Text>\n          );\n        }\n        const isActive = p === activePage;\n        return (\n          <Box\n            key={p}\n            aria-label={`Page ${p}`}\n            aria-role=\"button\"\n            aria-state={{ disabled, selected: isActive }}\n          >\n            <Text\n              aria-hidden\n              color={\n                isActive ? theme.colors.primary : theme.colors.mutedForeground\n              }\n              bold={isActive}\n            >\n              {isActive ? `[${p}]` : `${p}`}\n            </Text>\n          </Box>\n        );\n      })}\n\n      <Text\n        aria-hidden\n        color={\n          activePage === total\n            ? theme.colors.mutedForeground\n            : theme.colors.primary\n        }\n        dimColor={activePage === total}\n      >\n        {resolveTerminalSymbol(unicode, \"›\", \">\")}\n      </Text>\n    </Box>\n  );\n};\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "navigation"
  ],
  "type": "registry:ui"
}