{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox",
  "title": "Combobox",
  "description": "Autocomplete combobox (ARIA 1.2) with outline, filled, ghost, underline, pill and neo fields, tones, sizes and shadows; local ranked matching or debounced async search with abort, cache, loading, empty and error-with-retry states, every matched word highlighted, groups, avatars, single or multi-select chips, an “Add …” create row and automatic virtualization for 10,000+ rows, in a portaled list that flips above the field.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/core/combobox.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\n/*\n * Autocomplete combobox (ARIA 1.2 combobox + listbox): the user types, the list narrows. Independent layers:\n *   variant    outline, filled, ghost, underline, pill, neo      tone      accent for focus, active row and chips\n *   size       sm, md, lg                                         shadow    field elevation\n *   animation  none, fade-scale, slide, stagger (popup open)\n *   behaviour  local or async options (debounced, cancelled, cached) with loading / empty / error states,\n *              ranked matching with highlight, groups, single or multiple (chips), \"Add “…”\" create row,\n *              built-in virtualization for long lists (10k+ rows).\n * Keyboard: ↓ ↑ open and move, Alt+↓ opens, Home/End and PageUp/PageDown move in the open list, Enter picks,\n * Esc closes (then reverts or clears), Backspace on an empty input removes the last chip.\n * Use select when people pick from a short known list; combobox is for typing to search.\n */\n\nexport type ComboboxVariant = \"outline\" | \"filled\" | \"ghost\" | \"underline\" | \"pill\" | \"neo\"\nexport type ComboboxTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type ComboboxSize = \"sm\" | \"md\" | \"lg\"\nexport type ComboboxShadow = \"none\" | \"sm\" | \"md\" | \"lg\"\nexport type ComboboxAnimation = \"none\" | \"fade-scale\" | \"slide\" | \"stagger\"\n\nexport type ComboboxOption = {\n  /** Unique value reported by onValueChange. */\n  value: string\n  /** Text shown in the list, the input and the chips; matched and highlighted. */\n  label: string\n  /** Muted second line; also matched. */\n  description?: string\n  icon?: React.ReactNode\n  /** Image URL, or true for colored initials. */\n  avatar?: string | true\n  /** Section heading; groups keep the order of their best match. */\n  group?: string\n  disabled?: boolean\n  /** Extra search terms (not shown). */\n  keywords?: string[]\n}\ntype RawOption = ComboboxOption | string\n\nexport type ComboboxLabels = {\n  clear: string\n  /** Name of the chevron button that opens and closes the list. */\n  toggle: string\n  remove: (label: string) => string\n  /** Text of the create row. */\n  create: (text: string) => string\n  loading: string\n  empty: (query: string) => string\n  error: string\n  retry: string\n  /** Asks for more characters before an async search starts. */\n  minChars: (n: number) => string\n  /** Announced when the results change. */\n  results: (count: number) => string\n  /** Screen-reader text listing the chips. */\n  selectedHint: (selected: string) => string\n}\nconst DEFAULT_LABELS: ComboboxLabels = {\n  clear: \"Clear\",\n  toggle: \"Show suggestions\",\n  remove: (label) => `Remove ${label}`,\n  create: (text) => `Add “${text}”`,\n  loading: \"Searching…\",\n  empty: (q) => (q ? `No results for “${q}”` : \"No options\"),\n  error: \"Couldn’t load results.\",\n  retry: \"Retry\",\n  minChars: (n) => `Type at least ${n} character${n === 1 ? \"\" : \"s\"}`,\n  results: (n) => (n === 1 ? \"1 result available.\" : `${n} results available.`),\n  selectedHint: (s) => `${s} selected. Backspace removes the last one.`,\n}\n\ntype ComboboxBase = Omit<React.ComponentProps<\"div\">, \"defaultValue\" | \"onChange\" | \"children\" | \"onSubmit\"> & {\n  /** Local options (objects or strings). With loadOptions they are shown before typing and used to label values. */\n  options?: RawOption[]\n  /** Async search. Called after the debounce with the typed text; aborted when the text changes. */\n  loadOptions?: (query: string, ctx: { signal: AbortSignal }) => Promise<RawOption[]>\n  /** Debounce for loadOptions in ms. */\n  debounce?: number\n  /** Characters needed before loadOptions runs. */\n  minChars?: number\n  /** Cache loadOptions results per query for the life of the component. */\n  cache?: boolean\n  /** Custom local match. false shows options unfiltered (when you filter yourself). */\n  filter?: ((option: ComboboxOption, query: string) => boolean) | false\n  /** Shows an \"Add “text”\" row when no option matches the typed text exactly. */\n  creatable?: boolean\n  /** Called with the typed text when the create row is picked. Return the new option (or nothing to use the text). */\n  onCreate?: (text: string) => RawOption | void | Promise<RawOption | void>\n  placeholder?: string\n  /** Field style: outline (default), filled, ghost, underline, pill or neo. */\n  variant?: ComboboxVariant\n  /** Accent for the focus ring, active row, checks and chips. */\n  tone?: ComboboxTone\n  size?: ComboboxSize\n  /** Field shadow. Ignored by neo. */\n  shadow?: ComboboxShadow\n  /** How the list opens: fade-scale (default), slide, stagger (rows one by one; off when virtualized) or none. */\n  animation?: ComboboxAnimation\n  /** × button that clears the value and the text. */\n  clearable?: boolean\n  disabled?: boolean\n  /** Red border and aria-invalid on the input. */\n  invalid?: boolean\n  /** Leading icon in the field. */\n  icon?: React.ReactNode\n  /** Form field name (renders hidden inputs with the value). */\n  name?: string\n  /** Open the list when the input gets focus (by default it opens on typing, click or ↓). */\n  openOnFocus?: boolean\n  /** Rows above which the list is virtualized. */\n  virtualThreshold?: number\n  /** Text in the input (controlled). */\n  inputValue?: string\n  defaultInputValue?: string\n  onInputValueChange?: (text: string) => void\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Class for the popup. */\n  menuClassName?: string\n  /** Names the input and the list. Pass one unless a visible <label htmlFor={id}> points at the input. */\n  \"aria-label\"?: string\n  /** Goes on the input, so <label htmlFor> works. */\n  id?: string\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<ComboboxLabels>\n}\nexport type ComboboxSingleProps = ComboboxBase & {\n  /** true picks several values shown as chips; value then becomes string[]. */\n  multiple?: false\n  /** Selected value (controlled): a string or null, or string[] with multiple. */\n  value?: string | null\n  defaultValue?: string | null\n  /** Called with the new value and its option (null after clearing). */\n  onValueChange?: (value: string | null, option: ComboboxOption | null) => void\n}\nexport type ComboboxMultipleProps = ComboboxBase & {\n  multiple: true\n  value?: string[]\n  defaultValue?: string[]\n  onValueChange?: (value: string[], options: ComboboxOption[]) => void\n}\nexport type ComboboxProps = ComboboxSingleProps | ComboboxMultipleProps\n\nconst CSS = `\n.pc-cbx{--pc-c:var(--primary);--pc-fg:var(--primary-foreground)}\n.pc-cbx[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.pc-cbx[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.pc-cbx[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.pc-cbx[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.pc-cbx[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .pc-cbx[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .pc-cbx[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .pc-cbx[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.pc-cbx{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.pc-cbx[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n.pc-cbx{--pc-ring:color-mix(in oklab,var(--pc-c) 32%,transparent);--pc-edge:color-mix(in oklab,var(--pc-c) 55%,var(--border));--pc-muted:color-mix(in oklab,var(--muted-foreground) 80%,var(--foreground))}\n\n.pc-cbx-field{position:relative;color:var(--foreground);transition:border-color .15s,background-color .15s,box-shadow .15s,transform .12s}\n.pc-cbx[data-variant=outline] .pc-cbx-field,.pc-cbx[data-variant=pill] .pc-cbx-field{background:var(--background);border:1px solid var(--input)}\n.pc-cbx[data-variant=outline] .pc-cbx-field:hover,.pc-cbx[data-variant=pill] .pc-cbx-field:hover{border-color:color-mix(in oklab,var(--pc-c) 30%,var(--input))}\n.pc-cbx[data-variant=filled] .pc-cbx-field{background:var(--muted);border:1px solid transparent}\n.pc-cbx[data-variant=filled] .pc-cbx-field:hover{background:color-mix(in oklab,var(--foreground) 7%,var(--muted))}\n.pc-cbx[data-variant=filled] .pc-cbx-field:focus-within{background:var(--background)}\n.pc-cbx[data-variant=ghost] .pc-cbx-field{border:1px solid transparent}\n.pc-cbx[data-variant=ghost] .pc-cbx-field:is(:hover,:focus-within){background:var(--pc-tint)}\n.pc-cbx[data-variant=underline] .pc-cbx-field{border-radius:0;border-bottom:1.5px solid var(--input);padding-inline:.125rem}\n.pc-cbx[data-variant=underline] .pc-cbx-field::after{content:\"\";position:absolute;inset-inline:0;bottom:-1.5px;height:2px;background:var(--pc-c);transform:scaleX(0);transition:transform .25s var(--pc-ease-out)}\n.pc-cbx[data-variant=underline] .pc-cbx-field:focus-within::after{transform:scaleX(1)}\n.pc-cbx[data-variant=neo] .pc-cbx-field{background:var(--background);border:2px solid var(--foreground);box-shadow:3px 3px 0 var(--foreground)}\n.pc-cbx[data-variant=neo] .pc-cbx-field:focus-within{transform:translate(1px,1px);box-shadow:2px 2px 0 var(--foreground);outline:2px solid var(--pc-c);outline-offset:3px}\n.pc-cbx:is([data-variant=outline],[data-variant=filled],[data-variant=pill]) .pc-cbx-field:focus-within{border-color:var(--pc-edge);box-shadow:0 0 0 3px var(--pc-ring)}\n.pc-cbx[data-invalid] .pc-cbx-field{border-color:oklch(0.56 0.21 27)}\n.pc-cbx[data-variant=underline][data-invalid] .pc-cbx-field::after{background:oklch(0.56 0.21 27);transform:scaleX(1)}\n.pc-cbx[data-shadow=sm] .pc-cbx-field{box-shadow:0 1px 2px rgb(0 0 0/.08)}\n.pc-cbx[data-shadow=md] .pc-cbx-field{box-shadow:0 4px 12px -4px rgb(0 0 0/.16)}\n.pc-cbx[data-shadow=lg] .pc-cbx-field{box-shadow:0 12px 28px -10px rgb(0 0 0/.28)}\n.pc-cbx-input::placeholder{color:var(--pc-muted);opacity:1}\n.pc-cbx-muted{color:var(--pc-muted)}\n.pc-cbx-chev{transition:transform .2s var(--pc-ease-out);color:var(--pc-muted)}\n.pc-cbx[data-open] .pc-cbx-chev{transform:rotate(180deg)}\n.pc-cbx-chip{background:color-mix(in oklab,var(--pc-c) 10%,var(--muted));color:var(--foreground);border:1px solid color-mix(in oklab,var(--pc-c) 16%,transparent)}\n.pc-cbx[data-variant=neo] .pc-cbx-chip{border:1.5px solid var(--foreground);background:color-mix(in oklab,var(--pc-c) 18%,var(--background))}\n\n.pc-cbx-menu{background:var(--popover);color:var(--popover-foreground);border:1px solid var(--border);box-shadow:0 16px 40px -12px rgb(0 0 0/.25),0 4px 10px -4px rgb(0 0 0/.08)}\n.dark .pc-cbx-menu{box-shadow:0 16px 40px -12px rgb(0 0 0/.6),0 0 0 1px rgb(255 255 255/.04)}\n.pc-cbx[data-variant=neo] .pc-cbx-menu{border:2px solid var(--foreground);box-shadow:4px 4px 0 var(--foreground)}\n.pc-cbx-opt{color:var(--foreground)}\n.pc-cbx-opt[data-active]{background:color-mix(in oklab,var(--pc-c) 8%,var(--accent))}\n.pc-cbx-opt[data-selected]{color:var(--pc-ink)}\n.pc-cbx:is([data-tone=neutral],[data-tone=primary]) .pc-cbx-opt[data-selected]{color:var(--foreground)}\n.pc-cbx-opt[aria-disabled=true]{cursor:not-allowed}\n.pc-cbx-opt[aria-disabled=true]>*{opacity:.45}\n.pc-cbx-create{color:var(--pc-ink)}\n.pc-cbx-check{color:var(--pc-c)}\n.pc-cbx-box{border:1.5px solid color-mix(in oklab,var(--foreground) 25%,transparent);transition:background-color .12s,border-color .12s}\n.pc-cbx-opt[data-selected] .pc-cbx-box{background:var(--pc-c);border-color:var(--pc-c);color:var(--pc-fg)}\n.pc-cbx-hl{background:color-mix(in oklab,var(--pc-c) 16%,transparent);color:inherit;font-weight:600;border-radius:3px;padding:0 1px;margin:0 -1px}\n.pc-cbx-spin{animation:pc-cbx-spin .7s linear infinite}\n@keyframes pc-cbx-spin{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){.pc-cbx-field,.pc-cbx-chev,.pc-cbx-field::after{transition:none!important}.pc-cbx-spin{animation-duration:1.6s}}\n`\n\nconst SIZES = {\n  sm: { field: \"min-h-8 px-2.5 text-sm gap-1.5\", chip: \"h-5 text-[11px]\", opt: \"px-2 text-sm gap-2\", icon: \"[&_svg]:size-3.5\", row: 32, rowDesc: 44, head: 26 },\n  md: { field: \"min-h-10 px-3 text-sm gap-2\", chip: \"h-6 text-xs\", opt: \"px-2 text-sm gap-2.5\", icon: \"[&_svg]:size-4\", row: 36, rowDesc: 50, head: 30 },\n  lg: { field: \"min-h-12 px-4 text-base gap-2.5\", chip: \"h-7 text-sm\", opt: \"px-2.5 text-base gap-3\", icon: \"[&_svg]:size-[18px]\", row: 44, rowDesc: 58, head: 32 },\n} satisfies Record<ComboboxSize, Record<string, string | number>>\nconst RADIUS: Record<ComboboxVariant, string> = { outline: \"rounded-lg\", filled: \"rounded-lg\", ghost: \"rounded-lg\", underline: \"rounded-none\", pill: \"rounded-full\", neo: \"rounded-md\" }\nconst MENU_RADIUS: Record<ComboboxVariant, string> = { outline: \"rounded-xl\", filled: \"rounded-xl\", ghost: \"rounded-xl\", underline: \"rounded-lg\", pill: \"rounded-2xl\", neo: \"rounded-md\" }\n\n/* ---------- text matching ---------- */\n\nconst fold = (s: string) => s.normalize(\"NFD\").replace(/[̀-ͯ]/g, \"\").toLowerCase()\n\n/** Folds text and keeps a map from each folded character back to its index in the original. */\nfunction foldMap(s: string) {\n  let out = \"\"\n  const map: number[] = []\n  for (let i = 0; i < s.length; i++) {\n    const f = fold(s[i]!)\n    for (let k = 0; k < f.length; k++) {\n      out += f[k]\n      map.push(i)\n    }\n  }\n  return { out, map }\n}\n\nfunction Highlight({ text, query }: { text: string; query: string }) {\n  const tokens = fold(query).split(/\\s+/).filter(Boolean)\n  if (!tokens.length) return <>{text}</>\n  const { out, map } = foldMap(text)\n  const ranges: [number, number][] = []\n  for (const t of tokens) {\n    let from = 0\n    for (let i = out.indexOf(t, from); i >= 0 && ranges.length < 20; i = out.indexOf(t, from)) {\n      ranges.push([map[i]!, map[i + t.length - 1]! + 1])\n      from = i + t.length\n    }\n  }\n  if (!ranges.length) return <>{text}</>\n  ranges.sort((a, b) => a[0] - b[0])\n  const merged: [number, number][] = []\n  for (const r of ranges) {\n    const last = merged[merged.length - 1]\n    if (last && r[0] <= last[1]) last[1] = Math.max(last[1], r[1])\n    else merged.push([r[0], r[1]])\n  }\n  const parts: React.ReactNode[] = []\n  let at = 0\n  merged.forEach(([a, b], i) => {\n    if (a > at) parts.push(text.slice(at, a))\n    parts.push(\n      <mark key={i} className=\"pc-cbx-hl\">\n        {text.slice(a, b)}\n      </mark>,\n    )\n    at = b\n  })\n  if (at < text.length) parts.push(text.slice(at))\n  return <>{parts}</>\n}\n\nconst toOption = (o: RawOption): ComboboxOption => (typeof o === \"string\" ? { value: o, label: o } : o)\n\ntype Indexed = { o: ComboboxOption; label: string; hay: string }\nconst index = (list: ComboboxOption[]): Indexed[] =>\n  list.map((o) => ({ o, label: fold(o.label), hay: fold([o.label, o.description ?? \"\", o.group ?? \"\", ...(o.keywords ?? [])].join(\" \")) }))\n\n/** Ranks matches: label starts with the text, then a word in the label starts with it, then anywhere. Every word must match. */\nfunction rank(list: Indexed[], query: string): ComboboxOption[] {\n  const q = fold(query.trim())\n  if (!q) return list.map((x) => x.o)\n  const tokens = q.split(/\\s+/)\n  const first = tokens[0]!\n  const wordStart = new RegExp(`(^|[^\\\\p{L}\\\\p{N}])${first.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}`, \"u\")\n  const scored: { o: ComboboxOption; s: number; i: number }[] = []\n  list.forEach((x, i) => {\n    for (const t of tokens) if (!x.hay.includes(t)) return\n    const s = x.label.startsWith(q) ? 0 : x.label.startsWith(first) ? 1 : wordStart.test(x.label) ? 2 : x.label.includes(first) ? 3 : 4\n    scored.push({ o: x.o, s, i })\n  })\n  return scored.sort((a, b) => a.s - b.s || a.i - b.i).map((x) => x.o)\n}\n\n/* ---------- floating placement (flip + shift, no library) ---------- */\n\ntype Side = \"top\" | \"bottom\"\ntype Rect = { top: number; left: number; right: number; bottom: number; width: number; height: number }\ntype Placement = { x: number; y: number; side: Side; maxH: number; width: number }\n\nfunction place(a: Rect, h: number, preferred: Side, lock: boolean): Placement {\n  const pad = 8\n  const offset = 6\n  const vw = document.documentElement.clientWidth\n  const vh = window.innerHeight\n  const room = { top: a.top - offset - pad, bottom: vh - a.bottom - offset - pad }\n  const side: Side = !lock && room[preferred] < h && room[preferred === \"bottom\" ? \"top\" : \"bottom\"] > room[preferred] ? (preferred === \"bottom\" ? \"top\" : \"bottom\") : preferred\n  const maxH = Math.max(120, room[side])\n  const hh = Math.min(h, maxH)\n  const width = Math.min(a.width, vw - pad * 2)\n  return { x: Math.max(pad, Math.min(a.left, vw - pad - width)), y: side === \"bottom\" ? a.bottom + offset : a.top - offset - hh, side, maxH, width }\n}\n\nfunction usePlacement(open: boolean, anchor: React.RefObject<HTMLElement | null>, surface: React.RefObject<HTMLElement | null>) {\n  const [p, setP] = React.useState<Placement | null>(null)\n  const side = React.useRef<Side | null>(null)\n  React.useLayoutEffect(() => {\n    if (!open) {\n      // Keep the last placement so the closing animation plays where the list was.\n      side.current = null\n      return\n    }\n    const update = () => {\n      const el = surface.current\n      const a = anchor.current?.getBoundingClientRect()\n      if (!el || !a) return\n      // The side is chosen once per open, so the list does not jump while results stream in.\n      const next = place(a, el.scrollHeight + (el.offsetHeight - el.clientHeight), side.current ?? \"bottom\", side.current !== null)\n      side.current = next.side\n      setP((prev) =>\n        prev && Math.abs(prev.x - next.x) < 0.5 && Math.abs(prev.y - next.y) < 0.5 && prev.side === next.side && prev.maxH === next.maxH && prev.width === next.width ? prev : next,\n      )\n    }\n    update()\n    let raf = 0\n    const schedule = () => {\n      cancelAnimationFrame(raf)\n      raf = requestAnimationFrame(update)\n    }\n    window.addEventListener(\"scroll\", schedule, true)\n    window.addEventListener(\"resize\", schedule)\n    const ro = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(schedule)\n    if (surface.current) ro?.observe(surface.current)\n    if (anchor.current) ro?.observe(anchor.current)\n    return () => {\n      cancelAnimationFrame(raf)\n      window.removeEventListener(\"scroll\", schedule, true)\n      window.removeEventListener(\"resize\", schedule)\n      ro?.disconnect()\n    }\n  }, [open, anchor, surface, !!p])\n  return p\n}\n\n/* ---------- small parts ---------- */\n\nfunction Avatar({ src, label }: { src: string | true; label: string }) {\n  if (src !== true) return <img src={src} alt=\"\" className=\"size-6 shrink-0 rounded-full object-cover\" />\n  const initials = label\n    .split(/\\s+/)\n    .slice(0, 2)\n    .map((w) => w[0])\n    .join(\"\")\n    .toUpperCase()\n  let h = 0\n  for (const ch of label) h = (h * 31 + ch.charCodeAt(0)) % 360\n  return (\n    <span aria-hidden=\"true\" className=\"grid size-6 shrink-0 place-items-center rounded-full text-[10px] font-semibold text-white\" style={{ background: `oklch(0.5 0.13 ${h})` }}>\n      {initials}\n    </span>\n  )\n}\nconst Check = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"M3.5 8.5 6.5 11.5 12.5 4.5\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n)\nconst Cross = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n  </svg>\n)\nconst Plus = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"M8 3.5v9M3.5 8h9\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" />\n  </svg>\n)\nconst Spinner = ({ className }: { className?: string }) => (\n  <svg className={cn(\"pc-cbx-spin\", className)} viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\">\n    <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeOpacity=\".25\" strokeWidth=\"3\" />\n    <path d=\"M21 12a9 9 0 0 0-9-9\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" />\n  </svg>\n)\n\ntype Entry = { kind: \"option\"; o: ComboboxOption } | { kind: \"create\"; text: string }\ntype Row = { kind: \"head\"; label: string } | { kind: \"entry\"; e: Entry; n: number }\n\n/* ---------- component ---------- */\n\nexport function Combobox(props: ComboboxProps) {\n  const {\n    options: rawOptions,\n    loadOptions,\n    debounce = 250,\n    minChars = 0,\n    cache = true,\n    filter,\n    creatable,\n    onCreate,\n    placeholder = \"Type to search…\",\n    variant = \"outline\",\n    tone = \"primary\",\n    size = \"md\",\n    shadow = \"none\",\n    animation = \"fade-scale\",\n    clearable,\n    disabled,\n    invalid,\n    icon,\n    name,\n    openOnFocus,\n    virtualThreshold = 100,\n    inputValue: inputProp,\n    defaultInputValue,\n    onInputValueChange,\n    open: openProp,\n    defaultOpen = false,\n    onOpenChange,\n    menuClassName,\n    className,\n    multiple,\n    value: valueProp,\n    defaultValue,\n    onValueChange,\n    \"aria-label\": ariaLabel,\n    labels,\n    id: idProp,\n    ...rest\n  } = props\n  const l = useLabels(\"combobox\", DEFAULT_LABELS, labels)\n  const prefersReduced = useReducedMotion()\n  const [mounted, setMounted] = React.useState(false)\n  React.useEffect(() => setMounted(true), [])\n  const reduce = mounted && !!prefersReduced\n  const uid = React.useId()\n  const inputId = idProp ?? uid + \"-input\"\n  const listId = uid + \"-list\"\n  const optId = (n: number) => `${uid}-opt-${n}`\n\n  /* options and the labels of known values (async results, created ones) */\n  const [created, setCreated] = React.useState<ComboboxOption[]>([])\n  const local = React.useMemo(() => [...(rawOptions ?? []).map(toOption), ...created], [rawOptions, created])\n  const known = React.useRef(new Map<string, ComboboxOption>())\n  for (const o of local) known.current.set(o.value, o)\n\n  /* value */\n  const [inner, setInner] = React.useState<string | string[] | null | undefined>(defaultValue)\n  const current = valueProp !== undefined ? valueProp : inner\n  const selected: string[] = Array.isArray(current) ? current : current ? [current] : []\n  const optionOf = (v: string): ComboboxOption => known.current.get(v) ?? { value: v, label: v }\n  const commit = (next: string[]) => {\n    if (valueProp === undefined) setInner(multiple ? next : (next[0] ?? null))\n    if (multiple) (onValueChange as ComboboxMultipleProps[\"onValueChange\"])?.(next, next.map(optionOf))\n    else (onValueChange as ComboboxSingleProps[\"onValueChange\"])?.(next[0] ?? null, next[0] ? optionOf(next[0]) : null)\n  }\n  const singleLabel = !multiple && selected[0] ? optionOf(selected[0]).label : \"\"\n\n  /* input text */\n  const [textInner, setTextInner] = React.useState(defaultInputValue ?? (!multiple && selected[0] ? optionOf(selected[0]).label : \"\"))\n  const text = inputProp ?? textInner\n  const setText = (t: string) => {\n    if (inputProp === undefined) setTextInner(t)\n    onInputValueChange?.(t)\n  }\n  // The text only filters after the user typed; a picked label shows the full list again.\n  const [dirty, setDirty] = React.useState(false)\n  const query = dirty ? text : \"\"\n\n  // Follow controlled value changes in single mode (unless the user is typing).\n  const lastSingle = React.useRef(singleLabel)\n  React.useEffect(() => {\n    if (multiple || lastSingle.current === singleLabel) return\n    lastSingle.current = singleLabel\n    if (!dirty) setText(singleLabel)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [singleLabel])\n\n  /* open state */\n  const [openInner, setOpenInner] = React.useState(defaultOpen)\n  const open = (openProp ?? openInner) && !disabled\n  const setOpen = (o: boolean) => {\n    if (o === open) return\n    if (openProp === undefined) setOpenInner(o)\n    onOpenChange?.(o)\n  }\n\n  /* async */\n  const [remote, setRemote] = React.useState<{ status: \"idle\" | \"loading\" | \"done\" | \"error\"; query: string; options: ComboboxOption[] }>({ status: \"idle\", query: \"\", options: [] })\n  const [retry, setRetry] = React.useState(0)\n  const cacheRef = React.useRef(new Map<string, ComboboxOption[]>())\n  const loader = React.useRef(loadOptions)\n  React.useLayoutEffect(() => {\n    loader.current = loadOptions\n  })\n  const asyncMode = !!loadOptions\n  const tooShort = asyncMode && query.trim().length < minChars\n  React.useEffect(() => {\n    if (!asyncMode || !open) return\n    const q = query.trim()\n    if (q.length < minChars || (!q && rawOptions)) {\n      setRemote({ status: \"idle\", query: q, options: [] })\n      return\n    }\n    const hit = cache ? cacheRef.current.get(q) : undefined\n    if (hit) {\n      setRemote({ status: \"done\", query: q, options: hit })\n      return\n    }\n    setRemote((r) => ({ ...r, status: \"loading\" }))\n    const ctrl = new AbortController()\n    const t = window.setTimeout(() => {\n      Promise.resolve(loader.current?.(q, { signal: ctrl.signal }) ?? [])\n        .then((res) => {\n          if (ctrl.signal.aborted) return\n          const list = res.map(toOption)\n          for (const o of list) known.current.set(o.value, o)\n          if (cache) cacheRef.current.set(q, list)\n          setRemote({ status: \"done\", query: q, options: list })\n        })\n        .catch(() => {\n          if (!ctrl.signal.aborted) setRemote((r) => ({ ...r, status: \"error\", query: q }))\n        })\n    }, debounce)\n    return () => {\n      window.clearTimeout(t)\n      ctrl.abort()\n    }\n  }, [asyncMode, open, query, minChars, debounce, cache, retry, !!rawOptions])\n\n  /* visible entries */\n  const indexed = React.useMemo(() => index(local), [local])\n  const matches = React.useMemo(() => {\n    if (asyncMode && query.trim() && !tooShort) return remote.options\n    if (asyncMode && tooShort && !rawOptions) return []\n    if (filter === false) return local\n    if (filter) return local.filter((o) => filter(o, query))\n    return rank(indexed, query)\n  }, [asyncMode, query, tooShort, remote.options, rawOptions, filter, local, indexed])\n\n  const showCreate =\n    !!creatable && !!text.trim() && dirty && !tooShort && remote.status !== \"loading\" && !matches.some((o) => fold(o.label) === fold(text.trim())) && !local.some((o) => fold(o.label) === fold(text.trim()))\n\n  const { rows, entries } = React.useMemo(() => {\n    const groups: { name?: string; items: ComboboxOption[] }[] = []\n    for (const o of matches) {\n      const g = groups.find((x) => x.name === o.group)\n      if (g) g.items.push(o)\n      else groups.push({ name: o.group, items: [o] })\n    }\n    const rows: Row[] = []\n    const entries: Entry[] = []\n    for (const g of groups) {\n      if (g.name) rows.push({ kind: \"head\", label: g.name })\n      for (const o of g.items) {\n        const e: Entry = { kind: \"option\", o }\n        rows.push({ kind: \"entry\", e, n: entries.length })\n        entries.push(e)\n      }\n    }\n    if (showCreate) {\n      const e: Entry = { kind: \"create\", text: text.trim() }\n      rows.push({ kind: \"entry\", e, n: entries.length })\n      entries.push(e)\n    }\n    return { rows, entries }\n  }, [matches, showCreate, text])\n\n  const enabled = (n: number) => {\n    const e = entries[n]\n    return !!e && (e.kind === \"create\" || !e.o.disabled)\n  }\n  const step = (from: number, dir: 1 | -1, wrap = true) => {\n    const len = entries.length\n    for (let k = 1; k <= len; k++) {\n      let i = from + dir * k\n      if (wrap) i = ((i % len) + len) % len\n      else if (i < 0 || i >= len) break\n      if (enabled(i)) return i\n    }\n    return wrap ? -1 : from\n  }\n\n  const [active, setActive] = React.useState(-1)\n  const revertLater = React.useRef(false)\n  // After a pick in multiple mode the list resets; keep the picked row active.\n  const keepActive = React.useRef<string | null>(null)\n  // Highlight the first match while typing; on a fresh open, the selected option. Layout effect: Enter right after\n  // results arrive must already see the highlight.\n  React.useLayoutEffect(() => {\n    if (!open) return\n    const keep = keepActive.current\n    keepActive.current = null\n    const kept = keep === null ? -1 : entries.findIndex((e) => e.kind === \"option\" && e.o.value === keep)\n    if (kept >= 0) setActive(kept)\n    else if (query.trim()) setActive(step(-1, 1))\n    else {\n      const sel = entries.findIndex((e) => e.kind === \"option\" && selected.includes(e.o.value) && !e.o.disabled)\n      setActive(sel)\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [entries, open])\n\n  /* refs */\n  const root = React.useRef<HTMLDivElement>(null)\n  const field = React.useRef<HTMLDivElement>(null)\n  const input = React.useRef<HTMLInputElement>(null)\n  const surface = React.useRef<HTMLDivElement>(null)\n  const scroller = React.useRef<HTMLDivElement>(null)\n  const p = usePlacement(open && mounted, field, surface)\n\n  /* virtualization */\n  const s = SIZES[size]\n  const hasDesc = matches.some((o) => o.description)\n  const rowH = hasDesc ? s.rowDesc : s.row\n  const virtual = rows.length > virtualThreshold\n  const offsets = React.useMemo(() => {\n    if (!virtual) return null\n    const out = new Array<number>(rows.length + 1)\n    out[0] = 0\n    rows.forEach((r, i) => (out[i + 1] = out[i]! + (r.kind === \"head\" ? s.head : rowH)))\n    return out\n  }, [virtual, rows, rowH, s.head])\n  const rowOfEntry = React.useMemo(() => {\n    const m: number[] = []\n    rows.forEach((r, i) => r.kind === \"entry\" && (m[r.n] = i))\n    return m\n  }, [rows])\n  const [scroll, setScroll] = React.useState({ top: 0, h: 288 })\n  React.useLayoutEffect(() => {\n    if (!open || !scroller.current) return\n    scroller.current.scrollTop = 0\n    setScroll({ top: 0, h: scroller.current.clientHeight || 288 })\n  }, [open, query, virtual, !!p])\n\n  // Keep the active row in view.\n  React.useEffect(() => {\n    const sc = scroller.current\n    if (!open || active < 0 || !sc) return\n    if (offsets) {\n      const r = rowOfEntry[active] ?? 0\n      const top = offsets[r]!\n      const bottom = offsets[r + 1]!\n      // Show the group heading above the first option of a group.\n      const head = r > 0 && rows[r - 1]?.kind === \"head\" ? offsets[r - 1]! : top\n      if (head < sc.scrollTop) sc.scrollTop = head\n      else if (bottom > sc.scrollTop + sc.clientHeight) sc.scrollTop = bottom - sc.clientHeight\n    } else sc.querySelector<HTMLElement>(`[id=\"${optId(active)}\"]`)?.scrollIntoView({ block: \"nearest\" })\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [active, open])\n\n  /* actions */\n  const openList = () => {\n    if (disabled || open) return\n    setOpen(true)\n  }\n  const closeList = () => {\n    setOpen(false)\n    setActive(-1)\n  }\n  const revert = () => {\n    setDirty(false)\n    if (!multiple) setText(singleLabel)\n    else setText(\"\")\n  }\n\n  const pick = async (e: Entry) => {\n    if (e.kind === \"option\") {\n      const o = e.o\n      if (o.disabled) return\n      known.current.set(o.value, o)\n      if (multiple) {\n        commit(selected.includes(o.value) ? selected.filter((v) => v !== o.value) : [...selected, o.value])\n        keepActive.current = o.value\n        setText(\"\")\n        setDirty(false)\n      } else {\n        commit([o.value])\n        lastSingle.current = o.label\n        setText(o.label)\n        setDirty(false)\n        closeList()\n      }\n      return\n    }\n    const res = await onCreate?.(e.text)\n    const o = res ? toOption(res) : { value: e.text, label: e.text }\n    known.current.set(o.value, o)\n    setCreated((c) => (c.some((x) => x.value === o.value) ? c : [...c, o]))\n    if (multiple) {\n      if (!selected.includes(o.value)) commit([...selected, o.value])\n      setText(\"\")\n    } else {\n      commit([o.value])\n      lastSingle.current = o.label\n      setText(o.label)\n      closeList()\n    }\n    setDirty(false)\n  }\n\n  const clear = () => {\n    commit([])\n    lastSingle.current = \"\"\n    setText(\"\")\n    setDirty(false)\n    input.current?.focus()\n  }\n\n  /* outside pointer closes */\n  React.useEffect(() => {\n    if (!open) return\n    const onDown = (e: PointerEvent) => {\n      const t = e.target as Node\n      if (root.current?.contains(t) || surface.current?.contains(t)) return\n      closeList()\n      if (dirty) revertLater.current = true\n    }\n    document.addEventListener(\"pointerdown\", onDown, true)\n    return () => document.removeEventListener(\"pointerdown\", onDown, true)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [open, dirty])\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.nativeEvent.isComposing) return\n    const len = entries.length\n    switch (e.key) {\n      case \"ArrowDown\":\n        e.preventDefault()\n        if (!open) {\n          openList()\n          if (!e.altKey && active < 0) setActive(step(-1, 1))\n        } else if (!e.altKey) setActive((a) => step(a, 1))\n        break\n      case \"ArrowUp\":\n        e.preventDefault()\n        if (e.altKey) {\n          closeList()\n          break\n        }\n        if (!open) {\n          openList()\n          setActive(step(len, -1))\n        } else setActive((a) => step(a < 0 ? len : a, -1))\n        break\n      case \"PageDown\":\n      case \"PageUp\":\n        if (!open || !len) break\n        e.preventDefault()\n        setActive((a) => {\n          const dir = e.key === \"PageDown\" ? 1 : -1\n          let i = Math.max(0, Math.min(len - 1, (a < 0 ? 0 : a) + dir * 10))\n          if (!enabled(i)) i = step(i, dir, false)\n          return enabled(i) ? i : a\n        })\n        break\n      case \"Home\":\n      case \"End\":\n        if (!open || e.shiftKey || !len) break\n        e.preventDefault()\n        setActive(e.key === \"Home\" ? step(-1, 1) : step(len, -1))\n        break\n      case \"Enter\": {\n        if (!open) break\n        const en = entries[active]\n        if (en) {\n          e.preventDefault()\n          void pick(en)\n        }\n        break\n      }\n      case \"Escape\":\n        if (open) {\n          e.preventDefault()\n          e.stopPropagation()\n          closeList()\n        } else if (dirty || (multiple && text)) {\n          e.preventDefault()\n          revert()\n        } else if (clearable && selected.length) {\n          e.preventDefault()\n          clear()\n        }\n        break\n      case \"Backspace\":\n        if (multiple && !text && selected.length) {\n          e.preventDefault()\n          commit(selected.slice(0, -1))\n        }\n        break\n      case \"Tab\":\n        if (open) closeList()\n        break\n    }\n  }\n\n  /* motion */\n  const pop = p?.side === \"top\" ? 1 : -1\n  const t: Transition = reduce || animation === \"none\" ? { duration: 0 } : spring.snap\n  const menuMotion = reduce\n    ? { initial: { opacity: 0 }, animate: { opacity: 1 } }\n    : animation === \"fade-scale\"\n      ? { initial: { opacity: 0, scale: 0.97, y: pop * 4 }, animate: { opacity: 1, scale: 1, y: 0 } }\n      : animation === \"slide\"\n        ? { initial: { opacity: 0, y: pop * 10, clipPath: p?.side === \"top\" ? \"inset(100% 0 0 0)\" : \"inset(0 0 100% 0)\" }, animate: { opacity: 1, y: 0, clipPath: \"inset(0 0 0% 0)\" } }\n        : animation === \"stagger\"\n          ? { initial: { opacity: 0, y: pop * 4 }, animate: { opacity: 1, y: 0 } }\n          : { initial: false as const, animate: { opacity: 1 } }\n  const exitT: Transition = animation === \"none\" ? { duration: 0 } : { duration: 0.12 }\n  const staggerRows = animation === \"stagger\" && !reduce && !virtual\n\n  /* status line under the list */\n  const q = query.trim()\n  const status: { kind: \"loading\" | \"empty\" | \"error\" | \"short\"; text: string } | null =\n    asyncMode && tooShort && !rawOptions\n      ? { kind: \"short\", text: l.minChars(minChars) }\n      : asyncMode && remote.status === \"loading\" && (q ? remote.query !== q || !matches.length : !matches.length)\n        ? { kind: \"loading\", text: l.loading }\n        : asyncMode && remote.status === \"error\" && q\n          ? { kind: \"error\", text: l.error }\n          : !entries.length\n            ? { kind: \"empty\", text: l.empty(q) }\n            : null\n  const announce = !open ? \"\" : status ? status.text : l.results(matches.length)\n\n  /* rows */\n  const renderRow = (r: Row, i: number, style?: React.CSSProperties) => {\n    if (r.kind === \"head\")\n      return (\n        <div\n          key={\"h\" + i + r.label}\n          role=\"presentation\"\n          style={style}\n          className={cn(\"pc-cbx-muted flex items-end px-2 pb-1 text-[11px] font-medium tracking-wide uppercase\", !virtual && \"pt-2\", i > 0 && !virtual && \"mt-1 border-t pt-2.5\")}\n        >\n          <span className=\"truncate\">{r.label}</span>\n        </div>\n      )\n    const { e, n } = r\n    const isActive = n === active\n    if (e.kind === \"create\")\n      return (\n        <div\n          key=\"create\"\n          id={optId(n)}\n          role=\"option\"\n          aria-selected={false}\n          aria-posinset={n + 1}\n          aria-setsize={entries.length}\n          data-active={isActive ? \"\" : undefined}\n          style={style ?? { minHeight: s.row }}\n          className={cn(\"pc-cbx-opt pc-cbx-create flex cursor-pointer items-center rounded-md font-medium select-none\", s.opt, variant === \"pill\" && \"rounded-xl\")}\n          onPointerMove={() => !isActive && setActive(n)}\n          onPointerDown={(ev) => ev.preventDefault()}\n          onClick={() => void pick(e)}\n        >\n          <Plus className=\"size-4 shrink-0\" />\n          <span className=\"truncate\">{l.create(e.text)}</span>\n        </div>\n      )\n    const o = e.o\n    const isSel = selected.includes(o.value)\n    const anim = staggerRows ? { initial: { opacity: 0, y: -4 }, animate: { opacity: 1, y: 0 }, transition: { delay: 0.03 + Math.min(n, 10) * 0.025, duration: 0.2 } } : { initial: false as const }\n    return (\n      <motion.div\n        key={o.value}\n        {...anim}\n        id={optId(n)}\n        role=\"option\"\n        aria-selected={isSel}\n        aria-disabled={o.disabled || undefined}\n        aria-posinset={n + 1}\n        aria-setsize={entries.length}\n        data-active={isActive ? \"\" : undefined}\n        data-selected={isSel ? \"\" : undefined}\n        style={style ?? { minHeight: s.row }}\n        className={cn(\"pc-cbx-opt flex cursor-pointer items-center rounded-md select-none\", virtual ? \"py-0\" : \"py-1.5\", s.opt, variant === \"pill\" && \"rounded-xl\")}\n        onPointerMove={() => !o.disabled && !isActive && setActive(n)}\n        onPointerDown={(ev) => ev.preventDefault()}\n        onClick={() => void pick(e)}\n      >\n        {multiple && <span className=\"pc-cbx-box grid size-4 shrink-0 place-items-center rounded-[5px]\">{isSel && <Check className=\"size-3\" />}</span>}\n        {o.avatar ? <Avatar src={o.avatar} label={o.label} /> : o.icon ? <span className=\"pc-cbx-muted inline-flex shrink-0 [&_svg]:size-4\">{o.icon}</span> : null}\n        <span className=\"flex min-w-0 flex-1 flex-col\">\n          <span className=\"truncate\">\n            <Highlight text={o.label} query={q} />\n          </span>\n          {o.description && (\n            <span className=\"pc-cbx-muted truncate text-xs\">\n              <Highlight text={o.description} query={q} />\n            </span>\n          )}\n        </span>\n        {!multiple && isSel && <Check className=\"pc-cbx-check size-4 shrink-0\" />}\n      </motion.div>\n    )\n  }\n\n  let body: React.ReactNode\n  if (offsets) {\n    const total = offsets[rows.length]!\n    const top = scroll.top - 200\n    const bottom = scroll.top + scroll.h + 200\n    let lo = 0\n    let hi = rows.length - 1\n    while (lo < hi) {\n      const mid = (lo + hi) >> 1\n      if (offsets[mid + 1]! <= top) lo = mid + 1\n      else hi = mid\n    }\n    const vis: React.ReactNode[] = []\n    for (let i = lo; i < rows.length && offsets[i]! < bottom; i++) vis.push(renderRow(rows[i]!, i, { position: \"absolute\", insetInline: 0, top: offsets[i], height: offsets[i + 1]! - offsets[i]! }))\n    body = <div style={{ height: total, position: \"relative\" }}>{vis}</div>\n  } else body = rows.map((r, i) => renderRow(r, i))\n\n  const chips = multiple ? selected.map(optionOf) : []\n\n  const listContent = (\n    <>\n      <div\n        ref={scroller}\n        id={listId}\n        role=\"listbox\"\n        aria-multiselectable={multiple || undefined}\n        aria-label={ariaLabel}\n        aria-labelledby={ariaLabel ? undefined : inputId}\n        aria-busy={remote.status === \"loading\" || undefined}\n        className={cn(\"max-h-72 min-h-0 overflow-y-auto overscroll-contain\", !rows.length && \"hidden\")}\n        onScroll={(e) => {\n          const el = e.currentTarget\n          if (virtual) setScroll({ top: el.scrollTop, h: el.clientHeight })\n        }}\n      >\n        {body}\n      </div>\n      {status && (\n        <div\n          onPointerDown={(e) => e.preventDefault()}\n          className={cn(\"pc-cbx-muted flex items-center justify-center gap-2 px-3 text-center text-sm\", rows.length ? \"border-t py-2\" : \"py-5\")}\n        >\n          {status.kind === \"loading\" && <Spinner className=\"size-4\" />}\n          <span>{status.text}</span>\n          {status.kind === \"error\" && (\n            <button\n              type=\"button\"\n              tabIndex={-1}\n              onClick={() => setRetry((r) => r + 1)}\n              className=\"pc-press rounded-md px-1.5 py-0.5 font-medium text-foreground underline underline-offset-2 outline-none hover:bg-muted\"\n            >\n              {l.retry}\n            </button>\n          )}\n        </div>\n      )}\n    </>\n  )\n  const surfaceClass = cn(\"pc-cbx-menu flex flex-col overflow-hidden p-1\", MENU_RADIUS[variant], menuClassName)\n  const surfaceStyle = { maxHeight: p?.maxH, transformOrigin: p?.side === \"top\" ? \"bottom center\" : \"top center\" }\n  const popup = (\n    <div\n      key=\"popup\"\n      data-variant={variant}\n      data-tone={tone}\n      className=\"pc-cbx fixed z-50\"\n      style={{ left: p?.x ?? 0, top: p?.y ?? 0, width: p?.width ?? field.current?.offsetWidth, visibility: p ? undefined : \"hidden\" }}\n    >\n      {p ? (\n        <motion.div ref={surface} {...menuMotion} exit={{ opacity: 0, transition: exitT }} transition={reduce ? { duration: 0.12 } : t} style={surfaceStyle} className={surfaceClass}>\n          {listContent}\n        </motion.div>\n      ) : (\n        <div ref={surface} style={surfaceStyle} className={surfaceClass}>\n          {listContent}\n        </div>\n      )}\n    </div>\n  )\n\n  return (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-combobox\" precedence=\"default\">\n        {CSS}\n      </style>\n      <div\n        {...rest}\n        ref={root}\n        data-slot=\"combobox\"\n        data-variant={variant}\n        data-tone={tone}\n        data-shadow={variant === \"neo\" ? \"none\" : shadow}\n        data-open={open ? \"\" : undefined}\n        data-invalid={invalid ? \"\" : undefined}\n        className={cn(\"pc-cbx relative w-72 max-w-full\", disabled && \"pointer-events-none opacity-55\", className)}\n      >\n        <div\n          ref={field}\n          className={cn(\"pc-cbx-field flex w-full cursor-text flex-wrap items-center py-1\", s.field, s.icon, RADIUS[variant])}\n          onPointerDown={(e) => {\n            const t = e.target as HTMLElement\n            if (t === input.current || t.closest(\"button\")) return\n            e.preventDefault()\n            input.current?.focus()\n            if (open) closeList()\n            else openList()\n          }}\n        >\n          {icon && <span className=\"pc-cbx-muted inline-flex shrink-0\">{icon}</span>}\n          {multiple && (\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              {chips.map((o) => (\n                <motion.span\n                  key={o.value}\n                  layout={!reduce && animation !== \"none\"}\n                  initial={reduce || animation === \"none\" ? false : { opacity: 0, scale: 0.8 }}\n                  animate={{ opacity: 1, scale: 1 }}\n                  exit={{ opacity: 0, scale: 0.8 }}\n                  transition={t}\n                  className={cn(\"pc-cbx-chip inline-flex max-w-full items-center gap-1 rounded-md ps-1.5 pe-0.5 font-medium\", s.chip, variant === \"pill\" && \"rounded-full ps-2\")}\n                >\n                  <span className=\"truncate\">{o.label}</span>\n                  <button\n                    type=\"button\"\n                    aria-label={l.remove(o.label)}\n                    disabled={disabled}\n                    onClick={() => {\n                      commit(selected.filter((v) => v !== o.value))\n                      input.current?.focus()\n                    }}\n                    className=\"pc-press grid size-4 shrink-0 cursor-pointer place-items-center rounded-sm opacity-70 outline-none hover:bg-foreground/10 hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/60\"\n                  >\n                    <Cross className=\"!size-3\" />\n                  </button>\n                </motion.span>\n              ))}\n            </AnimatePresence>\n          )}\n          <input\n            ref={input}\n            id={inputId}\n            type=\"text\"\n            role=\"combobox\"\n            aria-autocomplete=\"list\"\n            aria-expanded={open}\n            aria-controls={open ? listId : undefined}\n            aria-activedescendant={open && active >= 0 && entries[active] ? optId(active) : undefined}\n            aria-label={ariaLabel}\n            aria-invalid={invalid || undefined}\n            aria-describedby={multiple && chips.length ? uid + \"-chips\" : undefined}\n            autoComplete=\"off\"\n            autoCorrect=\"off\"\n            spellCheck={false}\n            disabled={disabled}\n            placeholder={multiple && chips.length ? undefined : placeholder}\n            value={text}\n            onChange={(e) => {\n              setText(e.target.value)\n              setDirty(true)\n              if (!open) openList()\n            }}\n            onKeyDown={onKeyDown}\n            onClick={() => openList()}\n            onFocus={() => {\n              if (openOnFocus) openList()\n            }}\n            onBlur={(e) => {\n              const to = e.relatedTarget as Node | null\n              if (to && surface.current?.contains(to)) return\n              closeList()\n              if (dirty || revertLater.current) {\n                revertLater.current = false\n                // Emptying the text and leaving clears a single value; anything else snaps back to the selection.\n                if (!multiple && !text.trim() && selected.length) {\n                  commit([])\n                  lastSingle.current = \"\"\n                  setDirty(false)\n                } else revert()\n              }\n            }}\n            className=\"pc-cbx-input h-7 min-w-16 flex-1 bg-transparent outline-none disabled:cursor-not-allowed\"\n          />\n          {multiple && chips.length > 0 && (\n            <span id={uid + \"-chips\"} className=\"sr-only\">\n              {l.selectedHint(chips.map((o) => o.label).join(\", \"))}\n            </span>\n          )}\n          {asyncMode && remote.status === \"loading\" && open && <Spinner className=\"pc-cbx-muted !size-4 shrink-0\" />}\n          {clearable && (selected.length > 0 || text) && !disabled && (\n            <button\n              type=\"button\"\n              aria-label={l.clear}\n              onClick={clear}\n              className=\"pc-press pc-cbx-muted grid size-5 shrink-0 place-items-center rounded-md outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\"\n            >\n              <Cross className=\"!size-3.5\" />\n            </button>\n          )}\n          <button\n            type=\"button\"\n            tabIndex={-1}\n            aria-label={l.toggle}\n            aria-expanded={open}\n            aria-controls={open ? listId : undefined}\n            disabled={disabled}\n            onPointerDown={(e) => e.preventDefault()}\n            onClick={() => {\n              input.current?.focus()\n              if (open) closeList()\n              else openList()\n            }}\n            className=\"pc-press grid size-5 shrink-0 place-items-center rounded-md outline-none\"\n          >\n            <svg className=\"pc-cbx-chev !size-4\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n              <path d=\"m4 6 4 4 4-4\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n            </svg>\n          </button>\n        </div>\n        <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n          {announce}\n        </span>\n        {name && (multiple ? selected.map((v) => <input key={v} type=\"hidden\" name={name} value={v} />) : <input type=\"hidden\" name={name} value={selected[0] ?? \"\"} />)}\n      </div>\n      {mounted && createPortal(<AnimatePresence>{open && popup}</AnimatePresence>, document.body)}\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/combobox.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}