"use client" 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" import { cn } from "@/lib/utils" import { Check, ChevronsUpDown, X } from "lucide-react" import * as React from "react" export interface ComboboxOption { value: string label: string } interface ComboboxProps { options: ComboboxOption[] value?: string onValueChange?: (value: string) => void placeholder?: string searchPlaceholder?: string emptyText?: string className?: string } export function Combobox({ options, value, onValueChange, placeholder = "Select option...", searchPlaceholder = "Search...", emptyText = "No option found.", className, }: ComboboxProps) { const [open, setOpen] = React.useState(false) const handleClear = (e: React.MouseEvent) => { e.stopPropagation() // prevent popover from opening onValueChange?.("") } return ( { const option = options.find((opt) => opt.value === value) if (!option) return 0 return option.label.toLowerCase().includes(search.toLowerCase()) ? 1 : 0 }} > {emptyText} {options.map((option) => ( { onValueChange?.(currentValue === value ? "" : currentValue) setOpen(false) }} > {option.label} ))} ) }