"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "RowsRenderer", {
    enumerable: true,
    get: function() {
        return RowsRenderer;
    }
});
const _base = require("./_base");
const _console = require("../../../../helpers/console");
const _templateLiteralTag = require("../../../../helpers/templateLiteralTag");
const _orderView = require("../utils/orderView");
const _element = require("../../../../helpers/dom/element");
const _a11y = require("../../../../helpers/a11y");
const ROW_CLASSNAMES = {
    rowEven: 'ht__row_even',
    rowOdd: 'ht__row_odd'
};
let performanceWarningAppeared = false;
class RowsRenderer extends _base.BaseRenderer {
    /**
   * Returns currently rendered node.
   *
   * @param {string} visualIndex Visual index of the rendered node (it always goeas from 0 to N).
   * @returns {HTMLTableRowElement}
   */ getRenderedNode(visualIndex) {
        return this.orderView.getNode(visualIndex);
    }
    /**
   * Renders the cells.
   */ render() {
        const { rowsToRender } = this.table;
        if (!performanceWarningAppeared && rowsToRender > 1000) {
            performanceWarningAppeared = true;
            (0, _console.warn)((0, _templateLiteralTag.toSingleLine)`Performance tip: Handsontable rendered more than 1000 visible rows.\x20
        Consider limiting the number of rendered rows by specifying the table height and/or\x20
        turning off the "renderAllRows" option.`);
        }
        if (this.table.isAriaEnabled()) {
            (0, _element.setAttribute)(this.rootNode, [
                (0, _a11y.A11Y_ROWGROUP)()
            ]);
        }
        this.orderView.setSize(rowsToRender).setOffset(this.table.renderedRowToSource(0)).start();
        for(let visibleRowIndex = 0; visibleRowIndex < rowsToRender; visibleRowIndex++){
            this.orderView.render();
            const TR = this.orderView.getCurrentNode();
            const sourceRowIndex = this.table.renderedRowToSource(visibleRowIndex);
            if (this.table.isAriaEnabled()) {
                (0, _element.setAttribute)(TR, [
                    (0, _a11y.A11Y_ROW)(),
                    // `aria-rowindex` is incremented by both tbody and thead rows.
                    (0, _a11y.A11Y_ROWINDEX)(sourceRowIndex + (this.table.rowUtils?.dataAccessObject?.columnHeaders.length ?? 0) + 1)
                ]);
            }
            if ((sourceRowIndex + 1) % 2 === 0) {
                if (!(0, _element.hasClass)(TR, ROW_CLASSNAMES.rowEven)) {
                    (0, _element.removeClass)(TR, ROW_CLASSNAMES.rowOdd);
                    (0, _element.addClass)(TR, ROW_CLASSNAMES.rowEven);
                }
            } else if (!(0, _element.hasClass)(TR, ROW_CLASSNAMES.rowOdd)) {
                (0, _element.removeClass)(TR, ROW_CLASSNAMES.rowEven);
                (0, _element.addClass)(TR, ROW_CLASSNAMES.rowOdd);
            }
        }
        this.orderView.end();
    }
    constructor(rootNode){
        super('TR', rootNode);
        this.orderView = new _orderView.OrderView(rootNode, (sourceRowIndex)=>this.nodesPool.obtain(sourceRowIndex), this.nodeType);
    }
}
