"use client"; import { Button } from "@suphark/ui/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@suphark/ui/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@suphark/ui/components/ui/popover"; import { cn } from "@suphark/ui/lib/utils"; import { Check, ChevronsUpDown } from "lucide-react"; import { useState } from "react"; export interface SearchableSelectOption { value: string; label: string; [key: string]: any; } interface SearchableSelectProps { value: string | null | undefined; onChange: (val: string | null) => void; options: SearchableSelectOption[]; placeholder?: string; searchPlaceholder?: string; emptyText?: string; clearLabel?: string; allowClear?: boolean; disabled?: boolean; className?: string; popoverWidth?: string; } export function SearchableSelect({ value, onChange, options, placeholder = "เลือกรายการ...", searchPlaceholder = "ค้นหา...", emptyText = "ไม่พบข้อมูล", clearLabel = "-- ไม่ระบุ (General) --", allowClear = true, disabled = false, className, popoverWidth = "w-[240px]", }: SearchableSelectProps) { const [open, setOpen] = useState(false); const selectedOption = options.find((opt) => opt.value === value); return ( } > {selectedOption ? selectedOption.label : placeholder} {emptyText} {allowClear && ( { onChange(null); setOpen(false); }} className="font-medium text-muted-foreground text-xs" > {clearLabel} )} {options.map((option) => ( { onChange(option.value); setOpen(false); }} className="text-xs" > {option.label} ))} ); }