function canSelectTableRow(enableRowSelection, args) {
    if (typeof enableRowSelection === "function") {
        return enableRowSelection(args);
    }
    return enableRowSelection !== null && enableRowSelection !== void 0 ? enableRowSelection : true;
}
/**
 * Traverses the row and its children and updates selected-state directly on given selectedRowIds set.
 * Returns true if any changes were made to the set, false otherwise.
 */
function mutateRowSelection({ selectedRowIds, rowId, checked, childRowIdsById, itemDetails, enableRowSelection, }) {
    let changed = false;
    const item = itemDetails.get(rowId);
    if (item &&
        canSelectTableRow(enableRowSelection, { row: item.rowData, id: rowId })) {
        if (checked && !selectedRowIds.has(rowId)) {
            selectedRowIds.add(rowId);
            changed = true;
        }
        else if (!checked && selectedRowIds.has(rowId)) {
            selectedRowIds.delete(rowId);
            changed = true;
        }
    }
    const children = childRowIdsById.get(rowId);
    if (children) {
        for (const childId of children) {
            if (mutateRowSelection({
                selectedRowIds,
                rowId: childId,
                checked,
                childRowIdsById,
                itemDetails,
                enableRowSelection,
            })) {
                changed = true;
            }
        }
    }
    return changed;
}
export { canSelectTableRow, mutateRowSelection };
//# sourceMappingURL=selection.utils.js.map