import { useBoolean, useRequest, useToggle } from 'ahooks' import { CheckIcon, UserIcon, XIcon, AlertTriangleIcon } from 'lucide-react' import { formatCPF } from '@brazilian-utils/brazilian-utils' import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar' import { Abbr } from '@repo/ui/components/abbr' import { InputGroup, InputGroupAddon, InputGroupInput } from '@repo/ui/components/ui/input-group' import { initials, cn } from '@repo/ui/lib/utils' import { Popover, PopoverContent, PopoverTrigger } from '@repo/ui/components/ui/popover' import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@repo/ui/components/ui/command' import { Spinner } from '@repo/ui/components/ui/spinner' import { Button } from '@repo/ui/components/ui/button' interface AsyncComboboxProps { value: any title: string placeholder?: string onChange: (props: any) => void onSearch: (search: string) => Promise error?: any } export function AsyncCombobox({ title, placeholder, value, onSearch, onChange, error }: AsyncComboboxProps) { const [open, { set }] = useToggle() const [searched, { setTrue }] = useBoolean() const { data = [], loading, runAsync } = useRequest(onSearch, { manual: true, debounceWait: 300, defaultParams: [''], onSuccess: setTrue }) return ( {value && ( )} {loading && ( )} {searched ? ( Nenhum resultado encontrado. {data.map(({ id, name, email, cpf }) => ( { onChange?.({ id, name, email, cpf }) set(false) }} >
{initials(name)}
  • {name}
  • {email}
  • {cpf ? (
  • {formatCPF(cpf)}
  • ) : (
  • InelegĂ­vel
  • )}
))}
) : null}
) }