import { ArrowDownWideNarrow, Check, ChevronDown } from 'lucide-react'; import { useRef, useState } from 'react'; import { useOutsideClick } from '../../hooks/use-outside-click'; export type SortByValues = 'viewCount' | 'createdAt' | '-createdAt'; const sortingLabels: { label: string; value: SortByValues }[] = [ { label: 'Most Viewed', value: 'viewCount', }, { label: 'Newest', value: 'createdAt', }, { label: 'Oldest', value: '-createdAt', }, ]; type ExploreAISortingProps = { sortBy: SortByValues; onSortChange: (sortBy: SortByValues) => void; }; export function ExploreAISorting(props: ExploreAISortingProps) { const { sortBy, onSortChange } = props; const [isOpen, setIsOpen] = useState(false); const dropdownRef = useRef(null); const selectedValue = sortingLabels.find((item) => item.value === sortBy); useOutsideClick(dropdownRef, () => { setIsOpen(false); }); return (
{isOpen && (
{sortingLabels.map((item) => ( ))}
)}
); }