"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useBasicTableCellRenderer = void 0;
var react_1 = require("react");
var ramda_1 = require("ramda");
var tableUtils_1 = require("react-components/dist/Table/tableUtils");
var basicTable_1 = require("../../helpers/basicTable");
var useCollapsibleTableRows_1 = require("../useCollapsibleTableRows");
var useBasicTableCellRenderer = function (_a) {
    var rowsData = _a.rowsData, columnsData = _a.columnsData, getIdFromRowValue = _a.getIdFromRowValue, _b = _a.renderRowCell, renderRowCell = _b === void 0 ? basicTable_1.defaultRenderRowCell : _b, _c = _a.getRowCellHeight, getRowCellHeight = _c === void 0 ? basicTable_1.defaultGetRowCellHeight : _c, _d = _a.defaultRowHeight, defaultRowHeight = _d === void 0 ? 48 : _d, _e = _a.maxRowValuesCount, maxRowValuesCount = _e === void 0 ? Infinity : _e, applyMaxValuesCountConstraint = _a.applyMaxValuesCountConstraint;
    var _f = (0, useCollapsibleTableRows_1.useCollapsibleTableRows)({
        rowsData: rowsData,
        columnsData: columnsData,
        renderRowCell: renderRowCell,
        getRowCellHeight: getRowCellHeight,
        maxRowValuesCount: maxRowValuesCount,
        getIdFromRowValue: getIdFromRowValue,
        applyMaxValuesCountConstraint: applyMaxValuesCountConstraint
    }), tableRowsData = _f.tableRowsData, collapseContextValue = _f.collapseContextValue;
    return (0, react_1.useMemo)(function () {
        var rowHeightCache = tableRowsData.reduce(function (cache, rowData) {
            var data = rowData.data, id = rowData.id;
            cache[id] = (0, tableUtils_1.calculateRowHeight)(data, defaultRowHeight);
            return cache;
        }, {});
        var getHeightForSubRow = function (rowId, columnIndex, subRowIndex) {
            var heightPath = [rowId, 'subRowHeight', columnIndex, subRowIndex, 'height'];
            return (0, ramda_1.pathOr)(0, heightPath, rowHeightCache);
        };
        var getRowHeight = function (rowId) { return (0, ramda_1.pathOr)(0, [rowId, 'height'], rowHeightCache); };
        return { getRowHeight: getRowHeight, collapseContextValue: collapseContextValue, getHeightForSubRow: getHeightForSubRow, tableRowsData: tableRowsData };
    }, [tableRowsData, defaultRowHeight, collapseContextValue]);
};
exports.useBasicTableCellRenderer = useBasicTableCellRenderer;
