import { cn } from "@/app/utils/functions"; import { ChevronDownIcon } from "@/app/utils/svgs/chevronDownIcon"; import { useEffect, useRef, useState } from "react"; interface SortOption { key: string; label: string; } interface SortDropdownProps { sortOptions: SortOption[]; sortKey: string; setSortKey: (key: string) => void; } export const SortDropdown: React.FC = ({ sortOptions, sortKey, setSortKey, }) => { const [sortOpen, setSortOpen] = useState(false); const dropdownRef = useRef(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setSortOpen(false); } }; if (sortOpen) { document.addEventListener("mousedown", handleClickOutside); } else { document.removeEventListener("mousedown", handleClickOutside); } return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [sortOpen]); const currentSortLabel = sortOptions.find((opt) => opt.key === sortKey)?.label || "Select"; return (
{sortOpen && (
    {sortOptions.map((opt) => { const selected = opt.key === sortKey; return (
  • { setSortKey(opt.key); setSortOpen(false); }} className={`cursor-pointer text-xs md:text-sm -tracking-[0.035px] p-3 font-secondary border-b border-[var(--color-secondary-200)] flex items-center gap-2 text-[var(--color-secondary-800)]`} >

    {opt.label}
  • ); })}
)}
); };