'use client'; import * as React from 'react'; import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react'; import { cn } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from '@/components/ui/command'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; export interface ComboboxOption { value: string; label: string; } interface ComboboxProps { options: ComboboxOption[]; value?: string; onChange: (value: string) => void; placeholder?: string; searchPlaceholder?: string; emptyText?: string; disabled?: boolean; loading?: boolean; className?: string; id?: string; 'aria-invalid'?: boolean; 'aria-describedby'?: string; } /** * `Select` com busca, usado nas listas longas do sistema (cliente, * produto/serviço) — seção 7 do schema de frontend. Composição de * Command + Popover, não do `Select` nativo do Radix. */ function Combobox({ options, value, onChange, placeholder = 'Selecionar…', searchPlaceholder = 'Buscar…', emptyText = 'Nenhum resultado encontrado.', disabled, loading, className, id, ...aria }: ComboboxProps) { const [open, setOpen] = React.useState(false); const selected = options.find((option) => option.value === value); return ( {emptyText} {options.map((option) => ( { onChange(option.value); setOpen(false); }} > {option.label} ))} ); } export { Combobox };