"use strict";
/* TODO auto-generated eslint ignore, please fix! */
/* eslint no-var: "off", no-unused-vars: "off" */
/**
 * Flat UI group with stacked indexes
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of liza.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.StackedGroupUi = void 0;
var GroupUi_1 = require("./GroupUi");
/**
 * Stacks groups of field indexes one atop of another, similar to how groups
 * themselves appear.
 *
 * Does not yet support user adding or removing indexes.
 */
var StackedGroupUi = /** @class */ (function (_super) {
    __extends(StackedGroupUi, _super);
    function StackedGroupUi() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /**
         * Containing group DOM element
         */
        _this._container = null;
        /**
         * Definition list of each stacked item
         */
        _this._dl = null;
        return _this;
    }
    /**
     * Process group before initial display
     *
     * @param quote - active quote
     */
    StackedGroupUi.prototype.processContent = function (_quote) {
        this._container = this.content.querySelector('div.stacked-container');
        this._dl = this._container.querySelector('dl');
        this._dl.parentNode.removeChild(this._dl);
    };
    /**
     * Add index (stacked item)
     *
     * @param index - index that has been added (0-indexed)
     */
    StackedGroupUi.prototype.addIndex = function (index) {
        _super.prototype.addIndex.call(this, index);
        var item = this._dl.cloneNode(true);
        // properly name the elements to prevent id conflicts
        this.setElementIdIndexes(item.getElementsByTagName('*'), index);
        // add the index to the row title
        item.querySelector('span.item-index').textContent = ' ' + (index + 1);
        // Set field content parent for this index
        this.fieldContentParent[index] = item;
        if (this.getDomPerfFlag() === true) {
            this.context.addIndex(index, this.fieldContentParent[index]);
        }
        this._container.appendChild(item);
        // Todo: Transitional step to remove jQuery
        var $item = this.jquery(item);
        this.styler.apply($item);
        this.postAddRow($item, index);
        return this;
    };
    /**
     * Remove index (stacked item)
     *
     * @param index - index that has been removed (0-indexed)
     */
    StackedGroupUi.prototype.removeIndex = function (index) {
        var item = this._container.querySelector('dl:last-child');
        this.styler.remove(this.jquery(item));
        return _super.prototype.removeIndex.call(this, index);
    };
    /**
     * Hide the header if there are no visible fields
     *
     * @param field
     * @param index
     */
    StackedGroupUi.prototype.hideField = function (field, index) {
        _super.prototype.hideField.call(this, field, index);
        if (!this.hasVisibleField(index)) {
            // This possible effects of ignoring these errors has been
            // deemed less severe than the current effects when it fails
            // (i.e. showing all the questions).
            // This will also eventually be changed to have the elements
            // be hidden by default and show when appropriate. This will
            // likely fix the current issue and reduce the chances of
            // something like this happening.
            try {
                var header = this._container.querySelectorAll('dl')[index];
                if (header !== undefined) {
                    header.classList.add('hidden');
                }
            }
            catch (e) {
                console.warn(e);
            }
        }
    };
    /**
     * Show the header if there are visible fields
     *
     * @param field
     * @param index
     */
    StackedGroupUi.prototype.showField = function (field, index) {
        _super.prototype.showField.call(this, field, index);
        if (this.hasVisibleField(index)) {
            var header = this._container.querySelectorAll('dl')[index];
            if (header !== undefined) {
                header.classList.remove('hidden');
            }
        }
    };
    return StackedGroupUi;
}(GroupUi_1.GroupUi));
exports.StackedGroupUi = StackedGroupUi;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJ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