/*
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 { AnnotationLayer } from "./AnnotationLayer";
import { Axis } from "./Axis";
import { DependencyProperty } from "igniteui-angular-core";
import { CategoryTooltipLayerPosition_$type } from "./CategoryTooltipLayerPosition";
import { CategoryToolTipLayerFrame } from "./CategoryToolTipLayerFrame";
import { Base, enumGetBox, typeCast, fromEnum, Point_$type, markType, markDep, String_$type } from "igniteui-angular-core";
import { Series } from "./Series";
import { CategoryTooltipSeriesInfo } from "./CategoryTooltipSeriesInfo";
import { XamDataChart } from "./XamDataChart";
import { List$1 } from "igniteui-angular-core";
import { DataContext } from "igniteui-angular-core";
import { Size } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { PointerTooltip } from "./PointerTooltip";
/**
 * @hidden
 */
export class CategoryToolTipLayer extends AnnotationLayer {
    constructor() {
        super();
        let a = new CategoryToolTipLayerFrame();
        let b = new CategoryToolTipLayerFrame();
        let c = new CategoryToolTipLayerFrame();
        this.l2 = a;
        this.l1 = b;
        this.l3 = c;
        this.ab = CategoryToolTipLayer.$;
    }
    bf() {
        return new CategoryToolTipLayerView(this);
    }
    iu(a) {
        super.iu(a);
        this.m6 = a;
    }
    get_cn() {
        return true;
    }
    iz(a, b, c, d) {
        super.iz(a, b, c, d);
        switch (b) {
            case CategoryToolTipLayer.$$p[0]:
                this.jd(true);
                break;
            case CategoryToolTipLayer.$$p[2]:
                this.jd(true);
                break;
            case CategoryToolTipLayer.$$p[1]:
                this.jd(true);
                break;
            case "SeriesViewer":
                this.m6.cc();
                break;
        }
    }
    mk(a, b) {
        if (this.m4 == a) {
            if (!this.aq.c) {
                this.jd(b);
            }
        }
    }
    ml(a, b) {
        if (!this.aq.c) {
            this.jd(b);
        }
    }
    mn(a, b) {
        super.mn(a, b);
        let c = a;
        let d = this.m8;
        c.l = NaN;
        c.k = NaN;
        c.g = NaN;
        c.h = NaN;
        c.k = NaN;
        c.l = NaN;
        if (isNaN_(this.m1.x) && isNaN_(this.m1.y)) {
            this.m6.ca(this.m6.b7());
            return;
        }
        if (this.m4 != null) {
            let e = this.m4;
            if (e == null || !e.b2 || e.b0) {
                return;
            }
            if (!e.ce()) {
                return;
            }
            let f = e;
            let g = this.m7(f.cx, d);
            this.nd(g, c, d);
        }
        else {
            if (typeCast(XamDataChart.$, this.bs) !== null) {
                let h = this.bs;
                let i = true;
                let j = false;
                let k = new List$1(Series.$, 0);
                for (let l of fromEnum(h.axes)) {
                    if (l.b2 && !l.b0) {
                        if (!l.ce()) {
                            continue;
                        }
                        if (i) {
                            i = false;
                            j = l.cf;
                        }
                        else {
                            if (l.cf != j) {
                                continue;
                            }
                        }
                        for (let m of fromEnum(l.cx)) {
                            k.add(m);
                        }
                    }
                }
                let n = this.m7(k, d);
                this.nd(n, c, d);
            }
        }
    }
    m7(a, b) {
        let c = 1.7976931348623157E+308;
        let d = -1.7976931348623157E+308;
        let e = new List$1(DataContext.$, 0);
        let f = new List$1(Base.$, 0);
        let g = false;
        let h = true;
        for (let i = 0; i < a.count; i++) {
            let j = a.item(i);
            if (!j.cr && !j.cl) {
                continue;
            }
            if (j.isStacked) {
                continue;
            }
            let k = j;
            if (!k.categoryAxis.ce()) {
                continue;
            }
            if (h) {
                g = j.isVertical;
            }
            else {
                if (g != j.isVertical) {
                    continue;
                }
            }
            let l = this.mg(j);
            if (!l.c) {
                continue;
            }
            let m = j.ll(l.d, b, false);
            if (g) {
                if (!isNaN_(m.y)) {
                    c = Math.min(c, m.y);
                    d = Math.max(d, m.y);
                }
            }
            else {
                if (!isNaN_(m.x)) {
                    c = Math.min(c, m.x);
                    d = Math.max(d, m.x);
                }
            }
            let n = this.m9(j);
            if (n == null) {
                continue;
            }
            let o = null;
            let p = j.fp(this.m1);
            if (j.co && p != null) {
                o = j.as(p);
            }
            else {
                o = new DataContext();
                o.item = p;
                o.series = j;
            }
            e.add(o);
            f.add1(n);
        }
        let q = 0;
        let r = 0;
        if (g) {
            r = (c + d) / 2;
            q = this.ly.right;
            if (this.m5 == 2 || this.m5 == 1) {
                q = this.ly.left;
            }
            if (r < 0 || r > this.ly.bottom) {
                r = NaN;
            }
        }
        else {
            q = (c + d) / 2;
            r = this.ly.top;
            if (this.m5 == 2 || this.m5 == 1) {
                r = this.ly.bottom;
            }
            if (q < 0 || q > this.ly.right) {
                q = NaN;
            }
        }
        let s = new CategoryTooltipSeriesInfo();
        s.c = { $type: Point_$type, x: q, y: r };
        s.a = e;
        s.b = f;
        return s;
    }
    ia() {
        this.m1 = { $type: Point_$type, x: NaN, y: NaN };
        this.bi.am();
    }
    nd(a, b, c) {
        let d = a.c;
        let e = a.a;
        let f = a.b;
        d = this.m6.cd(d);
        let g = 0;
        let h = this.bi.br;
        let i = this.m6.b7();
        this.m6.b9();
        let j = false;
        if (e.count == 0) {
            this.bi.am();
            return;
        }
        let k = false;
        for (let l = 0; l < e.count; l++) {
            let m = e._inner[l].series;
            j = m.isVertical;
            let n = e._inner[l];
            let o = f._inner[l];
            if (this.m6.b4(m, o, n)) {
                k = true;
            }
            g++;
        }
        if (!k) {
            this.m6.ca(i);
            return;
        }
        let p = this.m6.ce(i);
        let q = 0;
        let r = 0;
        let s = 0;
        let t = 0;
        let u = false;
        let v = false;
        let w = this.m5;
        if (w == 2 || w == 3) {
            v = true;
        }
        if (w == 2 || w == 1) {
            u = true;
        }
        let x = this.m6.cf();
        if (j) {
            if (!u && !v && d.x + (p.width + DeviceUtils.g(10)) > x.width) {
                v = true;
            }
            if (u && !v && d.x - (p.width + DeviceUtils.g(10)) < 0) {
                v = true;
            }
        }
        else {
            if (!u && !v && d.y - (p.height + 10) < 0) {
                v = true;
            }
            if (u && !v && d.y + (p.height + 10) > x.height) {
                v = true;
            }
        }
        let y = DeviceUtils.g(10);
        let z = DeviceUtils.g(5);
        if (!u) {
            if (!j) {
                z = p.height + y;
            }
            if (v) {
                if (j) {
                    z = z + p.width + y;
                }
                else {
                    z = 0;
                }
            }
        }
        else {
            if (j) {
                z = p.width + y;
                if (v) {
                    z = 0;
                }
            }
            else {
                z = DeviceUtils.g(5);
                if (v) {
                    z = z + p.height + y;
                }
            }
        }
        if (j) {
            r = 0 - (y + DeviceUtils.g(5));
            if (u) {
                r = (r * -1) + p.width;
            }
            q = p.height / 2;
            t = d.y - p.height / 2;
            s = d.x - z;
        }
        else {
            q = p.height + DeviceUtils.g(10) + DeviceUtils.g(5);
            if (u) {
                q = 0 - (y + DeviceUtils.g(5));
            }
            r = p.width / 2;
            s = d.x - p.width / 2;
            t = d.y - z;
        }
        if (j) {
            if (t < 0) {
                q -= 0 - t;
                t = 0;
            }
            if (t + p.height > x.height) {
                q += (t + p.height) - x.height;
                t = x.height - p.height;
            }
        }
        else {
            if (s < 0) {
                r -= 0 - s;
                s = 0;
            }
            if (s + p.width > x.width) {
                r += (s + p.width) - x.width;
                s = x.width - p.width;
            }
        }
        b.k = s;
        b.l = t;
        b.g = r;
        b.h = q;
        b.j = p.width;
        b.i = p.height;
    }
    m9(a) {
        return a.toolTip;
    }
    mq(a, b) {
        super.mq(a, b);
        let c = a;
        let d = b.br.left;
        let e = b.br.right;
        let f = b.br.top;
        let g = b.br.bottom;
        let h = this.m6.b7();
        if (isNaN_(c.k) || isNaN_(c.l) || isNaN_(c.g) || isNaN_(c.h)) {
            this.m6.ca(h);
            return;
        }
        let i = c.k;
        let j = c.l;
        let k = c.g;
        let l = c.h;
        this.m6.cb(h, i, j, k, l);
    }
    c8() {
        return true;
    }
}
CategoryToolTipLayer.$t = markType(CategoryToolTipLayer, 'CategoryToolTipLayer', AnnotationLayer.$);
CategoryToolTipLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryToolTipLayer, 'raisePropertyChanged', ['TargetAxis:m4:ne', [Axis.$, null], 'ToolTipPosition:m5:nf', [CategoryTooltipLayerPosition_$type, enumGetBox(CategoryTooltipLayerPosition_$type, 0)], 'UseInterpolation:m8:ng', [0, false]]);
/**
 * @hidden
 */
