"use client"; import { useState, useRef, useEffect } from "react"; import { FiChevronDown, FiCheck } from "react-icons/fi"; import { useTheme } from "@/context/ThemeContext"; import { SORT_OPTIONS } from "./sortOptions"; interface Props { value: string; onChange: (v: string) => void; } export function SortDropdown({ value, onChange }: Props) { const [open, setOpen] = useState(false); const { isDark } = useTheme(); const ref = useRef(null); const active = SORT_OPTIONS.find((o) => o.value === value) ?? SORT_OPTIONS[0]; useEffect(() => { const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, []); const triggerCl = isDark ? "bg-slate-900 border-slate-700 text-slate-200 hover:border-violet-500/50" : "bg-white border-slate-200 text-slate-700 hover:border-violet-400"; const menuCl = isDark ? "bg-slate-900 border-slate-700 shadow-xl shadow-black/40" : "bg-white border-slate-200 shadow-xl shadow-slate-200/60"; return (
{open && (
{SORT_OPTIONS.map((opt) => { const isActive = opt.value === value; return ( ); })}
)}
); }