"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = require("../../support/node");
var ChoiceMutator_1 = require("./ChoiceMutator");
var InputContainer_1 = require("../../support/InputContainer");
/**
 * Abstract choice container can be either multiple choice or single choice
 *
 * @since 0.23.0
 * @see {@link IRenderable}
 */
var ChoiceContainer = /** @class */ (function () {
    function ChoiceContainer(spec) {
        this.spec = spec;
    }
    ChoiceContainer.prototype.render = function (renderer, isNested) {
        var _this = this;
        var container = node_1.default("div");
        this.spec.class ?
            container.addClasses(ChoiceContainer.CSS_BASE_CLASS, this.cssClassName(), this.spec.class)
            : container.addClasses(ChoiceContainer.CSS_BASE_CLASS, this.cssClassName());
        // add sieve and name as data attribute to maintain the information for the actual submit
        container.addDataAttributes({
            sieve: "" + this.spec.sieve,
            name: "" + this.spec.name,
        });
        InputContainer_1.InputContainer.setRequiredAttribute(container.unwrap(), this.spec.required);
        var children = this.spec.elements || [];
        ChoiceMutator_1.ChoiceMutator.mutate(children, this.mutatedChoiceType());
        children
            .map(function (child) { return renderer.render(child, _this); })
            .map(function (renderedChild) { return ChoiceContainer.unwrap(renderedChild); })
            .filter(function (renderedChild) { return renderedChild !== undefined; })
            .forEach(function (inputElement) { return container.appendChild(node_1.default(inputElement)); });
        container.findAll("input").forEach(function (input) {
            input.setName(_this.spec.name);
        });
        return container.unwrap();
    };
    ChoiceContainer.unwrap = function (e) {
        return (e != null && e.length) ? e[0] : undefined;
    };
    ChoiceContainer.CSS_BASE_CLASS = "lto-choice-container";
    return ChoiceContainer;
}());
exports.ChoiceContainer = ChoiceContainer;
//# sourceMappingURL=ChoiceContainer.js.map