"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSelectGroup = void 0;
var react_1 = require("react");
function useSelectGroup() {
    var _a = react_1.useState(new Map()), selected = _a[0], setSelected = _a[1];
    var selectedRef = react_1.useRef(selected);
    var onSelect = react_1.useCallback(function (resourceId, select) {
        if (select === void 0) { select = true; }
        setSelected(function (draft) {
            var newSelected = new Map(draft);
            if (select) {
                newSelected.set(resourceId, true);
            }
            else if (newSelected.get(resourceId) === true) {
                newSelected.delete(resourceId);
            }
            selectedRef.current = newSelected;
            return newSelected;
        });
    }, []);
    var onUnselectAll = react_1.useCallback(function () {
        setSelected(new Map());
        selectedRef.current = new Map();
    }, []);
    var checkSelected = react_1.useCallback(function (id) {
        return selectedRef.current.has(id);
    }, []);
    return [onSelect, onUnselectAll, selected, checkSelected];
}
exports.useSelectGroup = useSelectGroup;
//# sourceMappingURL=useSelectGroup.js.map