import { BaseEntity, CatalogColumn, } from '@redocly/theme/components/Catalog/CatalogTableView/CatalogTableView'; type CatalogTableHeaderCellActionsProps = { column: CatalogColumn; currentSortOption?: string | null; handleSortClick: (sortKey: string, direction: 'asc' | 'desc') => void; isColumnSorted: (sortKey: string, direction: 'asc' | 'desc') => boolean; }; export function useCatalogTableHeaderCellActions({ column, currentSortOption, handleSortClick, isColumnSorted, }: CatalogTableHeaderCellActionsProps) { const sortKey = column.sortKey; const isUpActive = Boolean( sortKey && (currentSortOption ? currentSortOption === sortKey : isColumnSorted(sortKey, 'desc')), ); const isDownActive = Boolean( sortKey && (currentSortOption ? currentSortOption === `-${sortKey}` : isColumnSorted(sortKey, 'asc')), ); const handleCellClick = (): void => { if (!column.sortable || !sortKey) return; if (isDownActive) { handleSortClick(sortKey, 'desc'); } else { handleSortClick(sortKey, 'asc'); } }; return { handleCellClick, sortKey, isUpActive, isDownActive }; }