var ChoiceMutator = /** @class */ (function () {
    function ChoiceMutator() {
    }
    /**
     * Mutates choice elements depending on the concrete container implementation
     * singleChoiceContainer => radioChoice
     * multipleChoiceContainer => checkboxChoice
     *
     * @param elements
     * @param type
     */
    ChoiceMutator.mutate = function (elements, type) {
        ChoiceMutator.leafElements(elements, [])
            .map(function (child) { return ChoiceMutator.mutateType(child, type); });
    };
    /**
     * Mutates the type of a choice element.
     * This is required to differ between radio buttons and checkboxes and should not be considered as
     * a good solution.
     */
    ChoiceMutator.mutateType = function (spec, type) {
        if (spec.type === "choice") {
            spec["type"] = type;
        }
        return spec;
    };
    /**
     * Recursively unpacks all leaf elements from the given {@link ISpecification[]}
     * @param specs
     * @param accumulator
     */
    ChoiceMutator.leafElements = function (specs, accumulator) {
        return specs.reduce(function (acc, val) {
            if (val.elements === undefined || val.type === 'choice') {
                acc.push(val);
                return acc;
            }
            return ChoiceMutator.leafElements(val.elements, acc);
        }, accumulator);
    };
    return ChoiceMutator;
}());
export { ChoiceMutator };
//# sourceMappingURL=ChoiceMutator.js.map