"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdornerLayer = void 0;
var AdornerLayer = /** @class */ (function () {
    function AdornerLayer(scs) {
        this.parentSurface = scs;
    }
    AdornerLayer.prototype.selectAnnotation = function (args) {
        if (this.isSelectionBypassActive()) {
            return false;
        }
        var scs = this.parentSurface;
        var selectedAnnotation;
        var selectAnnotationHelper = function (annotations) {
            for (var i = annotations.length - 1; i >= 0; i--) {
                var anBase = annotations[i];
                /** Allow all annotations to be clicked.  Only select if editable */
                var isAnnotationSelected = anBase.click(args, !selectedAnnotation && anBase.isEditable);
                if (isAnnotationSelected) {
                    selectedAnnotation = anBase;
                }
            }
        };
        selectAnnotationHelper(scs.annotations.asArray());
        selectAnnotationHelper(scs.modifierAnnotations.asArray());
        this.selectedAnnotationProperty = selectedAnnotation;
        return !!selectedAnnotation;
    };
    AdornerLayer.prototype.deselectAnnotation = function (annotation) {
        if (this.selectedAnnotationProperty === annotation)
            this.selectedAnnotationProperty = undefined;
    };
    Object.defineProperty(AdornerLayer.prototype, "selectedAnnotation", {
        get: function () {
            return this.selectedAnnotationProperty;
        },
        set: function (value) {
            this.selectedAnnotationProperty = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AdornerLayer.prototype, "isAnnotationSelected", {
        get: function () {
            return !!this.selectedAnnotationProperty;
        },
        enumerable: false,
        configurable: true
    });
    // Ugly TS workaround because `MultiPointAnnotationPlacementModifier` and `FreehandDrawingModifier` are in a different npm packages now; 
    // TODO-andrei: cleanup
    AdornerLayer.prototype.isSelectionBypassActive = function () {
        var _a, _b, _c, _d;
        var modifiers = (_d = (_c = (_b = (_a = this.parentSurface) === null || _a === void 0 ? void 0 : _a.chartModifiers) === null || _b === void 0 ? void 0 : _b.asArray) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : [];
        return modifiers.some(function (modifier) { return !!(modifier === null || modifier === void 0 ? void 0 : modifier.isAnnotationInteractionBypassActive); });
    };
    return AdornerLayer;
}());
exports.AdornerLayer = AdornerLayer;
