'use client' import { useState } from 'react' import { Building2, ChevronDown, Check, Search } from 'lucide-react' import { cn } from '@/lib/utils' interface Client { id: string nombre: string codigo: string } interface ClientSelectorProps { clients?: Client[] selectedId?: string | null onChange?: (clientId: string | null) => void showAll?: boolean } export default function ClientSelector({ clients = [], selectedId = null, onChange, showAll = true, }: ClientSelectorProps) { const [open, setOpen] = useState(false) const [search, setSearch] = useState('') const selectedClient = selectedId ? clients.find((c) => c.id === selectedId) : null const filteredClients = clients.filter( (c) => c.nombre.toLowerCase().includes(search.toLowerCase()) || c.codigo.toLowerCase().includes(search.toLowerCase()) ) const handleSelect = (id: string | null) => { onChange?.(id) setOpen(false) setSearch('') } return (
{open && ( <>
{ setOpen(false) setSearch('') }} />
{/* Search */}
setSearch(e.target.value)} placeholder="Buscar cliente..." className="input py-1.5 pl-8 text-sm" autoFocus />
{/* Options */}
{showAll && ( )} {filteredClients.length === 0 ? (
No se encontraron clientes
) : ( filteredClients.map((client) => ( )) )}
)}
) }