"use client"; import React, { useEffect, useRef, useState } from "react"; import { ChevronDown } from "lucide-react"; export default function EventsDropdown({ options, value, onChange }: { options: { value: string; label: string }[]; value: string[]; onChange: (v: string[]) => void; }) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { const onClick = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; document.addEventListener("mousedown", onClick); return () => document.removeEventListener("mousedown", onClick); }, []); const toggle = (v: string) => { onChange(value.includes(v) ? value.filter(x => x !== v) : [...value, v]); }; const summary = value.length === 0 ? "No events selected" : options.length > 0 && value.length === options.length ? "All events" : value.length === 1 ? (options.find(o => o.value === value[0])?.label || "1 event selected") : `${value.length} events selected`; return (
{open && (
{options.map(opt => ( ))} {options.length === 0 &&
No events available.
}
)}
); }