/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends, __values } from "tslib";
import { Base, runOn, delegateRemove, delegateCombine, fromEnum, markType } from "igniteui-angular-core";
import { IAxisAnnotationManager_$type } from "./IAxisAnnotationManager";
import { LabelPosition } from "./LabelPosition";
/**
 * @hidden
 */
var AxisAnnotationManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(AxisAnnotationManager, _super);
    function AxisAnnotationManager() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._owner = null;
        return _this;
    }
    Object.defineProperty(AxisAnnotationManager.prototype, "owner", {
        get: function () {
            return this._owner;
        },
        set: function (a) {
            this._owner = a;
        },
        enumerable: false,
        configurable: true
    });
    AxisAnnotationManager.prototype.onAddAnnotations = function (a) {
        var b = 0;
        for (var c = 0; c < a.an.count; c++) {
            b = this.a(a, a.an._inner[c], b);
        }
        for (var d = 0; d < a.am.count; d++) {
            b = this.a(a, a.am._inner[d], b);
        }
        a.bo.count = b;
        a.bp.count = b;
    };
    AxisAnnotationManager.prototype.a = function (a, b, c) {
        var d = NaN;
        d = b.value;
        var e = new LabelPosition(a.e3(d));
        if (a.cb) {
            var f = a;
            if (f.categoryMode == 2) {
                var g = a.bh.sf;
                var h = a.kc;
                var i = a.j7();
                e.c += (a.cg ? -f.getCategorySize(g, h, i) * 0.5 : f.getCategorySize(g, h, i) * 0.5);
            }
        }
        var j = e.c;
        if (a.co) {
            if (e.c > a.kc.bottom || e.c < a.kc.top) {
                return c;
            }
        }
        else {
            if (e.c > a.kc.right || e.c < a.kc.left) {
                return c;
            }
        }
        var k = a.bo.item(c);
        var l = a.bp.item(c);
        var m = 100 + c * 2;
        c++;
        l.al = b.resolveLabelValue();
        if (b.textColor != null) {
            l.ao = b.textColor;
        }
        k._fill = b.background;
        k.am = b.backgroundCornerRadius;
        k.an = b.backgroundCornerRadius;
        k._stroke = b.outline;
        k.ac = b.strokeThickness;
        k.s = m;
        l.s = m + 1;
        b.checkForExtentReset(function () { return e.b = true; });
        e.a = true;
        e.d = b.backgroundPadding;
        a.dc.add(e);
        a.db.add1(l.al);
        return c;
    };
    AxisAnnotationManager.prototype.arrangeAnnotations = function (a, b, c, d, e, f, g, h, i, j) {
        for (var k = 0; k < a.bp.count; k++) {
            var l = a.bo.item(k);
            var m = -1;
            for (var n = c.count - 1; n >= 0; n--) {
                if (c._inner[n] == a.bp.item(k)) {
                    m = n;
                    break;
                }
            }
            if (m == -1) {
                continue;
            }
            if (e) {
                b.z(l, a.bp.item(k), a.dc._inner[m], d._inner[m], g, h, i, j);
                b.ar(l, a.bp.item(k), a.dc._inner[m], d._inner[m], g, h, i, j, f);
            }
            else {
                b.z(l, a.bp.item(k), a.dc._inner[m], d._inner[m], g, h, i, j);
                b.ad(l);
            }
        }
    };
    AxisAnnotationManager.prototype.b = function (a, b) {
        this.owner.cp = true;
        this.owner.h6();
    };
    AxisAnnotationManager.prototype.c = function (a) {
        if (a.oldItems != null) {
            for (var b = 0; b < a.oldItems.count; b++) {
                var c = a.oldItems.item(b);
                if (c == null) {
                    continue;
                }
                var d = c;
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
        if (a.newItems != null) {
            for (var e = 0; e < a.newItems.count; e++) {
                var f = a.newItems.item(e);
                if (f == null) {
                    continue;
                }
                var g = f;
                g.propertyChanged = delegateCombine(g.propertyChanged, runOn(this, this.b));
            }
        }
        this.owner.cp = true;
        this.owner.h6();
    };
    AxisAnnotationManager.prototype.onAnnotionsChanged = function (a, b, c) {
        this.c(c);
    };
    AxisAnnotationManager.prototype.onAnnotionsReset = function (a, b, c) {
        var e_1, _a;
        try {
            for (var _b = __values(fromEnum(b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
        catch (e_1_1) {
            e_1 = { error: e_1_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_1)
                    throw e_1.error;
            }
        }
    };
    AxisAnnotationManager.prototype.onAutoAnnotionsChanged = function (a, b, c) {
        this.c(c);
    };
    AxisAnnotationManager.prototype.onAutoAnnotionsReset = function (a, b, c) {
        var e_2, _a;
        try {
            for (var _b = __values(fromEnum(b)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
    };
    AxisAnnotationManager.$t = markType(AxisAnnotationManager, 'AxisAnnotationManager', Base.$, [IAxisAnnotationManager_$type]);
    return AxisAnnotationManager;
}(Base));
export { AxisAnnotationManager };
