"use client";
const require_use_did_update = require("../use-did-update/use-did-update.cjs");
let react = require("react");
//#region packages/@mantine/hooks/src/use-selection/use-selection.ts
function useSelection(input) {
	const [selectionSet, setSelectionSet] = (0, react.useState)(new Set(input.defaultSelection || []));
	require_use_did_update.useDidUpdate(() => {
		if (input.resetSelectionOnDataChange) setSelectionSet(/* @__PURE__ */ new Set());
	}, [input.data, input.resetSelectionOnDataChange]);
	const select = (0, react.useCallback)((selected) => {
		setSelectionSet((state) => {
			if (!state.has(selected)) {
				const newSet = new Set(state);
				newSet.add(selected);
				return newSet;
			}
			return state;
		});
	}, []);
	const deselect = (0, react.useCallback)((deselected) => {
		setSelectionSet((state) => {
			if (state.has(deselected)) {
				const newSet = new Set(state);
				newSet.delete(deselected);
				return newSet;
			}
			return state;
		});
	}, []);
	const toggle = (0, react.useCallback)((toggled) => {
		setSelectionSet((state) => {
			const newSet = new Set(state);
			if (state.has(toggled)) newSet.delete(toggled);
			else newSet.add(toggled);
			return newSet;
		});
	}, []);
	const resetSelection = (0, react.useCallback)(() => {
		setSelectionSet(/* @__PURE__ */ new Set());
	}, []);
	const setSelection = (0, react.useCallback)((selection) => {
		setSelectionSet(new Set(selection));
	}, []);
	const isAllSelected = (0, react.useCallback)(() => {
		if (input.data.length === 0) return false;
		return input.data.every((item) => selectionSet.has(item));
	}, [selectionSet, input.data]);
	const isSomeSelected = (0, react.useCallback)(() => {
		return input.data.some((item) => selectionSet.has(item));
	}, [selectionSet, input.data]);
	return [Array.from(selectionSet), {
		select,
		deselect,
		toggle,
		isAllSelected,
		isSomeSelected,
		setSelection,
		resetSelection
	}];
}
//#endregion
exports.useSelection = useSelection;

//# sourceMappingURL=use-selection.cjs.map