import { motion, AnimatePresence } from "framer-motion"; import { cn } from "@/public/lib/utils"; import { Check, ChevronDown } from "lucide-react"; import { useState } from "react"; interface SettingOption { label: string; value: string; } interface SelectDropdownProps { dropdownId: string; label: string; options: SettingOption[]; value: string | Array; placeholder?: string; onChange: (value: string | Array) => void; } export const SelectDropdown = ( { dropdownId, label, options, value, placeholder, onChange }: SelectDropdownProps ) => { const [openDropdown, setOpenDropdown] = useState(null); const handleDropdownToggle = (dropdownId: string) => { setOpenDropdown(openDropdown === dropdownId ? null : dropdownId); }; return (
handleDropdownToggle(dropdownId)} whileHover={{ scale: 1.01 }} whileTap={{ scale: 0.99 }} >
{Array.isArray(value) ? ( {value.map(v => options.find(opt => opt.value === v)?.label).join(',')} ) : ( {options.find(opt => opt.value === value)?.label || value} )} {(!value || value.length === 0) && {placeholder}}
{openDropdown === dropdownId && ( {options.map((option) => ( { if (Array.isArray(value) && value.includes(option.value)) { onChange(value.filter(v => v !== option.value)); } else { onChange(Array.isArray(value) ? [...value, option.value] : option.value); } handleDropdownToggle(dropdownId); }} whileHover={{ x: 4 }} > {option.label} {value.includes(option.value) && } ))} )}
) };