import { useEffect, useRef } from 'react' import CountsResizeHandle from '@/components/counts/CountsResizeHandle' import { Button } from '@/components/ui/button' import { useUITranslation } from '@/lib/useUITranslation' import type { CountSort } from '@/lib/counts' const CountsSortHeader = ( { field, label, sorts, change, structured = false }: { field: string label: { text: string; language: string } sorts: CountSort[] change: (key: string, additive: boolean) => void structured?: boolean }, ) => { const { message } = useUITranslation ('counts') const press = useRef<{ x: number; y: number timer: ReturnType } | null> (null) const suppressClick = useRef (false) const cancel = () => { if (press.current != null) clearTimeout (press.current.timer) press.current = null } useEffect (() => () => { if (press.current != null) clearTimeout (press.current.timer) }, []) const priority = sorts.findIndex (sort => sort.key === field) const direction = sorts[priority]?.direction const state = priority < 0 ? 'none' : (direction === 'asc' ? 'ascending' : 'descending') const title = message (structured ? 'sort.structured' : 'sort.action') const aria = message (priority < 0 ? 'sort.unsortedLabel' : (sorts.length === 1 ? 'sort.singleLabel' : 'sort.label'), { column: label.text, priority: priority + 1, direction: message (`sort.${state}`).text }) return ( 1 && priority >= 0) ? 'other' : state}> ) } export default CountsSortHeader