{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pagination",
  "title": "Pagination",
  "description": "An accessible pagination control with smart ellipsis ranges, a sliding animated active page, solid, soft and compact variants, previous/next buttons and optional labels.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/pagination/pagination.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type PaginationVariant = \"solid\" | \"soft\" | \"compact\";\nexport type PaginationSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface PaginationProps {\n  totalPages?: number;\n  page?: number;\n  defaultPage?: number;\n  onPageChange?: (page: number) => void;\n  siblingCount?: number;\n  boundaryCount?: number;\n  variant?: PaginationVariant;\n  size?: PaginationSize;\n  theme?: \"dark\" | \"light\";\n  accentColor?: string;\n  showLabels?: boolean;\n  disabled?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", border: \"rgba(255,255,255,0.1)\", hover: \"rgba(255,255,255,0.07)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", border: \"rgba(10,10,10,0.1)\", hover: \"rgba(10,10,10,0.06)\" },\n};\n\nconst SIZES: Record<PaginationSize, { box: number; font: number; gap: number; icon: number }> = {\n  sm: { box: 30, font: 12.5, gap: 4, icon: 14 },\n  md: { box: 38, font: 14, gap: 6, icon: 16 },\n  lg: { box: 46, font: 15.5, gap: 8, icon: 18 },\n};\n\nfunction readableTextOn(hex: string): string {\n  const h = hex.replace(\"#\", \"\");\n  const full = h.length === 3 ? h.split(\"\").map((c) => c + c).join(\"\") : h;\n  const r = parseInt(full.slice(0, 2), 16);\n  const g = parseInt(full.slice(2, 4), 16);\n  const b = parseInt(full.slice(4, 6), 16);\n  return 0.299 * r + 0.587 * g + 0.114 * b > 150 ? \"#0A0A0A\" : \"#FFFFFF\";\n}\n\nfunction range(start: number, end: number) {\n  return Array.from({ length: Math.max(0, end - start + 1) }, (_, i) => start + i);\n}\n\nfunction getItems(page: number, total: number, sibling: number, boundary: number): (number | \"start-ellipsis\" | \"end-ellipsis\")[] {\n  const startPages = range(1, Math.min(boundary, total));\n  const endPages = range(Math.max(total - boundary + 1, boundary + 1), total);\n  const siblingsStart = Math.max(Math.min(page - sibling, total - boundary - sibling * 2 - 1), boundary + 2);\n  const siblingsEnd = Math.min(Math.max(page + sibling, boundary + sibling * 2 + 2), endPages.length > 0 ? endPages[0] - 2 : total - 1);\n  const out: (number | \"start-ellipsis\" | \"end-ellipsis\")[] = [...startPages];\n  if (siblingsStart > boundary + 2) out.push(\"start-ellipsis\");\n  else if (boundary + 1 < total - boundary) out.push(boundary + 1);\n  out.push(...range(siblingsStart, siblingsEnd));\n  if (siblingsEnd < total - boundary - 1) out.push(\"end-ellipsis\");\n  else if (total - boundary > boundary) out.push(total - boundary);\n  out.push(...endPages);\n  return out;\n}\n\nfunction Arrow({ dir, size }: { dir: \"left\" | \"right\"; size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={dir === \"left\" ? \"M10 3.5L5.5 8L10 12.5\" : \"M6 3.5L10.5 8L6 12.5\"} />\n    </svg>\n  );\n}\n\nexport function Pagination({\n  totalPages = 12,\n  page,\n  defaultPage = 1,\n  onPageChange,\n  siblingCount = 1,\n  boundaryCount = 1,\n  variant = \"solid\",\n  size = \"md\",\n  theme = \"dark\",\n  accentColor = \"#F2A841\",\n  showLabels = false,\n  disabled = false,\n  className,\n}: PaginationProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const total = Math.max(1, totalPages);\n  const [internal, setInternal] = React.useState(defaultPage);\n  const isControlled = page !== undefined;\n  const current = Math.min(total, Math.max(1, isControlled ? page : internal));\n\n  const go = (next: number) => {\n    const n = Math.min(total, Math.max(1, next));\n    if (disabled || n === current) return;\n    if (!isControlled) setInternal(n);\n    onPageChange?.(n);\n  };\n\n  const items = getItems(current, total, siblingCount, boundaryCount);\n  const activeBg = variant === \"soft\" ? `color-mix(in srgb, ${accentColor} 16%, transparent)` : accentColor;\n  const activeText = variant === \"soft\" ? accentColor : readableTextOn(accentColor);\n  const activeBorder = variant === \"soft\" ? `1px solid color-mix(in srgb, ${accentColor} 30%, transparent)` : \"1px solid transparent\";\n\n  const navBtn = (dir: \"left\" | \"right\") => {\n    const isPrev = dir === \"left\";\n    const off = disabled || (isPrev ? current <= 1 : current >= total);\n    return (\n      <button\n        type=\"button\"\n        aria-label={isPrev ? \"Previous page\" : \"Next page\"}\n        disabled={off}\n        onClick={() => go(current + (isPrev ? -1 : 1))}\n        className=\"flex shrink-0 items-center justify-center border-none outline-none focus-visible:ring-2\"\n        style={{\n          height: s.box,\n          minWidth: s.box,\n          gap: 6,\n          padding: showLabels ? `0 ${s.box * 0.35}px` : 0,\n          borderRadius: 10,\n          background: \"transparent\",\n          border: `1px solid ${p.border}`,\n          color: off ? p.muted : p.text,\n          opacity: off ? 0.45 : 1,\n          fontSize: s.font,\n          fontWeight: 600,\n          cursor: off ? \"default\" : \"pointer\",\n          transition: \"background 0.15s ease, opacity 0.15s ease\",\n          [\"--tw-ring-color\" as string]: accentColor,\n        }}\n        onMouseEnter={(e) => !off && (e.currentTarget.style.background = p.hover)}\n        onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n      >\n        {isPrev && <Arrow dir=\"left\" size={s.icon} />}\n        {showLabels && <span>{isPrev ? \"Previous\" : \"Next\"}</span>}\n        {!isPrev && <Arrow dir=\"right\" size={s.icon} />}\n      </button>\n    );\n  };\n\n  return (\n    <nav aria-label=\"Pagination\" className={cn(\"inline-block max-w-full\", className)} style={{ fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.6 : 1 }}>\n      <div className=\"flex flex-wrap items-center\" style={{ gap: s.gap }}>\n        {navBtn(\"left\")}\n\n        {variant === \"compact\" ? (\n          <span className=\"flex items-center justify-center font-semibold tabular-nums\" style={{ minWidth: s.box * 2.6, padding: \"0 10px\", fontSize: s.font, color: p.text }} aria-live=\"polite\">\n            Page {current} <span style={{ color: p.muted, fontWeight: 500, margin: \"0 6px\" }}>of</span> {total}\n          </span>\n        ) : (\n          items.map((it) => {\n            if (typeof it === \"string\") {\n              return (\n                <span key={it} aria-hidden=\"true\" className=\"flex items-center justify-center font-semibold\" style={{ width: s.box, height: s.box, color: p.muted, fontSize: s.font }}>\n                  …\n                </span>\n              );\n            }\n            const active = it === current;\n            return (\n              <button\n                key={it}\n                type=\"button\"\n                aria-label={`Page ${it}`}\n                aria-current={active ? \"page\" : undefined}\n                disabled={disabled}\n                onClick={() => go(it)}\n                className=\"relative flex shrink-0 items-center justify-center border-none bg-transparent font-semibold tabular-nums outline-none focus-visible:ring-2\"\n                style={{\n                  width: s.box,\n                  height: s.box,\n                  borderRadius: 10,\n                  fontSize: s.font,\n                  color: active ? activeText : p.muted,\n                  cursor: disabled ? \"default\" : active ? \"default\" : \"pointer\",\n                  transition: \"color 0.2s ease, background 0.15s ease\",\n                  [\"--tw-ring-color\" as string]: accentColor,\n                }}\n                onMouseEnter={(e) => !active && !disabled && ((e.currentTarget.style.background = p.hover), (e.currentTarget.style.color = p.text))}\n                onMouseLeave={(e) => {\n                  e.currentTarget.style.background = \"transparent\";\n                  e.currentTarget.style.color = active ? activeText : p.muted;\n                }}\n              >\n                {active && <motion.span layoutId={`${uid}-active`} className=\"absolute inset-0\" style={{ borderRadius: 10, background: activeBg, border: activeBorder }} transition={{ type: \"spring\", stiffness: 520, damping: 38 }} />}\n                <span className=\"relative\">{it}</span>\n              </button>\n            );\n          })\n        )}\n\n        {navBtn(\"right\")}\n      </div>\n    </nav>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}