{"version":3,"file":"Combobox-BXeV7i1G.cjs","names":["Popover","PopoverTrigger","cn","ChevronDownIcon","PopoverContent","Command","CommandInput","CommandList","CommandEmpty","CommandGroup","CommandItem","CheckIcon"],"sources":["../../../store/core/src/countries-api-context.ts","../../../platform/ui-components/src/components/Combobox.tsx"],"sourcesContent":["import { createContext, type Provider, use } from \"react\";\nimport type { CountriesApi } from \"./countries-api\";\n\nconst CountriesApiContext = createContext<CountriesApi | null>(null);\n\nexport const CountriesApiProvider: Provider<CountriesApi | null> =\n  CountriesApiContext.Provider;\n\nexport function useCountriesApi(): CountriesApi {\n  const api = use(CountriesApiContext);\n  if (!api) {\n    throw new Error(\n      \"useCountriesApi must be used within a CountriesApiProvider\",\n    );\n  }\n  return api;\n}\n","import type React from \"react\";\nimport { useState } from \"react\";\nimport { CheckIcon, ChevronDownIcon } from \"lucide-react\";\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n  cn,\n} from \"@fluid-app/ui-primitives\";\n\ntype ComboboxOption = {\n  label: string;\n  value: string;\n};\n\ntype ComboboxProps = {\n  /** Available options to choose from. */\n  options: ReadonlyArray<ComboboxOption>;\n  /** Currently selected value (controlled). */\n  value: string;\n  /** Called when an option is selected or cleared. */\n  onValueChange: (value: string) => void;\n  /** Placeholder shown when no option is selected. */\n  placeholder?: string;\n  /** Message shown when the search query matches no options. */\n  emptyText?: string;\n  /** Disables the input. */\n  disabled?: boolean;\n  /**\n   * Stacking order for the dropdown popover. Defaults to the primitive's\n   * layer; pass a higher value when rendering inside an overlay (e.g. a bottom\n   * sheet at z-1050) so the options render above it.\n   */\n  zIndex?: number;\n};\n\nexport type { ComboboxOption, ComboboxProps };\n\nexport function Combobox({\n  options,\n  value,\n  onValueChange,\n  placeholder = \"Select...\",\n  emptyText = \"No results found.\",\n  disabled = false,\n  zIndex,\n}: ComboboxProps): React.JSX.Element {\n  const [open, setOpen] = useState(false);\n  const [search, setSearch] = useState(\"\");\n\n  const selectedOption = options.find((opt) => opt.value === value);\n\n  const filtered = search\n    ? options.filter((opt) =>\n        opt.label.toLowerCase().includes(search.toLowerCase()),\n      )\n    : options;\n\n  return (\n    // `modal` gives the popover its own scroll lock. Without it, a surrounding\n    // dialog's lock swallows wheel events over the option list.\n    <Popover\n      open={open}\n      onOpenChange={(next) => {\n        setOpen(next);\n        if (!next) setSearch(\"\");\n      }}\n      modal\n    >\n      <PopoverTrigger asChild>\n        <button\n          type=\"button\"\n          role=\"combobox\"\n          aria-expanded={open}\n          disabled={disabled}\n          className={cn(\n            \"border-input flex h-9 w-full cursor-pointer items-center justify-between gap-2 rounded-md border bg-transparent px-3 text-sm shadow-xs transition-[color,box-shadow]\",\n            \"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] focus-visible:outline-none\",\n            open && \"border-ring ring-ring/50 ring-[3px]\",\n            disabled && \"cursor-not-allowed opacity-50\",\n          )}\n        >\n          <span\n            className={cn(\n              \"truncate\",\n              !selectedOption && \"text-muted-foreground\",\n            )}\n          >\n            {selectedOption ? selectedOption.label : placeholder}\n          </span>\n          <ChevronDownIcon className=\"size-4 shrink-0 opacity-50\" />\n        </button>\n      </PopoverTrigger>\n      <PopoverContent\n        className=\"bg-popover w-[var(--radix-popover-trigger-width)] rounded-md border p-0 shadow-md\"\n        align=\"start\"\n        style={zIndex === undefined ? undefined : { zIndex }}\n      >\n        {/* Plain substring matching, so cmdk's fuzzy scorer stays out of it. */}\n        <Command shouldFilter={false}>\n          <CommandInput\n            placeholder={placeholder}\n            value={search}\n            onValueChange={setSearch}\n          />\n          <CommandList>\n            {filtered.length === 0 && <CommandEmpty>{emptyText}</CommandEmpty>}\n            <CommandGroup>\n              {filtered.map((opt) => (\n                <CommandItem\n                  key={opt.value}\n                  value={opt.label}\n                  onSelect={() => {\n                    onValueChange(opt.value === value ? \"\" : opt.value);\n                    setOpen(false);\n                    setSearch(\"\");\n                  }}\n                >\n                  {opt.label}\n                  <CheckIcon\n                    className={cn(\n                      \"ml-auto size-4\",\n                      value === opt.value ? \"opacity-100\" : \"opacity-0\",\n                    )}\n                  />\n                </CommandItem>\n              ))}\n            </CommandGroup>\n          </CommandList>\n        </Command>\n      </PopoverContent>\n    </Popover>\n  );\n}\n"],"mappings":";;;;;;AAGA,MAAM,uBAAA,GAAA,MAAA,eAAyD,KAAK;AAEpE,MAAa,uBACX,oBAAoB;AAEtB,SAAgB,kBAAgC;CAC9C,MAAM,OAAA,GAAA,MAAA,KAAU,oBAAoB;AACpC,KAAI,CAAC,IACH,OAAM,IAAI,MACR,6DACD;AAEH,QAAO;;;;AC6BT,SAAgB,SAAS,EACvB,SACA,OACA,eACA,cAAc,aACd,YAAY,qBACZ,WAAW,OACX,UACmC;CACnC,MAAM,CAAC,MAAM,YAAA,GAAA,MAAA,UAAoB,MAAM;CACvC,MAAM,CAAC,QAAQ,cAAA,GAAA,MAAA,UAAsB,GAAG;CAExC,MAAM,iBAAiB,QAAQ,MAAM,QAAQ,IAAI,UAAU,MAAM;CAEjE,MAAM,WAAW,SACb,QAAQ,QAAQ,QACd,IAAI,MAAM,aAAa,CAAC,SAAS,OAAO,aAAa,CAAC,CACvD,GACD;AAEJ,QAGE,iBAAA,GAAA,kBAAA,MAACA,YAAAA,SAAD;EACQ;EACN,eAAe,SAAS;AACtB,WAAQ,KAAK;AACb,OAAI,CAAC,KAAM,WAAU,GAAG;;EAE1B,OAAA;YANF,CAQE,iBAAA,GAAA,kBAAA,KAACC,YAAAA,gBAAD;GAAgB,SAAA;aACd,iBAAA,GAAA,kBAAA,MAAC,UAAD;IACE,MAAK;IACL,MAAK;IACL,iBAAe;IACL;IACV,WAAWC,YAAAA,GACT,wKACA,4GACA,QAAQ,uCACR,YAAY,gCACb;cAVH,CAYE,iBAAA,GAAA,kBAAA,KAAC,QAAD;KACE,WAAWA,YAAAA,GACT,YACA,CAAC,kBAAkB,wBACpB;eAEA,iBAAiB,eAAe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