import { useMemo } from 'react';
import { pathOr } from 'ramda';
import { calculateRowHeight } from 'react-components/dist/Table/tableUtils';
import { defaultRenderRowCell, defaultGetRowCellHeight } from '../../helpers/basicTable';
import { useCollapsibleTableRows } from '../useCollapsibleTableRows';
export var useBasicTableCellRenderer = function (_a) {
    var rowsData = _a.rowsData, columnsData = _a.columnsData, getIdFromRowValue = _a.getIdFromRowValue, _b = _a.renderRowCell, renderRowCell = _b === void 0 ? defaultRenderRowCell : _b, _c = _a.getRowCellHeight, getRowCellHeight = _c === void 0 ? 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 = useCollapsibleTableRows({
        rowsData: rowsData,
        columnsData: columnsData,
        renderRowCell: renderRowCell,
        getRowCellHeight: getRowCellHeight,
        maxRowValuesCount: maxRowValuesCount,
        getIdFromRowValue: getIdFromRowValue,
        applyMaxValuesCountConstraint: applyMaxValuesCountConstraint
    }), tableRowsData = _f.tableRowsData, collapseContextValue = _f.collapseContextValue;
    return useMemo(function () {
        var rowHeightCache = tableRowsData.reduce(function (cache, rowData) {
            var data = rowData.data, id = rowData.id;
            cache[id] = calculateRowHeight(data, defaultRowHeight);
            return cache;
        }, {});
        var getHeightForSubRow = function (rowId, columnIndex, subRowIndex) {
            var heightPath = [rowId, 'subRowHeight', columnIndex, subRowIndex, 'height'];
            return pathOr(0, heightPath, rowHeightCache);
        };
        var getRowHeight = function (rowId) { return pathOr(0, [rowId, 'height'], rowHeightCache); };
        return { getRowHeight: getRowHeight, collapseContextValue: collapseContextValue, getHeightForSubRow: getHeightForSubRow, tableRowsData: tableRowsData };
    }, [tableRowsData, defaultRowHeight, collapseContextValue]);
};
