"use strict";
/* TODO auto-generated eslint ignore, please fix! */
/* eslint @typescript-eslint/no-inferrable-types: "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/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultFieldStyler = void 0;
/**
 * Styles DOM fields
 */
var DefaultFieldStyler = /** @class */ (function () {
    /**
     * Initialize DefaultFieldStyler
     *
     * @param name field name
     * @param index field index
     */
    function DefaultFieldStyler(name, index) {
        this.name = name;
        this.index = index;
        /**
         * Field element ID prefix
         */
        this._field_id_prefix = 'q_';
    }
    /**
     * Set value of the field
     *
     * @param content - field content
     * @param value - value to set
     */
    DefaultFieldStyler.prototype.setValue = function (content, value) {
        var element = this._getElement(content);
        if (element !== null) {
            element.value = '' + value;
        }
    };
    /**
     * Get field element
     *
     * @param content - field content
     */
    DefaultFieldStyler.prototype._getElement = function (content) {
        var id = this._field_id_prefix + this.name + '_' + this.index;
        var element = content.querySelector('#' + id);
        if (element !== null) {
            return element;
        }
        // In case the element is not found by id, we can query by data-field-name.
        // The index is not needed because the content is at the field level
        return (content.querySelector("[data-field-name=\"" + this.name + "\"]"));
    };
    return DefaultFieldStyler;
}());
exports.DefaultFieldStyler = DefaultFieldStyler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVmYXVsdEZpZWxkU3R5bGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZ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