'use client'; import { Icon } from '@umami/react-zen'; import type { ReactNode } from 'react'; import { useNavigation } from '@/components/hooks'; import { ChevronDown, ChevronUp } from '@/components/icons'; type SortDirection = 'asc' | 'desc'; export interface SortableLabelProps { label: ReactNode; sortKey: string; defaultDirection?: SortDirection; } export function SortableLabel({ label, sortKey, defaultDirection = 'asc' }: SortableLabelProps) { const { router, query, updateParams } = useNavigation(); const isActive = query.orderBy === sortKey; const isDescending = query.sortDescending === 'true'; const direction = isActive ? (isDescending ? 'desc' : 'asc') : undefined; const activeColor = 'var(--zen-fg)'; const getNextDirection = (): SortDirection => { if (!isActive) { return defaultDirection; } return direction === 'desc' ? 'asc' : 'desc'; }; const handleSort = () => { const nextDirection = getNextDirection(); router.push( updateParams({ orderBy: sortKey, sortDescending: nextDirection === 'desc' ? 'true' : undefined, page: 1, }), ); }; return ( ); }