{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "combobox-9",
  "type": "registry:component",
  "title": "Combobox 9",
  "description": "Combobox 9. A combobox component for selecting from a list of options.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "command",
    "label",
    "popover"
  ],
  "files": [
    {
      "path": "components/watermelon/combobox-9.tsx",
      "type": "registry:component",
      "content": "'use client'\n\nimport { useId, useState } from 'react'\n\nimport { ChevronDownIcon } from 'lucide-react'\n\nimport {\n  Command,\n  CommandEmpty,\n  CommandInput,\n  CommandItem,\n  CommandList\n} from '@/components/base-ui/command'\nimport { Label } from '@/components/base-ui/label'\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/base-ui/popover'\n\ntype CountryOption = {\n  flag: string\n  label: string\n  value: string\n}\n\nconst countries = [\n  {\n    value: 'india',\n    label: 'India',\n    flag: 'https://flagcdn.com/w40/in.png'\n  },\n  {\n    value: 'japan',\n    label: 'Japan',\n    flag: 'https://flagcdn.com/w40/jp.png'\n  },\n  {\n    value: 'canada',\n    label: 'Canada',\n    flag: 'https://flagcdn.com/w40/ca.png'\n  },\n  {\n    value: 'germany',\n    label: 'Germany',\n    flag: 'https://flagcdn.com/w40/de.png'\n  },\n  {\n    value: 'brazil',\n    label: 'Brazil',\n    flag: 'https://flagcdn.com/w40/br.png'\n  },\n  {\n    value: 'france',\n    label: 'France',\n    flag: 'https://flagcdn.com/w40/fr.png'\n  }\n] as const satisfies readonly CountryOption[]\n\ntype CountryValue = (typeof countries)[number]['value']\n\nconst countryByValue: Record<CountryValue, (typeof countries)[number]> = {\n  india: countries[0],\n  japan: countries[1],\n  canada: countries[2],\n  germany: countries[3],\n  brazil: countries[4],\n  france: countries[5]\n}\n\nconst isCountryValue = (value: string): value is CountryValue =>\n  countries.some((country) => country.value === value)\n\nconst Combobox9 = () => {\n  const id = useId()\n  const [open, setOpen] = useState<boolean>(false)\n  const [selectedCountry, setSelectedCountry] = useState<CountryValue | ''>('')\n\n  const selectedCountryOption = selectedCountry\n    ? countryByValue[selectedCountry]\n    : undefined\n\n  return (\n    <div className='w-full max-w-xs space-y-2'>\n      <Label htmlFor={id} className='text-sm font-medium'>\n        Country picker\n      </Label>\n      <Popover open={open} onOpenChange={setOpen}>\n        <PopoverTrigger\n          id={id}\n          role='combobox'\n          aria-expanded={open}\n          className='flex h-10 w-full items-center justify-between rounded-xl border border-border/60 bg-background px-3.5 text-sm shadow-xs outline-none transition-colors hover:bg-accent/20 focus-visible:ring-[3px] focus-visible:ring-ring/50'\n        >\n          {selectedCountryOption ? (\n            <span className='flex min-w-0 items-center gap-2'>\n              <img\n                src={selectedCountryOption.flag}\n                alt={`${selectedCountryOption.label} flag`}\n                className='h-4 w-5 rounded-[2px] object-cover'\n              />\n              <span className='truncate'>{selectedCountryOption.label}</span>\n            </span>\n          ) : (\n            <span className='text-muted-foreground'>Select country</span>\n          )}\n          <ChevronDownIcon\n            className='text-muted-foreground/80 size-4 shrink-0'\n            aria-hidden='true'\n          />\n        </PopoverTrigger>\n        <PopoverContent\n          className='w-full min-w-(--radix-popper-anchor-width) rounded-xl border-border/60 p-0 shadow-sm'\n          align='start'\n        >\n          <Command>\n            <CommandInput placeholder='Search country...' className='h-9 px-1' />\n            <CommandList className='mt-2 rounded-lg px-1 pb-1'>\n              <CommandEmpty>No country found.</CommandEmpty>\n              {countries.map((country) => (\n                <CommandItem\n                  key={country.value}\n                  value={country.value}\n                  data-checked={selectedCountry === country.value}\n                  onSelect={(currentValue) => {\n                    if (currentValue === selectedCountry) {\n                      setSelectedCountry('')\n                      setOpen(false)\n                      return\n                    }\n\n                    if (!isCountryValue(currentValue)) {\n                      return\n                    }\n\n                    setSelectedCountry(currentValue)\n                    setOpen(false)\n                  }}\n                className='rounded-lg pr-2'\n                >\n                  <img\n                    src={country.flag}\n                    alt={`${country.label} flag`}\n                    className='h-4 w-5 rounded-[2px] object-cover'\n                  />\n                  <span className='min-w-0 flex-1 truncate'>{country.label}</span>\n                </CommandItem>\n              ))}\n            </CommandList>\n          </Command>\n        </PopoverContent>\n      </Popover>\n    </div>\n  )\n}\n\nexport default Combobox9\n"
    }
  ]
}
