/*
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 { Base, runOn, delegateRemove, delegateCombine, fromEnum, markType } from "igniteui-angular-core";
import { IAxisAnnotationManager_$type } from "./IAxisAnnotationManager";
import { DeviceUtils } from "igniteui-angular-core";
import { LabelPosition } from "./LabelPosition";
import { isNaN_ } from "igniteui-angular-core";
/**
 * @hidden
 */
export let AxisAnnotationManager = /*@__PURE__*/ (() => {
    class AxisAnnotationManager extends Base {
        constructor() {
            super(...arguments);
            this._owner = null;
        }
        get owner() {
            return this._owner;
        }
        set owner(a) {
            this._owner = a;
        }
        onAddAnnotations(a) {
            let b = 0;
            for (let c = 0; c < a.as.count; c++) {
                b = this.b(a, a.as._inner[c], b);
            }
            for (let d = 0; d < a.ar.count; d++) {
                b = this.b(a, a.ar._inner[d], b);
            }
            a.b7.count = b;
            a.b8.count = b;
        }
        a(a) {
            if (isNaN_(a) || a < 0) {
                return DeviceUtils.g(3);
            }
            return a;
        }
        b(a, b, c) {
            let d = NaN;
            d = b.value;
            let e = new LabelPosition(a.gg(d));
            if (a.c9) {
                let f = a;
                if (f.categoryMode == 2) {
                    let g = a.b0.xm;
                    let h = a.n1;
                    let i = a.nw();
                    e.c += (a.df ? -f.getCategorySize(g, h, i) * 0.5 : f.getCategorySize(g, h, i) * 0.5);
                }
            }
            let j = e.c;
            if (a.dq) {
                if (e.c > a.n1.bottom || e.c < a.n1.top) {
                    return c;
                }
            }
            else {
                if (e.c > a.n1.right || e.c < a.n1.left) {
                    return c;
                }
            }
            let k = a.b7.item(c);
            let l = a.b8.item(c);
            let m = 100 + c * 2;
            c++;
            l.al = b.resolveLabelValue();
            if (b.textColor != null) {
                l.ao = b.textColor;
            }
            k._fill = b.background;
            k.ap = this.a(b.backgroundCornerRadius);
            k.aq = this.a(b.backgroundCornerRadius);
            k._stroke = b.outline;
            k.ad = b.strokeThickness;
            k.s = m;
            l.s = m + 1;
            b.checkForExtentReset(() => e.b = true);
            e.a = true;
            e.d = b.backgroundPadding;
            a.eg.add(e);
            a.ef.add1(l.al);
            return c;
        }
        arrangeAnnotations(a, b, c, d, e, f, g, h, i, j) {
            for (let k = 0; k < a.b8.count; k++) {
                let l = a.b7.item(k);
                let m = -1;
                for (let n = c.count - 1; n >= 0; n--) {
                    if (c._inner[n] == a.b8.item(k)) {
                        m = n;
                        break;
                    }
                }
                if (m == -1) {
                    continue;
                }
                if (e) {
                    b.z(l, a.b8.item(k), a.eg._inner[m], d._inner[m], g, h, i, j);
                    b.ar(l, a.b8.item(k), a.eg._inner[m], d._inner[m], g, h, i, j, f);
                }
                else {
                    b.z(l, a.b8.item(k), a.eg._inner[m], d._inner[m], g, h, i, j);
                    b.ad(l);
                }
            }
        }
        c(a, b) {
            this.owner.dr = true;
            this.owner.k2();
        }
        d(a) {
            if (a.oldItems != null) {
                for (let b = 0; b < a.oldItems.count; b++) {
                    let c = a.oldItems.item(b);
                    if (c == null) {
                        continue;
                    }
                    let d = c;
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.c));
                }
            }
            if (a.newItems != null) {
                for (let e = 0; e < a.newItems.count; e++) {
                    let f = a.newItems.item(e);
                    if (f == null) {
                        continue;
                    }
                    let g = f;
                    g.propertyChanged = delegateCombine(g.propertyChanged, runOn(this, this.c));
                }
            }
            this.owner.dr = true;
            this.owner.k2();
        }
        onAnnotionsChanged(a, b, c) {
            this.d(c);
        }
        onAnnotionsReset(a, b, c) {
            for (let d of fromEnum(b)) {
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.c));
            }
        }
        onAutoAnnotionsChanged(a, b, c) {
            this.d(c);
        }
        onAutoAnnotionsReset(a, b, c) {
            for (let d of fromEnum(b)) {
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.c));
            }
        }
    }
    AxisAnnotationManager.$t = markType(AxisAnnotationManager, 'AxisAnnotationManager', Base.$, [IAxisAnnotationManager_$type]);
    return AxisAnnotationManager;
})();
