"use client" import { useState, type ReactNode } from "react" import { CheckIcon, ChevronsUpDownIcon } from "lucide-react" 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 { useI18n } from "@/i18n/provider" export type ComboboxOption = { value: string label: string } type OptionComboboxProps = { value: string options: ComboboxOption[] placeholder: string searchPlaceholder?: string emptyText?: string disabled?: boolean onChange: (value: string) => void renderOptionAction?: (option: ComboboxOption) => ReactNode } export function OptionCombobox({ value, options, placeholder, searchPlaceholder, emptyText, disabled = false, onChange, renderOptionAction, }: OptionComboboxProps) { const t = useI18n() const [open, setOpen] = useState(false) const selectedLabel = options.find((option) => option.value === value)?.label ?? placeholder return ( } > {selectedLabel} {emptyText ?? t("common.emptyOptions")} {options.map((option) => ( { onChange(option.value) setOpen(false) }} >
{option.label}
{renderOptionAction ? (
event.preventDefault()} onClick={(event) => event.stopPropagation()} > {renderOptionAction(option)}
) : null}
))}
) }