/*
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 * as tslib_1 from "tslib";
import { IAxisAnnotationManager_$type } from "./IAxisAnnotationManager";
import { LabelPosition } from "./LabelPosition";
import { Base, runOn, delegateRemove, delegateCombine, fromEnum, markType } from "igniteui-react-core/ES5/type";
var AxisAnnotationManager = /** @class */ (function (_super) {
    tslib_1.__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: true,
        configurable: true
    });
    AxisAnnotationManager.prototype.onAddAnnotations = function (a) {
        var b = 0;
        for (var c = 0; c < a.al.count; c++) {
            b = this.a(a, a.al._inner[c], b);
        }
        for (var d = 0; d < a.ak.count; d++) {
            b = this.a(a, a.ak._inner[d], b);
        }
        a.bm.count = b;
        a.bn.count = b;
    };
    AxisAnnotationManager.prototype.a = function (a, b, c) {
        var d = NaN;
        d = b.value;
        var e = new LabelPosition(a.d8(d));
        var f = e.d;
        if (a.ce) {
            if (e.d > a.it.bottom || e.d < a.it.top) {
                return c;
            }
        }
        else {
            if (e.d > a.it.right || e.d < a.it.left) {
                return c;
            }
        }
        var g = a.bm.item(c);
        var h = a.bn.item(c);
        var i = 100 + c * 2;
        c++;
        h.ak = b.resolveLabelValue();
        if (b.textColor != null) {
            h.am = b.textColor;
        }
        g._fill = b.background;
        g._stroke = b.outline;
        g.ac = b.strokeThickness;
        g.s = i;
        h.s = i + 1;
        b.checkForExtentReset(function () { return e.b = true; });
        e.a = true;
        e.c = b.backgroundPadding;
        a.ct.add(e);
        a.cs.add1(h.ak);
        return c;
    };
    AxisAnnotationManager.prototype.arrangeAnnotations = function (a, b, c, d, e, f, g, h, i, j) {
        for (var k = 0; k < a.bn.count; k++) {
            var l = a.bm.item(k);
            var m = -1;
            for (var n = c.count - 1; n >= 0; n--) {
                if (c._inner[n] == a.bn.item(k)) {
                    m = n;
                    break;
                }
            }
            if (m == -1) {
                continue;
            }
            if (e) {
                b.z(l, a.bn.item(k), a.ct._inner[m], d._inner[m], g, h, i, j);
                b.aq(l, a.bn.item(k), a.ct._inner[m], d._inner[m], g, h, i, j, f);
            }
            else {
                b.z(l, a.bn.item(k), a.ct._inner[m], d._inner[m], g, h, i, j);
            }
        }
    };
    AxisAnnotationManager.prototype.b = function (a, b) {
        this.owner.cf = true;
        this.owner.gy();
    };
    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.cf = true;
        this.owner.gy();
    };
    AxisAnnotationManager.prototype.onAnnotionsChanged = function (a, b, c) {
        this.c(c);
    };
    AxisAnnotationManager.prototype.onAnnotionsReset = function (a, b, c) {
        try {
            for (var _a = tslib_1.__values(fromEnum(b)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var d = _b.value;
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_1) throw e_1.error; }
        }
        var e_1, _c;
    };
    AxisAnnotationManager.prototype.onAutoAnnotionsChanged = function (a, b, c) {
        this.c(c);
    };
    AxisAnnotationManager.prototype.onAutoAnnotionsReset = function (a, b, c) {
        try {
            for (var _a = tslib_1.__values(fromEnum(b)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var d = _b.value;
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_2) throw e_2.error; }
        }
        var e_2, _c;
    };
    AxisAnnotationManager.$t = markType(AxisAnnotationManager, 'AxisAnnotationManager', Base.$, [IAxisAnnotationManager_$type]);
    return AxisAnnotationManager;
}(Base));
export { AxisAnnotationManager };
