"use client";
import { useCallback, useState } from "react";
/**
 * @remarks \@since 6.0.0 Renamed from `useTreeItemSelection` and uses a Set
 * instead of a list to increase performance.
 */ export function useTreeSelection(defaultSelectedIds, multiSelect = false) {
    const [selectedIds, setSelectedIds] = useState(()=>{
        const defaultIds = typeof defaultSelectedIds === "function" ? defaultSelectedIds() : defaultSelectedIds;
        return new Set(defaultIds);
    });
    const toggleTreeItemSelection = useCallback((itemId)=>{
        setSelectedIds((selectedIds)=>{
            if (!multiSelect) {
                return selectedIds.has(itemId) ? selectedIds : new Set([
                    itemId
                ]);
            }
            const nextSelectedIds = new Set(selectedIds);
            if (selectedIds.has(itemId)) {
                nextSelectedIds.delete(itemId);
            } else {
                nextSelectedIds.add(itemId);
            }
            return nextSelectedIds;
        });
    }, [
        multiSelect
    ]);
    return {
        selectedIds,
        multiSelect,
        toggleTreeItemSelection,
        selectMultipleTreeItems: setSelectedIds
    };
}

//# sourceMappingURL=useTreeSelection.js.map