import { __extends } from "tslib";
import { PDFAnnotation, PDFArray, PDFDict, PDFName } from "../..";
import { PDFAcroButton } from './index';
var PDFRadioButton = /** @class */ (function (_super) {
    __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(PDFName.Opt, PDFArray);
    };
    PDFRadioButton.prototype.getOptions = function () {
        var optionsArray = this.Opt();
        return optionsArray ? optionsArray.lookupElements(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(PDFName.Kids, PDFArray);
    };
    PDFRadioButton.prototype.getKids = function () {
        return this.Kids()
            .lookupElements(PDFDict)
            .map(function (childDict) { return PDFAnnotation.fromDict(childDict); });
    };
    PDFRadioButton.prototype.getValue = function () {
        var value = this.dict.lookup(PDFName.V);
        if (!value) {
            return PDFName.Off;
        }
        return this.dict.lookup(PDFName.V, PDFName);
    };
    PDFRadioButton.prototype.toggle = function (index) {
        var canToggle = !this.NoToggleToOff() ||
            (this.NoToggleToOff() && this.getValue() === PDFName.Off);
        if (canToggle) {
            this.toggleChild(index);
        }
    };
    PDFRadioButton.prototype.getChildOnAppearanceState = function (index) {
        var childAnnotation = this.getKids()[index];
        var childAnnotationNormalAppearanceDict = childAnnotation.dict
            .lookup(PDFName.AP, PDFDict)
            .lookup(PDFName.N, PDFDict);
        var childAnnotationNormalOnAppearance = childAnnotationNormalAppearanceDict
            .entries()
            .filter(function (entry) { return entry[0] !== PDFName.Off; })[0][0];
        return childAnnotationNormalOnAppearance;
    };
    PDFRadioButton.prototype.toggleChild = function (index) {
        if (this.getValue() === PDFName.Off) {
            this.setValue(this.getChildOnAppearanceState(index));
        }
        else {
            this.setValue(PDFName.Off);
        }
    };
    return PDFRadioButton;
}(PDFAcroButton));
export default PDFRadioButton;
//# sourceMappingURL=PDFRadioButton.js.map