"use strict";
/* TODO auto-generated eslint ignore, please fix! */
/* eslint no-var: "off", @typescript-eslint/no-var-requires: "off" */
/**
 * Liza Default Field Styler
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework
 *
 *  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.DisplayFieldStyler = void 0;
var EventEmitter = require('events').EventEmitter;
/**
 * Styles display/answer fields
 *
 * Currently a passthrough to ElementStyler until
 * the logic to style displays/answers can be moved here
 */
var DisplayFieldStyler = /** @class */ (function (_super) {
    __extends(DisplayFieldStyler, _super);
    /**
     * Initialize DisplayFieldStyler
     *
     * @param element_styler element styler
     * @param name field name
     * @param index field index
     */
    function DisplayFieldStyler(element_styler, name, index) {
        var _this = _super.call(this) || this;
        _this.element_styler = element_styler;
        _this.name = name;
        _this.index = index;
        return _this;
    }
    /**
     * Set value of the display/answer field
     *
     * @param content - field content
     * @param value - value to set
     */
    DisplayFieldStyler.prototype.setValue = function (content, value) {
        var elements = content.querySelectorAll("[data-field-name=\"" + this.name + "\"]");
        var i = elements.length;
        while (i--) {
            var element = elements[i];
            var ref_id = element.getAttribute('data-answer-ref');
            if (ref_id === null) {
                throw TypeError("Display for " + this.name + " is missing an answer ref");
            }
            var display_value = this.element_styler.styleAnswer(ref_id, value);
            var allow_html = element.getAttribute('data-field-allow-html') || '';
            if (allow_html === 'true') {
                element.innerHTML = display_value;
            }
            else {
                element.textContent = display_value;
            }
            this.emit('displayChanged', this.name, this.index, value);
        }
    };
    return DisplayFieldStyler;
}(EventEmitter));
exports.DisplayFieldStyler = DisplayFieldStyler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGlzcGxheUZpZWxkU3R5bGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiRGlzcGxheUZpZWxkU3R5bGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxvREFBb0Q7QUFDcEQscUVBQXFFO0FBQ3JFOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBbUJHOzs7Ozs7Ozs7Ozs7Ozs7O0FBT0gsSUFBTSxZQUFZLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDLFlBQVksQ0FBQztBQUVwRDs7Ozs7R0FLRztBQUNIO0lBQXdDLHNDQUFZO0lBQ2xEOzs7Ozs7T0FNRztJQUNILDRCQUNxQixjQUE2QixFQUM3QixJQUFZLEVBQ1osS0FBc0I7UUFIM0MsWUFLRSxpQkFBTyxTQUNSO1FBTG9CLG9CQUFjLEdBQWQsY0FBYyxDQUFlO1FBQzdCLFVBQUksR0FBSixJQUFJLENBQVE7UUFDWixXQUFLLEdBQUwsS0FBSyxDQUFpQjs7SUFHM0MsQ0FBQztJQUVEOzs7OztPQUtHO0lBQ0gscUNBQVEsR0FBUixVQUFTLE9BQXVCLEVBQUUsS0FBYTtRQUM3QyxJQUFNLFFBQVEsR0FBYSxPQUFPLENBQUMsZ0JBQWdC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