'use strict';

var DataListContext = require('./DataListContext-cjs.js');

function useBatchSelect() {
    const { selected, onSelect, onSelectAll } = DataListContext.useDataListContext();
    const isArray = Array.isArray(selected);
    const selectedIDs = getIDs(selected);
    const isSelectAll = !isArray;
    return {
        canSelect: Boolean(selected && onSelect),
        canSelectAll: Boolean(onSelect && onSelectAll),
        hasAtLeastOneSelected: isSelectAll || selectedIDs.length > 0,
        isSelectAll,
        isSelectSome: isArray,
        selectedCount: getSelectedCount(selected),
        selectedIDs,
        selected,
        onSelect,
        onSelectAll,
    };
}
function getIDs(selected) {
    if (Array.isArray(selected))
        return selected;
    if (selected === undefined)
        return [];
    return selected.unselected;
}
function getSelectedCount(selected) {
    if (Array.isArray(selected))
        return selected.length;
    if (selected === undefined)
        return 0;
    return selected.totalCount - selected.unselected.length;
}

exports.useBatchSelect = useBatchSelect;
