"use strict";
/**
 * Liza Checkbox 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.CheckboxFieldStyler = void 0;
/**
 * Styles checkbox, radio, legacyradio and noyes DOM fields
 */
var CheckboxFieldStyler = /** @class */ (function () {
    /**
     * Initialize CheckboxFieldStyler
     *
     * @param name field name
     * @param index field index
     */
    function CheckboxFieldStyler(name, index) {
        this.name = name;
        this.index = index;
    }
    /**
     * Set value of the checkbox, radio, legacyradio or noyes field
     *
     * @param content - field content
     * @param value - value to set
     */
    CheckboxFieldStyler.prototype.setValue = function (content, value) {
        var contentParent = content;
        // SideTableGroupUi allows for a radio to be split across a table row
        // TODO: Remove this logic once SideTableGroupUi is removed
        if (content.parentElement !== null) {
            contentParent = content.parentElement;
        }
        var elements = contentParent.querySelectorAll("[data-field-name=\"" + this.name + "\"]");
        var i = elements.length;
        while (i--) {
            var question = elements[i];
            if (question) {
                question.checked = question.value === value;
            }
        }
    };
    return CheckboxFieldStyler;
}());
exports.CheckboxFieldStyler = CheckboxFieldStyler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2hlY2tib3hGaWVsZFN0eWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIkNoZWNrYm94RmllbGRTdHlsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7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