"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("../..");
var annotationTypes = [
    core_1.PDFName.Text,
    core_1.PDFName.Link,
    core_1.PDFName.FreeText,
    core_1.PDFName.Line,
    core_1.PDFName.Square,
    core_1.PDFName.Circle,
    core_1.PDFName.Polygon,
    core_1.PDFName.PolyLine,
    core_1.PDFName.Highlight,
    core_1.PDFName.Underline,
    core_1.PDFName.Squiggly,
    core_1.PDFName.StrikeOut,
    core_1.PDFName.Stamp,
    core_1.PDFName.Caret,
    core_1.PDFName.Ink,
    core_1.PDFName.Popup,
    core_1.PDFName.FileAttachment,
    core_1.PDFName.Sound,
    core_1.PDFName.Movie,
    core_1.PDFName.Widget,
    core_1.PDFName.Screen,
    core_1.PDFName.PrinterMark,
    core_1.PDFName.TrapNet,
    core_1.PDFName.Watermark,
    core_1.PDFName.ThreeD,
    core_1.PDFName.Redact,
];
var PDFAnnotation = /** @class */ (function () {
    function PDFAnnotation(dict) {
        this.dict = dict;
        if (!annotationTypes.includes(this.Subtype())) {
            throw new Error('Invalid annotation type');
        }
    }
    PDFAnnotation.fromDict = function (dict) {
        return new PDFAnnotation(dict);
    };
    PDFAnnotation.prototype.Type = function () {
        return this.dict.lookupMaybe(core_1.PDFName.Type, core_1.PDFName);
    };
    PDFAnnotation.prototype.Subtype = function () {
        return this.dict.lookup(core_1.PDFName.Subtype, core_1.PDFName);
    };
    PDFAnnotation.prototype.Rect = function () {
        return this.dict.lookup(core_1.PDFName.Rect, core_1.PDFArray);
    };
    PDFAnnotation.prototype.getRectangle = function () {
        return core_1.PDFRectangle.fromArray(this.Rect());
    };
    PDFAnnotation.prototype.Contents = function () {
        return this.dict.lookupMaybe(core_1.PDFName.Contents, core_1.PDFString);
    };
    PDFAnnotation.prototype.P = function () {
        return this.dict.lookupMaybe(core_1.PDFName.P, core_1.PDFDict);
    };
    PDFAnnotation.prototype.NM = function () {
        return this.dict.lookupMaybe(core_1.PDFName.NM, core_1.PDFString);
    };
    PDFAnnotation.prototype.M = function () {
        return this.dict.lookupMaybe(core_1.PDFName.M, core_1.PDFString);
    };
    PDFAnnotation.prototype.F = function () {
        return this.dict.lookupMaybe(core_1.PDFName.F, core_1.PDFNumber);
    };
    PDFAnnotation.prototype.getFlags = function () {
        var _a;
        return ((_a = this.F()) === null || _a === void 0 ? void 0 : _a.value()) || 0;
    };
    PDFAnnotation.prototype.setFlag = function (flag) {
        var newFlags = this.getFlags() | (1 << flag);
        this.dict.set(core_1.PDFName.F, core_1.PDFNumber.of(newFlags));
    };
    PDFAnnotation.prototype.unsetFlag = function (flag) {
        var newFlags = this.getFlags() & ~(1 << flag);
        this.dict.set(core_1.PDFName.F, core_1.PDFNumber.of(newFlags));
    };
    PDFAnnotation.prototype.toggleFlag = function (flag) {
        var flagValue = this.getFlags() & (1 << flag);
        if (flagValue) {
            this.unsetFlag(flag);
        }
        else {
            this.setFlag(flag);
        }
    };
    PDFAnnotation.prototype.setInvisible = function (invisible) {
        if (Number(this.isInvisible()) ^ Number(invisible)) {
            this.toggleFlag(0);
        }
    };
    PDFAnnotation.prototype.setHidden = function (hidden) {
        if (Number(this.isHidden()) ^ Number(hidden)) {
            this.toggleFlag(1);
        }
    };
    PDFAnnotation.prototype.setPrint = function (print) {
        if (Number(this.shouldPrint()) ^ Number(print)) {
            this.toggleFlag(2);
        }
    };
    PDFAnnotation.prototype.setNoZoom = function (noZoom) {
        if (Number(this.isNoZoom()) ^ Number(noZoom)) {
            this.toggleFlag(3);
        }
    };
    PDFAnnotation.prototype.setNoRotate = function (noRotate) {
        if (Number(this.isNoRotate()) ^ Number(noRotate)) {
            this.toggleFlag(4);
        }
    };
    PDFAnnotation.prototype.setNoView = function (noView) {
        if (Number(this.isNoView()) ^ Number(noView)) {
            this.toggleFlag(5);
        }
    };
    PDFAnnotation.prototype.setReadOnly = function (readOnly) {
        if (Number(this.isReadOnly()) ^ Number(readOnly)) {
            this.toggleFlag(6);
        }
    };
    PDFAnnotation.prototype.setLocked = function (locked) {
        if (Number(this.isLocked()) ^ Number(locked)) {
            this.toggleFlag(7);
        }
    };
    PDFAnnotation.prototype.setToggleNoView = function (toggleNoView) {
        if (Number(this.isToggleNoView()) ^ Number(toggleNoView)) {
            this.toggleFlag(8);
        }
    };
    PDFAnnotation.prototype.setLockedContent = function (lockedContent) {
        if (Number(this.isLockedContent()) ^ Number(lockedContent)) {
            this.toggleFlag(9);
        }
    };
    PDFAnnotation.prototype.isInvisible = function () {
        return !!(this.getFlags() & 1);
    };
    PDFAnnotation.prototype.isHidden = function () {
        return !!(this.getFlags() & (1 << 1));
    };
    PDFAnnotation.prototype.shouldPrint = function () {
        return !!(this.getFlags() & (1 << 2));
    };
    PDFAnnotation.prototype.isNoZoom = function () {
        return !!(this.getFlags() & (1 << 3));
    };
    PDFAnnotation.prototype.isNoRotate = function () {
        return !!(this.getFlags() & (1 << 4));
    };
    PDFAnnotation.prototype.isNoView = function () {
        return !!(this.getFlags() & (1 << 5));
    };
    PDFAnnotation.prototype.isReadOnly = function () {
        return !!(this.getFlags() & (1 << 6));
    };
    PDFAnnotation.prototype.isLocked = function () {
        return !!(this.getFlags() & (1 << 7));
    };
    PDFAnnotation.prototype.isToggleNoView = function () {
        return !!(this.getFlags() & (1 << 8));
    };
    PDFAnnotation.prototype.isLockedContent = function () {
        return !!(this.getFlags() & (1 << 9));
    };
    PDFAnnotation.prototype.AP = function () {
        return this.dict.lookupMaybe(core_1.PDFName.AP, core_1.PDFDict);
    };
    PDFAnnotation.prototype.getAppearance = function () {
        var appearanceDict = this.AP();
        if (!appearanceDict) {
            return appearanceDict;
        }
        return core_1.PDFAnnotationAppearance.fromDict(appearanceDict);
    };
    PDFAnnotation.prototype.AS = function () {
        return this.dict.lookupMaybe(core_1.PDFName.AS, core_1.PDFName);
    };
    PDFAnnotation.prototype.Border = function () {
        return this.dict.lookupMaybe(core_1.PDFName.Border, core_1.PDFArray);
    };
    PDFAnnotation.prototype.C = function () {
        return this.dict.lookupMaybe(core_1.PDFName.C, core_1.PDFArray);
    };
    PDFAnnotation.prototype.StructParent = function () {
        return this.dict.lookupMaybe(core_1.PDFName.StructParent, core_1.PDFNumber);
    };
    PDFAnnotation.prototype.OC = function () {
        return this.dict.lookupMaybe(core_1.PDFName.OC, core_1.PDFDict);
    };
    return PDFAnnotation;
}());
exports.default = PDFAnnotation;
//# sourceMappingURL=PDFAnnotation.js.map