'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState, useCallback, useMemo } from 'react';
const BulkSelectionContext = createContext(null);
export function BulkSelectionProvider({ children }) {
    const [selectedIds, setSelectedIds] = useState(new Set());
    const toggleSelection = useCallback((id) => {
        setSelectedIds((prev) => {
            const next = new Set(prev);
            if (next.has(id)) {
                next.delete(id);
            }
            else {
                next.add(id);
            }
            return next;
        });
    }, []);
    const selectAll = useCallback((ids) => {
        setSelectedIds(new Set(ids));
    }, []);
    const clearSelection = useCallback(() => {
        setSelectedIds(new Set());
    }, []);
    const isSelected = useCallback((id) => selectedIds.has(id), [selectedIds]);
    const value = useMemo(() => ({
        selectedIds,
        toggleSelection,
        selectAll,
        clearSelection,
        isSelected,
    }), [selectedIds, toggleSelection, selectAll, clearSelection, isSelected]);
    return _jsx(BulkSelectionContext.Provider, { value: value, children: children });
}
export function useBulkSelection() {
    const context = useContext(BulkSelectionContext);
    if (!context) {
        throw new Error('useBulkSelection must be used within a BulkSelectionProvider');
    }
    return context;
}
