"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var core_1 = require("../..");
var index_1 = require("./index");
var PDFRadioButton = /** @class */ (function (_super) {
    tslib_1.__extends(PDFRadioButton, _super);
    function PDFRadioButton(dict) {
        return _super.call(this, dict) || this;
    }
    PDFRadioButton.fromDict = function (dict) {
        return new PDFRadioButton(dict);
    };
    PDFRadioButton.prototype.Opt = function () {
        return this.dict.lookupMaybe(core_1.PDFName.Opt, core_1.PDFArray);
    };
    PDFRadioButton.prototype.getOptions = function () {
        var optionsArray = this.Opt();
        return optionsArray ? optionsArray.lookupElements(core_1.PDFName) : [];
    };
    PDFRadioButton.prototype.NoToggleToOff = function () {
        return !!(this.getFlags() & (1 << 14));
    };
    PDFRadioButton.prototype.RadiosInUnison = function () {
        return !!(this.getFlags() & (1 << 25));
    };
    PDFRadioButton.prototype.Kids = function () {
        return this.dict.lookup(core_1.PDFName.Kids, core_1.PDFArray);
    };
    PDFRadioButton.prototype.getKids = function () {
        return this.Kids()
            .lookupElements(core_1.PDFDict)
            .map(function (childDict) { return core_1.PDFAnnotation.fromDict(childDict); });
    };
    PDFRadioButton.prototype.getValue = function () {
        var value = this.dict.lookup(core_1.PDFName.V);
        if (!value) {
            return core_1.PDFName.Off;
        }
        return this.dict.lookup(core_1.PDFName.V, core_1.PDFName);
    };
    PDFRadioButton.prototype.toggle = function (index) {
        var canToggle = !this.NoToggleToOff() ||
            (this.NoToggleToOff() && this.getValue() === core_1.PDFName.Off);
        if (canToggle) {
            this.toggleChild(index);
        }
    };
    PDFRadioButton.prototype.getChildOnAppearanceState = function (index) {
        var childAnnotation = this.getKids()[index];
        var childAnnotationNormalAppearanceDict = childAnnotation.dict
            .lookup(core_1.PDFName.AP, core_1.PDFDict)
            .lookup(core_1.PDFName.N, core_1.PDFDict);
        var childAnnotationNormalOnAppearance = childAnnotationNormalAppearanceDict
            .entries()
            .filter(function (entry) { return entry[0] !== core_1.PDFName.Off; })[0][0];
        return childAnnotationNormalOnAppearance;
    };
    PDFRadioButton.prototype.toggleChild = function (index) {
        if (this.getValue() === core_1.PDFName.Off) {
            this.setValue(this.getChildOnAppearanceState(index));
        }
        else {
            this.setValue(core_1.PDFName.Off);
        }
    };
    return PDFRadioButton;
}(index_1.PDFAcroButton));
exports.default = PDFRadioButton;
//# sourceMappingURL=PDFRadioButton.js.map