export class CategoryToolTipLayerView extends AnnotationLayerView {
    constructor(a) {
        super(a);
        this.b1 = null;
        this.b2 = null;
        this._tooltips = null;
        this.b5 = null;
        this.b3 = false;
        this._htmlTest = null;
        this.b1 = a;
        this.htmlTest = /^[^<]*(<[\w\W]+>)[^>]*$/;
    }
    b7() {
        if (this.b2 == null) {
            this.b2 = new PointerTooltip();
            this.b2.bs(this.e.e4);
            this.b2.ao = this.e.bs.bn.j;
            this._tooltips = this.e.e4.createElement("div");
            this.b5 = this.e.e4.createElement("div");
            this.b2._visibility = 0;
        }
        return this.b2;
    }
    ap() {
        super.ap();
        if (this.b2 != null) {
            this.b2._visibility = 1;
        }
    }
    ag() {
        super.ag();
        if (this.b2 != null) {
            this.b2.bo();
            this.b2 = null;
        }
    }
    get htmlTest() {
        return this._htmlTest;
    }
    set htmlTest(a) {
        this._htmlTest = a;
    }
    b4(a, b, c) {
        if (a.fz == "default") {
            a.fz = a.bi.getDefaultTooltipTemplate();
        }
        let template_ = a.fz;
        let context_ = c;
        if (a.toolTip == null) {
            return false;
        }
        let tooltip_ = a.toolTip;
        if ((tooltip_.updateToolTip)) {
            tooltip_._inPointer = true;
            tooltip_.updateToolTip(context_, true);
            tooltip_.setStyleProperty('position', 'relative');
            tooltip_.setStyleProperty('left', '');
            tooltip_.setStyleProperty('top', '');
            tooltip_.remove();
        }
        this._tooltips.append(a.toolTip);
        return true;
    }
    ce(a) {
        let b = a;
        b.content = this._tooltips;
        let c = new Size(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
        b.ct = 1;
        let d = b.cs(new Size(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY));
        b.ct = 0;
        return d;
    }
    cd(a) {
        let b = 0;
        let c = 0;
        if (this.e.bs != null) {
            let d = this.e.bs.mj();
            b += d.x;
            c += d.y;
        }
        return { $type: Point_$type, x: b + a.x, y: c + a.y };
    }
    cb(a, b, c, d, e) {
        let f = a;
        let g = f.content;
        f.cn = { $type: Point_$type, x: d, y: e };
        f._visibility = 0;
        f.n = b;
        f.o = c;
    }
    cf() {
        let a = (window.innerWidth);
        let b = (window.innerHeight);
        return new Size(1, a, b);
    }
    ca(a) {
        this._tooltips.removeChildren();
        this.b5.removeChildren();
        this.b2._visibility = 1;
    }
    b9() {
        if (this._tooltips != null) {
            this._tooltips.removeChildren();
        }
    }
    cc() {
    }
    a3(a, b) {
        super.a3(a, b);
        if (b) {
            return;
        }
        let c = null;
        if (this.e.bs != null) {
            c = this.e.bs.bn.i.i();
        }
        let d = 0;
        let e = 0;
        let f = this.e.bs;
        if (f != null) {
            let g = f.bn.i.b6();
            d += g.x;
            e += g.y;
        }
        if (this.b2 != null) {
            this.b2.ap = c;
            this.b2.bu(this.b2.n, this.b2.o);
        }
    }
    ai(a) {
        super.ai(a);
        let b = this.b2;
        let c = 0;
        let d = 0;
        if (this.e.bs != null) {
            let e = this.e.bs.mj();
            c += e.x;
            d += e.y;
        }
        let f = b.a3();
        let g = b.n - c;
        let h = b.o - d;
        let i = new List$1(String_$type, 0);
        let j = this._tooltips.getChildCount();
        for (let k = 0; k < j; k++) {
            let indexliteral_ = k.toString();
            let l = this._tooltips.getChildAt(k).getText();
            let m = l.toString();
            i.add(m);
        }
        this.e.a2.addPointerTooltipData(a, f, g, h, i);
    }
}
CategoryToolTipLayerView.$t = markType(CategoryToolTipLayerView, 'CategoryToolTipLayerView', AnnotationLayerView.$);
//# sourceMappingURL=CategoryToolTipLayer_combined.js.map