import { PDFAnnotationAppearance, PDFArray, PDFDict, PDFName, PDFNumber, PDFRectangle, PDFString, } from "../..";
var annotationTypes = [
    PDFName.Text,
    PDFName.Link,
    PDFName.FreeText,
    PDFName.Line,
    PDFName.Square,
    PDFName.Circle,
    PDFName.Polygon,
    PDFName.PolyLine,
    PDFName.Highlight,
    PDFName.Underline,
    PDFName.Squiggly,
    PDFName.StrikeOut,
    PDFName.Stamp,
    PDFName.Caret,
    PDFName.Ink,
    PDFName.Popup,
    PDFName.FileAttachment,
    PDFName.Sound,
    PDFName.Movie,
    PDFName.Widget,
    PDFName.Screen,
    PDFName.PrinterMark,
    PDFName.TrapNet,
    PDFName.Watermark,
    PDFName.ThreeD,
    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(PDFName.Type, PDFName);
    };
    PDFAnnotation.prototype.Subtype = function () {
        return this.dict.lookup(PDFName.Subtype, PDFName);
    };
    PDFAnnotation.prototype.Rect = function () {
        return this.dict.lookup(PDFName.Rect, PDFArray);
    };
    PDFAnnotation.prototype.getRectangle = function () {
        return PDFRectangle.fromArray(this.Rect());
    };
    PDFAnnotation.prototype.Contents = function () {
        return this.dict.lookupMaybe(PDFName.Contents, PDFString);
    };
    PDFAnnotation.prototype.P = function () {
        return this.dict.lookupMaybe(PDFName.P, PDFDict);
    };
    PDFAnnotation.prototype.NM = function () {
        return this.dict.lookupMaybe(PDFName.NM, PDFString);
    };
    PDFAnnotation.prototype.M = function () {
        return this.dict.lookupMaybe(PDFName.M, PDFString);
    };
    PDFAnnotation.prototype.F = function () {
        return this.dict.lookupMaybe(PDFName.F, 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(PDFName.F, PDFNumber.of(newFlags));
    };
    PDFAnnotation.prototype.unsetFlag = function (flag) {
        var newFlags = this.getFlags() & ~(1 << flag);
        this.dict.set(PDFName.F, 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(PDFName.AP, PDFDict);
    };
    PDFAnnotation.prototype.getAppearance = function () {
        var appearanceDict = this.AP();
        if (!appearanceDict) {
            return appearanceDict;
        }
        return PDFAnnotationAppearance.fromDict(appearanceDict);
    };
    PDFAnnotation.prototype.AS = function () {
        return this.dict.lookupMaybe(PDFName.AS, PDFName);
    };
    PDFAnnotation.prototype.Border = function () {
        return this.dict.lookupMaybe(PDFName.Border, PDFArray);
    };
    PDFAnnotation.prototype.C = function () {
        return this.dict.lookupMaybe(PDFName.C, PDFArray);
    };
    PDFAnnotation.prototype.StructParent = function () {
        return this.dict.lookupMaybe(PDFName.StructParent, PDFNumber);
    };
    PDFAnnotation.prototype.OC = function () {
        return this.dict.lookupMaybe(PDFName.OC, PDFDict);
    };
    return PDFAnnotation;
}());
export default PDFAnnotation;
//# sourceMappingURL=PDFAnnotation.js.map