/*
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 { LabelPosition } from "./LabelPosition";
/**
 * @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.ao.count; c++) {
                b = this.a(a, a.ao._inner[c], b);
            }
            for (let d = 0; d < a.an.count; d++) {
                b = this.a(a, a.an._inner[d], b);
            }
            a.bp.count = b;
            a.bq.count = b;
        }
        a(a, b, c) {
            let d = NaN;
            d = b.value;
            let e = new LabelPosition(a.e6(d));
            if (a.cc) {
                let f = a;
                if (f.categoryMode == 2) {
                    let g = a.bi.v4;
                    let h = a.kh;
                    let i = a.kc();
                    e.c += (a.ch ? -f.getCategorySize(g, h, i) * 0.5 : f.getCategorySize(g, h, i) * 0.5);
                }
            }
            let j = e.c;
            if (a.cp) {
                if (e.c > a.kh.bottom || e.c < a.kh.top) {
                    return c;
                }
            }
            else {
                if (e.c > a.kh.right || e.c < a.kh.left) {
                    return c;
                }
            }
            let k = a.bp.item(c);
            let l = a.bq.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 = b.backgroundCornerRadius;
            k.aq = 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.de.add(e);
            a.dd.add1(l.al);
            return c;
        }
        arrangeAnnotations(a, b, c, d, e, f, g, h, i, j) {
            for (let k = 0; k < a.bq.count; k++) {
                let l = a.bp.item(k);
                let m = -1;
                for (let n = c.count - 1; n >= 0; n--) {
                    if (c._inner[n] == a.bq.item(k)) {
                        m = n;
                        break;
                    }
                }
                if (m == -1) {
                    continue;
                }
                if (e) {
                    b.z(l, a.bq.item(k), a.de._inner[m], d._inner[m], g, h, i, j);
                    b.ar(l, a.bq.item(k), a.de._inner[m], d._inner[m], g, h, i, j, f);
                }
                else {
                    b.z(l, a.bq.item(k), a.de._inner[m], d._inner[m], g, h, i, j);
                    b.ad(l);
                }
            }
        }
        b(a, b) {
            this.owner.cq = true;
            this.owner.ia();
        }
        c(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.b));
                }
            }
            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.b));
                }
            }
            this.owner.cq = true;
            this.owner.ia();
        }
        onAnnotionsChanged(a, b, c) {
            this.c(c);
        }
        onAnnotionsReset(a, b, c) {
            for (let d of fromEnum(b)) {
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
        onAutoAnnotionsChanged(a, b, c) {
            this.c(c);
        }
        onAutoAnnotionsReset(a, b, c) {
            for (let d of fromEnum(b)) {
                d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.b));
            }
        }
    }
    AxisAnnotationManager.$t = markType(AxisAnnotationManager, 'AxisAnnotationManager', Base.$, [IAxisAnnotationManager_$type]);
    return AxisAnnotationManager;
})();
