"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "OrderView", {
    enumerable: true,
    get: function() {
        return OrderView;
    }
});
const _viewSizeSet = require("./viewSizeSet");
const _viewDiffer = require("./viewDiffer");
const _rendererAdapter = require("./rendererAdapter");
class OrderView {
    /**
   * Sets the size for rendered elements. It can be a size for rows, cells or size for row
   * headers etc. It depends for what table renderer this instance was created.
   *
   * @param {number} size The size.
   * @returns {OrderView}
   */ setSize(size) {
        this.sizeSet.setSize(size);
        return this;
    }
    /**
   * Sets the offset for rendered elements. The offset describes the shift between 0 and
   * the first rendered element according to the scroll position.
   *
   * @param {number} offset The offset.
   * @returns {OrderView}
   */ setOffset(offset) {
        this.sizeSet.setOffset(offset);
        return this;
    }
    /**
   * Checks if this instance of the view shares the root node with another instance. This happens only once when
   * a row (TR) as a root node is managed by two OrderView instances. If this happens another DOM injection
   * algorithm is performed to achieve consistent order.
   *
   * @returns {boolean}
   */ isSharedViewSet() {
        return this.sizeSet.isShared();
    }
    /**
   * Returns rendered DOM element based on visual index.
   *
   * @param {number} visualIndex The visual index.
   * @returns {HTMLElement}
   */ getNode(visualIndex) {
        return visualIndex < this.collectedNodes.length ? this.collectedNodes[visualIndex] : null;
    }
    /**
   * Returns currently processed DOM element.
   *
   * @returns {HTMLElement}
   */ getCurrentNode() {
        const length = this.collectedNodes.length;
        return length > 0 ? this.collectedNodes[length - 1] : null;
    }
    /**
   * Setups and prepares all necessary properties and start the rendering process.
   * This method has to be called only once (at the start) for the render cycle.
   */ start() {
        this.rendererAdapter.start();
    }
    /**
   * Renders the DOM element based on visual index (which is calculated internally).
   * This method has to be called as many times as the size count is met (to cover all previously rendered DOM elements).
   */ render() {
        this.rendererAdapter.render();
    }
    /**
   * Ends the render process.
   * This method has to be called only once (at the end) for the render cycle.
   */ end() {
        this.rendererAdapter.end();
    }
    constructor(rootNode, nodesPool, childNodeType){
        /**
   * Holder for sizing and positioning of the view.
   *
   * @type {ViewSizeSet}
   */ this.sizeSet = new _viewSizeSet.ViewSizeSet();
        /**
   * The list of DOM elements which are rendered for this render cycle.
   *
   * @type {HTMLElement[]}
   */ this.collectedNodes = [];
        /**
   * The differ which calculates the differences between current and next view. It generates
   * commands that are processed by the OrderView (see `applyCommand` method).
   *
   * @type {ViewDiffer}
   */ this.viewDiffer = new _viewDiffer.ViewDiffer(this.sizeSet);
        this.rootNode = rootNode;
        this.nodesPool = nodesPool;
        this.childNodeType = childNodeType;
        this.rendererAdapter = (0, _rendererAdapter.createRendererAdapter)(this);
    }
}
