{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table",
  "title": "Data Table",
  "description": "An admin data table with sortable/filterable columns, global search, status tabs, row selection, badge/avatar/actions cell types, pagination, and light/dark/custom theming.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/data-table/data-table.tsx",
      "content": "\"use client\";\n\nimport * as React from \"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 DataTableColumnType = \"text\" | \"number\" | \"currency\" | \"badge\" | \"avatar\" | \"actions\";\nexport type DataTableAlign = \"left\" | \"center\" | \"right\";\ntype SortDirection = \"asc\" | \"desc\" | null;\nexport type DataTableTheme = \"dark\" | \"light\" | \"custom\";\n\nexport interface DataTableColumn {\n  key: string;\n  label: string;\n  type: DataTableColumnType;\n  sortable?: boolean;\n  filterable?: boolean;\n  align?: DataTableAlign;\n  width?: number;\n}\n\nexport interface DataTableBadgeRule {\n  value: string;\n  background: string;\n  text: string;\n  dot?: boolean;\n}\n\nexport type DataTableActionIcon = \"eye\" | \"refresh\" | \"edit\" | \"trash\" | \"external\" | \"download\" | \"check\" | \"x\";\n\nexport interface DataTableActionButton {\n  icon: DataTableActionIcon;\n  label: string;\n}\n\nexport type DataTableRow = Record<string, string | number | boolean | null>;\n\nexport interface DataTableProps {\n  data?: DataTableRow[];\n  columns?: DataTableColumn[];\n  badgeColors?: DataTableBadgeRule[];\n  actionButtons?: DataTableActionButton[];\n\n  showTitle?: boolean;\n  title?: string;\n\n  showSearch?: boolean;\n  searchPlaceholder?: string;\n\n  showStatusTabs?: boolean;\n  statusTabsColumn?: string;\n\n  selectable?: boolean;\n\n  showPagination?: boolean;\n  rowsPerPage?: number;\n\n  fontSize?: number;\n  cellPaddingX?: number;\n  cellPaddingY?: number;\n  cornerRadius?: number;\n\n  theme?: DataTableTheme;\n\n  backgroundColor?: string;\n  borderColor?: string;\n  headerTextColor?: string;\n  textColor?: string;\n  mutedTextColor?: string;\n  hoverColor?: string;\n  accentColor?: string;\n  selectedRowColor?: string;\n\n  className?: string;\n}\n\nconst DEFAULT_DATA: DataTableRow[] = [\n  { id: 1, name: \"John Doe\", email: \"john@example.com\", role: \"Admin\", status: \"Active\" },\n  { id: 2, name: \"Jane Smith\", email: \"jane@example.com\", role: \"User\", status: \"Active\" },\n  { id: 3, name: \"Bob Johnson\", email: \"bob@example.com\", role: \"User\", status: \"Inactive\" },\n  { id: 4, name: \"Alice Brown\", email: \"alice@example.com\", role: \"Moderator\", status: \"Active\" },\n  { id: 5, name: \"Charlie Wilson\", email: \"charlie@example.com\", role: \"User\", status: \"Active\" },\n  { id: 6, name: \"Diana Prince\", email: \"diana@example.com\", role: \"Moderator\", status: \"Inactive\" },\n  { id: 7, name: \"Ethan Hunt\", email: \"ethan@example.com\", role: \"User\", status: \"Active\" },\n  { id: 8, name: \"Fiona Gallagher\", email: \"fiona@example.com\", role: \"Admin\", status: \"Inactive\" },\n];\n\nconst DEFAULT_COLUMNS: DataTableColumn[] = [\n  { key: \"id\", label: \"ID\", type: \"number\", sortable: true, filterable: false, align: \"left\", width: 60 },\n  { key: \"name\", label: \"Name\", type: \"avatar\", sortable: true, filterable: false, align: \"left\" },\n  { key: \"email\", label: \"Email\", type: \"text\", sortable: true, filterable: true, align: \"left\" },\n  { key: \"role\", label: \"Role\", type: \"badge\", sortable: true, filterable: true, align: \"left\", width: 130 },\n  { key: \"status\", label: \"Status\", type: \"badge\", sortable: true, filterable: true, align: \"left\", width: 110 },\n];\n\nconst DEFAULT_BADGE_COLORS: DataTableBadgeRule[] = [\n  { value: \"Active\", background: \"rgba(135,255,227,0.12)\", text: \"#87FFE3\", dot: true },\n  { value: \"Inactive\", background: \"rgba(255,255,255,0.08)\", text: \"rgba(255,255,255,0.6)\", dot: true },\n  { value: \"Paused\", background: \"rgba(242,168,65,0.12)\", text: \"#F2A841\", dot: true },\n  { value: \"Stopped\", background: \"rgba(255,122,107,0.12)\", text: \"#FF7A6B\", dot: true },\n  { value: \"Admin\", background: \"rgba(143,184,255,0.14)\", text: \"#8FB8FF\", dot: false },\n  { value: \"Moderator\", background: \"rgba(184,166,255,0.14)\", text: \"#B8A6FF\", dot: false },\n  { value: \"User\", background: \"rgba(255,255,255,0.08)\", text: \"rgba(255,255,255,0.6)\", dot: false },\n];\n\nconst LIGHT_BADGE_COLORS: DataTableBadgeRule[] = [\n  { value: \"Active\", background: \"rgba(14,159,128,0.12)\", text: \"#0E9F80\", dot: true },\n  { value: \"Inactive\", background: \"rgba(17,19,23,0.06)\", text: \"rgba(17,19,23,0.6)\", dot: true },\n  { value: \"Paused\", background: \"rgba(217,130,43,0.12)\", text: \"#D9822B\", dot: true },\n  { value: \"Stopped\", background: \"rgba(229,72,77,0.12)\", text: \"#E5484D\", dot: true },\n  { value: \"Admin\", background: \"rgba(59,111,216,0.12)\", text: \"#3B6FD8\", dot: false },\n  { value: \"Moderator\", background: \"rgba(124,92,224,0.12)\", text: \"#7C5CE0\", dot: false },\n  { value: \"User\", background: \"rgba(17,19,23,0.06)\", text: \"rgba(17,19,23,0.6)\", dot: false },\n];\n\nconst DEFAULT_ACTION_BUTTONS: DataTableActionButton[] = [\n  { icon: \"eye\", label: \"View\" },\n  { icon: \"refresh\", label: \"Restart\" },\n];\n\nconst AVATAR_COLORS = [\"#87FFE3\", \"#F2A841\", \"#FF7A6B\", \"#8FB8FF\", \"#B8A6FF\", \"#F5F4F1\", \"#F59EC5\", \"#C4F26B\"];\n\nconst DARK_PALETTE = {\n  backgroundColor: \"#0E0E0E\",\n  borderColor: \"rgba(255,255,255,0.08)\",\n  headerTextColor: \"rgba(255,255,255,0.6)\",\n  textColor: \"#f4f5f7\",\n  mutedTextColor: \"rgba(255,255,255,0.45)\",\n  hoverColor: \"rgba(255,255,255,0.035)\",\n  accentColor: \"#87FFE3\",\n  selectedRowColor: \"rgba(135,255,227,0.07)\",\n};\n\nconst LIGHT_PALETTE = {\n  backgroundColor: \"#ffffff\",\n  borderColor: \"rgba(0,0,0,0.06)\",\n  headerTextColor: \"rgba(17,19,23,0.55)\",\n  textColor: \"#111317\",\n  mutedTextColor: \"rgba(17,19,23,0.45)\",\n  hoverColor: \"rgba(0,0,0,0.035)\",\n  accentColor: \"#0E9F80\",\n  selectedRowColor: \"rgba(14,159,128,0.07)\",\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 getInitials(value: string): string {\n  const parts = value.trim().split(/\\s+/).filter(Boolean);\n  if (parts.length === 0) return \"?\";\n  if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();\n  return (parts[0][0] + parts[1][0]).toUpperCase();\n}\n\nfunction hashString(value: string): number {\n  let hash = 0;\n  for (let i = 0; i < value.length; i++) {\n    hash = (hash << 5) - hash + value.charCodeAt(i);\n    hash |= 0;\n  }\n  return Math.abs(hash);\n}\n\nfunction formatCellValue(value: unknown, type: DataTableColumnType): string {\n  if (value === null || value === undefined || value === \"\") return \"-\";\n  if (type === \"currency\") {\n    const num = typeof value === \"number\" ? value : parseFloat(String(value));\n    if (isNaN(num)) return String(value);\n    return `$${num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;\n  }\n  return String(value);\n}\n\nfunction compareValues(a: unknown, b: unknown, type: DataTableColumnType): number {\n  if (type === \"number\" || type === \"currency\") {\n    const an = typeof a === \"number\" ? a : parseFloat(String(a));\n    const bn = typeof b === \"number\" ? b : parseFloat(String(b));\n    const av = isNaN(an) ? -Infinity : an;\n    const bv = isNaN(bn) ? -Infinity : bn;\n    return av - bv;\n  }\n  return String(a ?? \"\").toLowerCase().localeCompare(String(b ?? \"\").toLowerCase());\n}\n\nfunction SearchIcon({ size = 14, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <circle cx=\"7\" cy=\"7\" r=\"5.25\" stroke={color} strokeWidth=\"1.5\" />\n      <line x1=\"11.1\" y1=\"11.1\" x2=\"14\" y2=\"14\" stroke={color} strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\nfunction ChevronUpIcon({ size = 12, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M4 10L8 6L12 10\" stroke={color} strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction ChevronDownIcon({ size = 12, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M4 6L8 10L12 6\" stroke={color} strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction ChevronsUpDownIcon({ size = 12, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M4.5 6.5L8 3.5L11.5 6.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n      <path d=\"M4.5 9.5L8 12.5L11.5 9.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction ChevronLeftIcon({ size = 14, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M10 3L5 8L10 13\" stroke={color} strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction ChevronRightIcon({ size = 14, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M6 3L11 8L6 13\" stroke={color} strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction FilterIcon({ size = 12, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M2.5 3.5H13.5L9.5 8.2V12.5L6.5 11V8.2L2.5 3.5Z\" stroke={color} strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction CheckIcon({ size = 10, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M2.5 8.5L6 12L13.5 3.5\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction MinusIcon({ size = 10, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M3 8H13\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\nfunction XIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M3.5 3.5L12.5 12.5M12.5 3.5L3.5 12.5\" stroke={color} strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\nfunction EyeIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M1 8C1 8 3.5 3 8 3C12.5 3 15 8 15 8C15 8 12.5 13 8 13C3.5 13 1 8 1 8Z\" stroke={color} strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n      <circle cx=\"8\" cy=\"8\" r=\"2.25\" stroke={color} strokeWidth=\"1.4\" />\n    </svg>\n  );\n}\nfunction RefreshIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M13.5 8A5.5 5.5 0 1 1 11.8 4.2\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" />\n      <path d=\"M13.5 2.5V5.5H10.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction EditIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M11 2L14 5L5.5 13.5L2 14L2.5 10.5L11 2Z\" stroke={color} strokeWidth=\"1.3\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction TrashIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M2.5 4H13.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" />\n      <path d=\"M5.5 4V2.5H10.5V4\" stroke={color} strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n      <path d=\"M4 4L4.5 13.5H11.5L12 4\" stroke={color} strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction ExternalIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M6.5 2.5H13.5V9.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n      <path d=\"M13.5 2.5L7 9\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" />\n      <path d=\"M11 8.5V13.5H2.5V5H7.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\nfunction DownloadIcon({ size = 13, color = \"currentColor\" }: { size?: number; color?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\">\n      <path d=\"M8 2V10\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" />\n      <path d=\"M4.5 7L8 10.5L11.5 7\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n      <path d=\"M2.5 13.5H13.5\" stroke={color} strokeWidth=\"1.4\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction renderActionIcon(icon: DataTableActionIcon, size: number, color: string) {\n  switch (icon) {\n    case \"eye\":\n      return <EyeIcon size={size} color={color} />;\n    case \"refresh\":\n      return <RefreshIcon size={size} color={color} />;\n    case \"edit\":\n      return <EditIcon size={size} color={color} />;\n    case \"trash\":\n      return <TrashIcon size={size} color={color} />;\n    case \"external\":\n      return <ExternalIcon size={size} color={color} />;\n    case \"download\":\n      return <DownloadIcon size={size} color={color} />;\n    case \"check\":\n      return <CheckIcon size={size} color={color} />;\n    case \"x\":\n      return <XIcon size={size} color={color} />;\n  }\n}\n\nfunction TableCheckbox({\n  checked,\n  indeterminate,\n  onChange,\n  accentColor,\n  borderColor,\n}: {\n  checked: boolean;\n  indeterminate?: boolean;\n  onChange: () => void;\n  accentColor: string;\n  borderColor: string;\n}) {\n  const active = checked || !!indeterminate;\n  return (\n    <div\n      onClick={(e) => {\n        e.stopPropagation();\n        onChange();\n      }}\n      className=\"box-border flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded\"\n      style={{ border: `1.5px solid ${active ? accentColor : borderColor}`, background: active ? accentColor : \"transparent\", transition: \"background 0.15s ease, border-color 0.15s ease\" }}\n    >\n      {checked && <CheckIcon size={10} color={readableTextOn(accentColor)} />}\n      {!checked && indeterminate && <MinusIcon size={10} color={readableTextOn(accentColor)} />}\n    </div>\n  );\n}\n\nfunction FilterPopover({\n  options,\n  selected,\n  onToggle,\n  onClear,\n  backgroundColor,\n  borderColor,\n  textColor,\n  mutedTextColor,\n  hoverColor,\n  accentColor,\n}: {\n  options: { value: string; count: number }[];\n  selected: Set<string>;\n  onToggle: (value: string) => void;\n  onClear: () => void;\n  backgroundColor: string;\n  borderColor: string;\n  textColor: string;\n  mutedTextColor: string;\n  hoverColor: string;\n  accentColor: string;\n}) {\n  return (\n    <div\n      onClick={(e) => e.stopPropagation()}\n      className=\"absolute top-[calc(100%_+_6px)] left-0 z-50 min-w-[190px] max-h-60 overflow-y-auto rounded-lg p-1.5 font-normal normal-case\"\n      style={{ background: backgroundColor, border: `1px solid ${borderColor}`, boxShadow: \"0 10px 30px rgba(0,0,0,0.3)\" }}\n    >\n      {options.length === 0 && <div className=\"p-2 text-xs\" style={{ color: mutedTextColor }}>No values</div>}\n      {options.map((opt) => {\n        const isSelected = selected.has(opt.value);\n        return (\n          <div\n            key={opt.value}\n            onClick={() => onToggle(opt.value)}\n            className=\"flex items-center gap-2 rounded-md px-2 py-1.5 text-[12.5px] cursor-pointer\"\n            style={{ color: textColor }}\n            onMouseEnter={(e) => (e.currentTarget.style.background = hoverColor)}\n            onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n          >\n            <TableCheckbox checked={isSelected} onChange={() => onToggle(opt.value)} accentColor={accentColor} borderColor={borderColor} />\n            <span className=\"flex-1 truncate whitespace-nowrap\">{opt.value || \"(empty)\"}</span>\n            <span className=\"text-[11px]\" style={{ color: mutedTextColor }}>\n              {opt.count}\n            </span>\n          </div>\n        );\n      })}\n      {selected.size > 0 && (\n        <div onClick={onClear} className=\"mt-1 px-2 py-1.5 text-center text-xs cursor-pointer\" style={{ borderTop: `1px solid ${borderColor}`, color: accentColor }}>\n          Clear filter\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport function DataTable({\n  data = DEFAULT_DATA,\n  columns = DEFAULT_COLUMNS,\n  badgeColors,\n  actionButtons = DEFAULT_ACTION_BUTTONS,\n\n  showTitle = true,\n  title = \"Users\",\n\n  showSearch = true,\n  searchPlaceholder = \"Search...\",\n\n  showStatusTabs = true,\n  statusTabsColumn = \"status\",\n\n  selectable = true,\n\n  showPagination = true,\n  rowsPerPage = 5,\n\n  fontSize = 13,\n  cellPaddingX = 16,\n  cellPaddingY = 12,\n  cornerRadius = 20,\n\n  theme = \"dark\",\n\n  backgroundColor: backgroundColorProp = \"#0E0E0E\",\n  borderColor: borderColorProp = \"rgba(255,255,255,0.08)\",\n  headerTextColor: headerTextColorProp = \"rgba(255,255,255,0.6)\",\n  textColor: textColorProp = \"#f4f5f7\",\n  mutedTextColor: mutedTextColorProp = \"rgba(255,255,255,0.45)\",\n  hoverColor: hoverColorProp = \"rgba(255,255,255,0.035)\",\n  accentColor: accentColorProp = \"#87FFE3\",\n  selectedRowColor: selectedRowColorProp = \"rgba(135,255,227,0.07)\",\n  className,\n}: DataTableProps) {\n  const palette =\n    theme === \"light\"\n      ? LIGHT_PALETTE\n      : theme === \"dark\"\n        ? DARK_PALETTE\n        : {\n            backgroundColor: backgroundColorProp,\n            borderColor: borderColorProp,\n            headerTextColor: headerTextColorProp,\n            textColor: textColorProp,\n            mutedTextColor: mutedTextColorProp,\n            hoverColor: hoverColorProp,\n            accentColor: accentColorProp,\n            selectedRowColor: selectedRowColorProp,\n          };\n\n  const { backgroundColor, borderColor, headerTextColor, textColor, mutedTextColor, hoverColor, accentColor, selectedRowColor } = palette;\n\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const [containerWidth, setContainerWidth] = React.useState(800);\n\n  const [searchQuery, setSearchQuery] = React.useState(\"\");\n  const [sortKey, setSortKey] = React.useState<string | null>(null);\n  const [sortDirection, setSortDirection] = React.useState<SortDirection>(null);\n  const [columnFilters, setColumnFilters] = React.useState<Record<string, Set<string>>>({});\n  const [openFilter, setOpenFilter] = React.useState<string | null>(null);\n  const [statusTab, setStatusTab] = React.useState<string>(\"All\");\n  const [page, setPage] = React.useState(1);\n  const [selectedRows, setSelectedRows] = React.useState<Set<number>>(new Set());\n  const [hoveredRow, setHoveredRow] = React.useState<number | null>(null);\n\n  React.useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => setContainerWidth(entry.contentRect.width));\n    ro.observe(el);\n    setContainerWidth(el.getBoundingClientRect().width);\n    return () => ro.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    if (!openFilter) return;\n    const handler = () => setOpenFilter(null);\n    window.addEventListener(\"click\", handler);\n    return () => window.removeEventListener(\"click\", handler);\n  }, [openFilter]);\n\n  React.useEffect(() => {\n    const id = setTimeout(() => setPage(1), 0);\n    return () => clearTimeout(id);\n  }, [searchQuery, columnFilters, statusTab]);\n\n  const rows = React.useMemo<(DataTableRow & { __id: number })[]>(() => data.map((row, i) => ({ ...row, __id: i })), [data]);\n\n  const badgeMap = React.useMemo(() => {\n    const map = new Map<string, DataTableBadgeRule>();\n    (badgeColors ?? (theme === \"light\" ? LIGHT_BADGE_COLORS : DEFAULT_BADGE_COLORS)).forEach((b) => map.set(b.value.toLowerCase(), b));\n    return map;\n  }, [badgeColors, theme]);\n\n  const statusTabOptions = React.useMemo(() => {\n    if (!showStatusTabs) return [];\n    const set = new Set<string>();\n    rows.forEach((r) => {\n      const v = r[statusTabsColumn];\n      if (v !== undefined && v !== null && v !== \"\") set.add(String(v));\n    });\n    return Array.from(set);\n  }, [rows, showStatusTabs, statusTabsColumn]);\n\n  const filteredRows = React.useMemo(() => {\n    let result: (DataTableRow & { __id: number })[] = rows;\n\n    if (showStatusTabs && statusTab !== \"All\") {\n      result = result.filter((r) => String(r[statusTabsColumn]) === statusTab);\n    }\n\n    Object.entries(columnFilters).forEach(([key, values]) => {\n      if (values.size === 0) return;\n      result = result.filter((r) => values.has(String(r[key] ?? \"\")));\n    });\n\n    if (showSearch && searchQuery.trim()) {\n      const q = searchQuery.trim().toLowerCase();\n      result = result.filter((r) => columns.some((c) => String(r[c.key] ?? \"\").toLowerCase().includes(q)));\n    }\n\n    return result;\n  }, [rows, showStatusTabs, statusTab, statusTabsColumn, columnFilters, showSearch, searchQuery, columns]);\n\n  const sortedRows = React.useMemo(() => {\n    if (!sortKey || !sortDirection) return filteredRows;\n    const col = columns.find((c) => c.key === sortKey);\n    const type = col?.type ?? \"text\";\n    const sorted = [...filteredRows].sort((a, b) => compareValues(a[sortKey], b[sortKey], type));\n    return sortDirection === \"asc\" ? sorted : sorted.reverse();\n  }, [filteredRows, sortKey, sortDirection, columns]);\n\n  const totalRows = sortedRows.length;\n  const perPage = showPagination ? Math.max(1, rowsPerPage) : Math.max(1, totalRows || 1);\n  const totalPages = Math.max(1, Math.ceil(totalRows / perPage));\n  const currentPage = Math.min(page, totalPages);\n  const pageStart = (currentPage - 1) * perPage;\n  const pageRows = showPagination ? sortedRows.slice(pageStart, pageStart + perPage) : sortedRows;\n\n  const pageIds = pageRows.map((r) => r.__id);\n  const allSelected = pageIds.length > 0 && pageIds.every((id) => selectedRows.has(id));\n  const someSelected = !allSelected && pageIds.some((id) => selectedRows.has(id));\n\n  const toggleSelectAll = () => {\n    setSelectedRows((prev) => {\n      const next = new Set(prev);\n      if (allSelected) pageIds.forEach((id) => next.delete(id));\n      else pageIds.forEach((id) => next.add(id));\n      return next;\n    });\n  };\n\n  const toggleSelectRow = (id: number) => {\n    setSelectedRows((prev) => {\n      const next = new Set(prev);\n      if (next.has(id)) next.delete(id);\n      else next.add(id);\n      return next;\n    });\n  };\n\n  const handleSort = (key: string) => {\n    if (sortKey !== key) {\n      setSortKey(key);\n      setSortDirection(\"asc\");\n    } else if (sortDirection === \"asc\") {\n      setSortDirection(\"desc\");\n    } else if (sortDirection === \"desc\") {\n      setSortKey(null);\n      setSortDirection(null);\n    } else {\n      setSortDirection(\"asc\");\n    }\n  };\n\n  const toggleFilterValue = (key: string, value: string) => {\n    setColumnFilters((prev) => {\n      const next = { ...prev };\n      const set = new Set(next[key] ?? []);\n      if (set.has(value)) set.delete(value);\n      else set.add(value);\n      next[key] = set;\n      return next;\n    });\n  };\n\n  const clearColumnFilter = (key: string) => {\n    setColumnFilters((prev) => {\n      const next = { ...prev };\n      delete next[key];\n      return next;\n    });\n  };\n\n  const getColumnOptions = (key: string) => {\n    const counts = new Map<string, number>();\n    rows.forEach((r) => {\n      const v = String(r[key] ?? \"\");\n      counts.set(v, (counts.get(v) ?? 0) + 1);\n    });\n    return Array.from(counts.entries())\n      .map(([value, count]) => ({ value, count }))\n      .sort((a, b) => a.value.localeCompare(b.value));\n  };\n\n  const compact = containerWidth > 0 && containerWidth < 600;\n  const stackFooter = containerWidth > 0 && containerWidth < 480;\n\n  const thStyle: React.CSSProperties = {\n    padding: `${cellPaddingY}px ${cellPaddingX}px`,\n    textAlign: \"left\",\n    fontSize: Math.max(10, fontSize - 1.5),\n    fontWeight: 600,\n    color: headerTextColor,\n    whiteSpace: \"nowrap\",\n    borderBottom: `1px solid ${borderColor}`,\n    position: \"relative\",\n    textTransform: \"uppercase\",\n    letterSpacing: 0.4,\n  };\n\n  const tdStyle: React.CSSProperties = { padding: `${cellPaddingY}px ${cellPaddingX}px`, color: textColor, whiteSpace: \"nowrap\" };\n\n  function renderCell(row: DataTableRow, col: DataTableColumn) {\n    const value = row[col.key];\n\n    switch (col.type) {\n      case \"badge\": {\n        const str = String(value ?? \"\");\n        const rule = badgeMap.get(str.toLowerCase());\n        const bg = rule?.background ?? \"rgba(161,161,170,0.16)\";\n        const fg = rule?.text ?? mutedTextColor;\n        return (\n          <span className=\"inline-flex items-center gap-1.5 rounded-md px-2.5 py-[3px] text-[0.92em] font-semibold whitespace-nowrap\" style={{ background: bg, color: fg }}>\n            {rule?.dot && <span className=\"h-1.5 w-1.5 shrink-0 rounded-full\" style={{ background: fg }} />}\n            {str || \"-\"}\n          </span>\n        );\n      }\n\n      case \"avatar\": {\n        const str = String(value ?? \"\");\n        const idx = hashString(str) % AVATAR_COLORS.length;\n        return (\n          <div className=\"flex items-center gap-2.5\">\n            <div className=\"flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-[11px] font-bold\" style={{ background: AVATAR_COLORS[idx], color: \"#0A0A0A\" }}>\n              {getInitials(str)}\n            </div>\n            <span>{str || \"-\"}</span>\n          </div>\n        );\n      }\n\n      case \"actions\": {\n        return (\n          <div className=\"flex items-center gap-4\">\n            {actionButtons.map((action, i) => (\n              <span\n                key={i}\n                className=\"inline-flex cursor-pointer items-center gap-1.5 text-[0.92em] font-medium\"\n                style={{ color: mutedTextColor }}\n                onMouseEnter={(e) => (e.currentTarget.style.color = textColor)}\n                onMouseLeave={(e) => (e.currentTarget.style.color = mutedTextColor)}\n              >\n                {renderActionIcon(action.icon, 13, \"currentColor\")}\n                {action.label}\n              </span>\n            ))}\n          </div>\n        );\n      }\n\n      case \"number\":\n      case \"currency\":\n        return <span>{formatCellValue(value, col.type)}</span>;\n\n      default:\n        return <span>{value === null || value === undefined || value === \"\" ? \"-\" : String(value)}</span>;\n    }\n  }\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\"box-border flex w-full h-full flex-col overflow-hidden\", className)}\n      style={{ background: backgroundColor, border: `1px solid ${borderColor}`, borderRadius: cornerRadius, fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\", color: textColor }}\n    >\n      {(showTitle || showSearch || (showStatusTabs && statusTabOptions.length > 0)) && (\n        <div\n          className={cn(\"flex items-center justify-between gap-3\", compact && \"flex-col items-start\")}\n          style={{ padding: `16px ${cellPaddingX}px`, borderBottom: `1px solid ${borderColor}` }}\n        >\n          {showTitle && (\n            <div className=\"font-semibold\" style={{ fontSize: fontSize + 3 }}>\n              {title}\n            </div>\n          )}\n\n          <div className={cn(\"flex items-center gap-2.5\", compact && \"w-full flex-col items-stretch\")}>\n            {showSearch && (\n              <div className=\"relative flex items-center\">\n                <span className=\"pointer-events-none absolute left-2.5 flex\" style={{ color: mutedTextColor }}>\n                  <SearchIcon size={14} color={mutedTextColor} />\n                </span>\n                <input\n                  value={searchQuery}\n                  onChange={(e) => setSearchQuery(e.target.value)}\n                  placeholder={searchPlaceholder}\n                  className={cn(\"box-border rounded-lg bg-transparent px-8 py-2 font-[inherit] outline-none\", compact ? \"w-full\" : \"w-[230px]\")}\n                  style={{ border: `1px solid ${borderColor}`, fontSize: Math.max(11, fontSize - 1), color: textColor }}\n                />\n                {searchQuery && (\n                  <span onClick={() => setSearchQuery(\"\")} className=\"absolute right-2.5 flex cursor-pointer\" style={{ color: mutedTextColor }}>\n                    <XIcon size={12} color={mutedTextColor} />\n                  </span>\n                )}\n              </div>\n            )}\n\n            {showStatusTabs && statusTabOptions.length > 0 && (\n              <div className=\"flex flex-wrap gap-1.5\">\n                {[\"All\", ...statusTabOptions].map((opt) => {\n                  const active = statusTab === opt;\n                  return (\n                    <div\n                      key={opt}\n                      onClick={() => setStatusTab(opt)}\n                      className=\"cursor-pointer rounded-md px-3 py-1.5 font-semibold whitespace-nowrap transition-all duration-150\"\n                      style={{\n                        fontSize: Math.max(11, fontSize - 1),\n                        background: active ? accentColor : \"transparent\",\n                        color: active ? readableTextOn(accentColor) : mutedTextColor,\n                        border: `1px solid ${active ? accentColor : borderColor}`,\n                        // Explicit \"ease\" (not Tailwind's transition-all default\n                        // of cubic-bezier(0.4,0,0.2,1)) to match the source exactly.\n                        transitionTimingFunction: \"ease\",\n                      }}\n                    >\n                      {opt}\n                    </div>\n                  );\n                })}\n              </div>\n            )}\n          </div>\n        </div>\n      )}\n\n      <div className=\"flex-1 overflow-auto\">\n        <table className=\"w-full min-w-[480px] border-collapse\" style={{ fontSize }}>\n          <thead>\n            <tr>\n              {selectable && (\n                <th style={{ ...thStyle, width: 44 }}>\n                  <TableCheckbox checked={allSelected} indeterminate={someSelected} onChange={toggleSelectAll} accentColor={accentColor} borderColor={borderColor} />\n                </th>\n              )}\n              {columns.map((col) => {\n                const align = col.align ?? \"left\";\n                const filterCount = columnFilters[col.key]?.size ?? 0;\n                return (\n                  <th key={col.key} style={{ ...thStyle, textAlign: align, width: col.width || undefined, zIndex: openFilter === col.key ? 51 : undefined }}>\n                    <div className=\"inline-flex items-center gap-1.5 select-none\" style={{ cursor: col.sortable ? \"pointer\" : \"default\" }} onClick={() => col.sortable && handleSort(col.key)}>\n                      <span>{col.label}</span>\n                      {col.sortable &&\n                        (sortKey === col.key ? (\n                          sortDirection === \"asc\" ? (\n                            <ChevronUpIcon size={12} color={accentColor} />\n                          ) : (\n                            <ChevronDownIcon size={12} color={accentColor} />\n                          )\n                        ) : (\n                          <ChevronsUpDownIcon size={12} color={mutedTextColor} />\n                        ))}\n                      {col.filterable && (\n                        <span\n                          onClick={(e) => {\n                            e.stopPropagation();\n                            setOpenFilter(openFilter === col.key ? null : col.key);\n                          }}\n                          className=\"flex rounded p-[3px]\"\n                          style={{ background: filterCount > 0 ? `${accentColor}29` : \"transparent\" }}\n                        >\n                          <FilterIcon size={12} color={filterCount > 0 ? accentColor : mutedTextColor} />\n                        </span>\n                      )}\n                    </div>\n                    {openFilter === col.key && (\n                      <FilterPopover\n                        options={getColumnOptions(col.key)}\n                        selected={columnFilters[col.key] ?? new Set()}\n                        onToggle={(v) => toggleFilterValue(col.key, v)}\n                        onClear={() => clearColumnFilter(col.key)}\n                        backgroundColor={backgroundColor}\n                        borderColor={borderColor}\n                        textColor={textColor}\n                        mutedTextColor={mutedTextColor}\n                        hoverColor={hoverColor}\n                        accentColor={accentColor}\n                      />\n                    )}\n                  </th>\n                );\n              })}\n            </tr>\n          </thead>\n          <tbody>\n            {pageRows.length === 0 ? (\n              <tr>\n                <td colSpan={columns.length + (selectable ? 1 : 0)} className=\"text-center\" style={{ padding: 36, color: mutedTextColor, fontSize }}>\n                  No results found.\n                </td>\n              </tr>\n            ) : (\n              pageRows.map((row) => {\n                const id = row.__id;\n                const isSelected = selectedRows.has(id);\n                const isHovered = hoveredRow === id;\n                return (\n                  <tr\n                    key={id}\n                    onMouseEnter={() => setHoveredRow(id)}\n                    onMouseLeave={() => setHoveredRow(null)}\n                    style={{ background: isSelected ? selectedRowColor : isHovered ? hoverColor : \"transparent\", borderTop: `1px solid ${borderColor}`, transition: \"background 0.1s ease\" }}\n                  >\n                    {selectable && (\n                      <td style={tdStyle}>\n                        <TableCheckbox checked={isSelected} onChange={() => toggleSelectRow(id)} accentColor={accentColor} borderColor={borderColor} />\n                      </td>\n                    )}\n                    {columns.map((col) => (\n                      <td key={col.key} style={{ ...tdStyle, textAlign: col.align ?? \"left\" }}>\n                        {renderCell(row, col)}\n                      </td>\n                    ))}\n                  </tr>\n                );\n              })\n            )}\n          </tbody>\n        </table>\n      </div>\n\n      {showPagination && (\n        <div\n          className={cn(\"flex items-center justify-between gap-2.5\", stackFooter && \"flex-col items-start\")}\n          style={{ padding: `12px ${cellPaddingX}px`, borderTop: `1px solid ${borderColor}`, fontSize: Math.max(11, fontSize - 1), color: mutedTextColor }}\n        >\n          <div>\n            {totalRows === 0 ? \"Showing 0 results\" : `Showing ${pageStart + 1} to ${Math.min(pageStart + perPage, totalRows)} of ${totalRows} results`}\n            {selectable && selectedRows.size > 0 && (\n              <span className=\"ml-3 font-semibold\" style={{ color: textColor }}>\n                {selectedRows.size} row{selectedRows.size === 1 ? \"\" : \"s\"} selected\n              </span>\n            )}\n          </div>\n          <div className=\"flex items-center gap-4\">\n            <span onClick={() => currentPage > 1 && setPage(currentPage - 1)} className=\"flex\" style={{ cursor: currentPage <= 1 ? \"default\" : \"pointer\", opacity: currentPage <= 1 ? 0.35 : 1 }}>\n              <ChevronLeftIcon size={16} color={textColor} />\n            </span>\n            <span className=\"font-semibold\" style={{ color: textColor }}>\n              {currentPage} / {totalPages}\n            </span>\n            <span onClick={() => currentPage < totalPages && setPage(currentPage + 1)} className=\"flex\" style={{ cursor: currentPage >= totalPages ? \"default\" : \"pointer\", opacity: currentPage >= totalPages ? 0.35 : 1 }}>\n              <ChevronRightIcon size={16} color={textColor} />\n            </span>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}