"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.collectTableRowEntries = collectTableRowEntries;
function collectTableRowEntries({ items, getRowId, getRows, isRowExpandable, }) {
    const itemDetailsMap = new Map();
    const childRowIdsById = new Map();
    const rootRowIds = [];
    const traverseRow = (rowData, rowIndex, level, parentRowId) => {
        var _a, _b;
        const rowId = getRowId
            ? getRowId(rowData, rowIndex)
            : getFallbackTableRowId(rowIndex, parentRowId);
        const children = (_b = (((_a = isRowExpandable === null || isRowExpandable === void 0 ? void 0 : isRowExpandable(rowData)) !== null && _a !== void 0 ? _a : true) ? getRows === null || getRows === void 0 ? void 0 : getRows(rowData) : [])) !== null && _b !== void 0 ? _b : [];
        const childRowIds = [];
        for (let childIndex = 0; childIndex < children.length; childIndex++) {
            const childRow = children[childIndex];
            const childRowId = traverseRow(childRow, childIndex, level + 1, rowId);
            childRowIds.push(childRowId);
        }
        itemDetailsMap.set(rowId, {
            id: rowId,
            rowData,
            level,
            parentId: parentRowId,
            children: childRowIds,
        });
        childRowIdsById.set(rowId, childRowIds);
        return rowId;
    };
    for (let rowIndex = 0; rowIndex < items.length; rowIndex++) {
        rootRowIds.push(traverseRow(items[rowIndex], rowIndex, 0, null));
    }
    return {
        itemDetails: itemDetailsMap,
        rootRowIds,
        childRowIdsById,
    };
}
function getFallbackTableRowId(rowIndex, parentRowId) {
    return parentRowId == null ? String(rowIndex) : `${parentRowId}.${rowIndex}`;
}
//# sourceMappingURL=collectTableRowEntries.js.map