{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-phone-input",
  "title": "Phone Input",
  "description": "Phone input field with country code selection and flags.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/button",
    "@lema-ds/command",
    "@lema-ds/popover",
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-phone-input.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { Check, ChevronsUpDown } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n} from \"@/components/ui/command\"\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from \"@/components/ui/popover\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\n\n// ── Data ──\n\nexport interface CountryData {\n  iso: string\n  name: string\n  code: string\n  flag: string\n}\n\n// A reduced list for the design system. In a real project,\n// you could inject this list or use a library like libphonenumber-js.\nconst defaultCountries: CountryData[] = [\n  { iso: \"BR\", name: \"Brazil\", code: \"+55\", flag: \"🇧🇷\" },\n  { iso: \"US\", name: \"United States\", code: \"+1\", flag: \"🇺🇸\" },\n  { iso: \"PT\", name: \"Portugal\", code: \"+351\", flag: \"🇵🇹\" },\n  { iso: \"ES\", name: \"Spain\", code: \"+34\", flag: \"🇪🇸\" },\n  { iso: \"FR\", name: \"France\", code: \"+33\", flag: \"🇫🇷\" },\n  { iso: \"UK\", name: \"United Kingdom\", code: \"+44\", flag: \"🇬🇧\" },\n  { iso: \"AR\", name: \"Argentina\", code: \"+54\", flag: \"🇦🇷\" },\n  { iso: \"CO\", name: \"Colombia\", code: \"+57\", flag: \"🇨🇴\" },\n  { iso: \"MX\", name: \"Mexico\", code: \"+52\", flag: \"🇲🇽\" },\n]\n\n// ── Variants ──\n\nexport const phoneInputContainerVariants = cva(\n  \"flex w-full items-center rounded-md border border-input bg-background ring-offset-background transition-colors focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2\",\n  {\n    variants: {\n      size: {\n        sm: \"h-8 text-xs\",\n        md: \"h-9 text-sm\",\n        lg: \"h-10 text-base\",\n      },\n      disabled: {\n        true: \"cursor-not-allowed opacity-50\",\n      },\n      invalid: {\n        true: \"border-destructive focus-within:ring-destructive\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n    },\n  }\n)\n\nexport const phoneInputInputVariants = cva(\n  \"flex-1 bg-transparent px-3 py-1 outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed\",\n  {\n    variants: {\n      size: {\n        sm: \"text-xs\",\n        md: \"text-sm\",\n        lg: \"text-base\",\n      },\n    },\n    defaultVariants: {\n      size: \"md\",\n    },\n  }\n)\n\n// ── Types ──\n\nexport interface PhoneInputProps\n  extends\n    Omit<\n      React.InputHTMLAttributes<HTMLInputElement>,\n      \"size\" | \"onChange\" | \"value\"\n    >,\n    Omit<\n      VariantProps<typeof phoneInputContainerVariants>,\n      \"disabled\" | \"invalid\"\n    > {\n  value?: string\n  onChange?: (value: string) => void\n  country?: string\n  onCountryChange?: (country: string) => void\n  countries?: CountryData[]\n  loading?: boolean\n  invalid?: boolean\n  disabled?: boolean\n  locale?: UILocale\n}\n\n// ── Component ──\n\nexport const PhoneInput = React.forwardRef<HTMLInputElement, PhoneInputProps>(\n  (\n    {\n      value,\n      onChange,\n      country = \"BR\",\n      onCountryChange,\n      countries = defaultCountries,\n      size = \"md\",\n      disabled = false,\n      invalid = false,\n      loading = false,\n      locale: localeProp,\n      placeholder,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const [open, setOpen] = React.useState(false)\n    const [selectedCountry, setSelectedCountry] = React.useState<CountryData>(\n      countries.find((c) => c.iso === country) || countries[0]\n    )\n\n    const i18n = UI_I18N[locale].phoneInput\n\n    React.useEffect(() => {\n      const newCountry = countries.find((c) => c.iso === country)\n      if (newCountry) {\n        setSelectedCountry(newCountry)\n      }\n    }, [country, countries])\n\n    if (loading) {\n      const dims = {\n        sm: \"h-8\",\n        md: \"h-9\",\n        lg: \"h-10\",\n      }\n      return (\n        <Skeleton className={cn(\"w-full\", dims[size || \"md\"], className)} />\n      )\n    }\n\n    return (\n      <div\n        className={cn(\n          phoneInputContainerVariants({ size, disabled, invalid }),\n          className\n        )}\n        data-slot=\"ds-phone-input\"\n      >\n        <Popover open={open} onOpenChange={setOpen}>\n          <PopoverTrigger asChild>\n            <Button\n              variant=\"ghost\"\n              role=\"combobox\"\n              aria-expanded={open}\n              aria-label={selectedCountry.name}\n              disabled={disabled}\n              className={cn(\n                \"flex shrink-0 items-center gap-1.5 rounded-l-md rounded-r-none border-r px-3 text-muted-foreground hover:bg-muted hover:text-foreground\",\n                size === \"sm\"\n                  ? \"h-full text-xs\"\n                  : size === \"lg\"\n                    ? \"h-full text-base\"\n                    : \"h-full text-sm\",\n                disabled && \"pointer-events-none opacity-50\"\n              )}\n            >\n              <span className=\"text-base leading-none\">\n                {selectedCountry.flag}\n              </span>\n              <span className=\"hidden sm:inline-block\">\n                {selectedCountry.code}\n              </span>\n              <ChevronsUpDown className=\"ml-1 size-3.5 opacity-50\" />\n            </Button>\n          </PopoverTrigger>\n          <PopoverContent className=\"w-[280px] p-0\" align=\"start\">\n            <Command>\n              <CommandInput placeholder={i18n.searchCountry} />\n              <CommandList>\n                <CommandEmpty>{i18n.noCountryFound}</CommandEmpty>\n                <CommandGroup>\n                  {countries.map((c) => (\n                    <CommandItem\n                      key={c.iso}\n                      value={`${c.name} ${c.code} ${c.iso}`}\n                      onSelect={() => {\n                        setSelectedCountry(c)\n                        onCountryChange?.(c.iso)\n                        setOpen(false)\n                      }}\n                    >\n                      <Check\n                        className={cn(\n                          \"mr-2 size-4\",\n                          selectedCountry.iso === c.iso\n                            ? \"opacity-100\"\n                            : \"opacity-0\"\n                        )}\n                      />\n                      <span className=\"mr-2 text-base leading-none\">\n                        {c.flag}\n                      </span>\n                      <span className=\"flex-1 text-sm\">{c.name}</span>\n                      <span className=\"text-sm text-muted-foreground\">\n                        {c.code}\n                      </span>\n                    </CommandItem>\n                  ))}\n                </CommandGroup>\n              </CommandList>\n            </Command>\n          </PopoverContent>\n        </Popover>\n        <input\n          ref={ref}\n          type=\"tel\"\n          className={phoneInputInputVariants({ size })}\n          disabled={disabled}\n          value={value}\n          onChange={(e) => onChange?.(e.target.value)}\n          placeholder={placeholder}\n          aria-label={props[\"aria-label\"] || placeholder || \"Phone number\"}\n          aria-invalid={invalid}\n          {...props}\n        />\n      </div>\n    )\n  }\n)\nPhoneInput.displayName = \"PhoneInput\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
