"use client"; import { useState, useRef, useEffect, Fragment } from 'react'; import { Combobox, Transition } from '@headlessui/react'; import { ChevronUpDownIcon, CheckIcon, MagnifyingGlassIcon } from '@heroicons/react/24/outline'; interface Option { id: string; name: string; subtitle?: string; } interface SearchableSelectProps { options: Option[]; value: string; onChange: (value: string | null) => void; placeholder?: string; emptyText?: string; label?: string; helperText?: string; } export default function SearchableSelect({ options, value, onChange, placeholder = 'Selecione...', emptyText = 'Nenhum resultado encontrado', label, helperText, }: SearchableSelectProps) { const [query, setQuery] = useState(''); const selectedOption = options.find(opt => opt.id === value); const filteredOptions = query === '' ? options : options.filter((option) => option.name.toLowerCase().includes(query.toLowerCase()) || option.subtitle?.toLowerCase().includes(query.toLowerCase()) ); return (
{helperText}
)}