/* eslint-disable unicorn/explicit-length-check */
/**
 * @desc 表格排序事件hooks
 * @author 邓欢
 */
import { useCallback } from 'react';
export default function useSortChanged(onSortChanged) {
    return useCallback((event) => {
        const sortModel = event.api.getSortModel();
        if (sortModel.length) {
            onSortChanged &&
                onSortChanged({
                    fieldName: sortModel[0].colId || '',
                    direction: (sortModel[0].sort && sortModel[0].sort.toUpperCase()) || '',
                });
        }
        else {
            onSortChanged && onSortChanged();
        }
    }, [onSortChanged]);
}
