import {
    useGridColumn,
    useGridContext,
    useGridSelector,
} from '../context/grid-context'
import type { Column, GridRowData } from '../types'

/**
 * hook to get column and sort information for use when rendering column headers
 */
export function useColumnHeader<T extends GridRowData>(columnId: string) {
    const { selectors } = useGridContext()
    const column = useGridColumn(columnId)
    const sort = useGridSelector((state) =>
        selectors.selectColumnSort(state, columnId)
    )
    const sortNumber = useGridSelector((state) =>
        selectors.selectColumnSortNumber(state, columnId)
    )

    return {
        column: column.data as Column<T>,
        sort,
        sortNumber,
    }
}
