/*
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 { ContentControl } from "igniteui-react-core/ES2015/ContentControl";
import { INotifyPropertyChanged_$type, Type, PropertyChangedEventArgs, Base, delegateCombine, Point_$type, enumGetBox, markType } from "igniteui-react-core/ES2015/type";
import { SRProvider } from "igniteui-react-core/ES2015/SRProvider";
import { ISeriesVisualDataManager_$type } from "./ISeriesVisualDataManager";
import { DVContainer } from "igniteui-react-core/ES2015/DVContainer";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { Visibility_$type } from "igniteui-react-core/ES2015/Visibility";
import { PointerTooltipPointerLocation_$type } from "./PointerTooltipPointerLocation";
import { PointCollection } from "igniteui-react-core/ES2015/PointCollection";
import { Polygon } from "igniteui-react-core/ES2015/Polygon";
import { Polyline } from "igniteui-react-core/ES2015/Polyline";
import { PropertyUpdatedEventArgs } from "igniteui-react-core/ES2015/PropertyUpdatedEventArgs";
import { Size } from "igniteui-react-core/ES2015/Size";
import { DeviceUtils } from "igniteui-react-core/ES2015/DeviceUtils";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { RenderingContext } from "igniteui-react-core/ES2015/RenderingContext";
import { Rectangle } from "igniteui-react-core/ES2015/Rectangle";
import { CanvasViewRenderer } from "igniteui-react-core/ES2015/CanvasViewRenderer";
import { Brush } from "igniteui-react-core/ES2015/Brush";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { truncate, isNaN_ } from "igniteui-react-core/ES2015/number";
export class PointerTooltip extends ContentControl {
    constructor() {
        super();
        this.aq = null;
        this.ai = null;
        this.am = null;
        this.propertyChanged = null;
        this.propertyUpdated = null;
        this.bw = null;
        this.cq = null;
        this.cr = null;
        this.au = false;
        this.cf = { $type: Point_$type, x: NaN, y: NaN };
        this.ak = 0;
        this.aw = 0;
        this.av = 0;
        this.ao = null;
        this.as = false;
        this.ap = null;
        DVContainer.instance.registerIfLoaded("VisualDataFactoryManager");
        this.ab = PointerTooltip.$;
        this.propertyUpdated = delegateCombine(this.propertyUpdated, (a, b) => this.br(a, b.propertyName, b.oldValue, b.newValue));
        this.am = new PointerTooltipView(this);
    }
    get ar() {
        if (this.aq == null) {
            this.aq = new SRProvider(this.am.k);
        }
        return this.aq;
    }
    get aj() {
        if (this.ai == null) {
            this.ai = DVContainer.instance.createInstance(ISeriesVisualDataManager_$type, () => this.ar.q);
        }
        return this.ai;
    }
    bt(a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        if (this.propertyUpdated != null) {
            this.propertyUpdated(this, new PropertyUpdatedEventArgs(a, b, c));
        }
    }
    br(a, b, c, d) {
        switch (b) {
            case PointerTooltip.$$p[15]:
                this.bq();
                break;
            case PointerTooltip.$$p[16]:
                this.bq();
                break;
        }
    }
    bn() {
        if (this.am.d(this.content)) {
            this.bq();
        }
    }
    bq() {
        this.au = true;
    }
    at(a, b) {
        if (Math.abs(a - b) < 1E-05) {
            return true;
        }
        return false;
    }
    cs(a) {
        this.au = false;
        let b = 0;
        let c = 0;
        let d = this.am.y(a);
        b = d.width;
        c = d.height;
        if (this.ak == this.al && this.at(this.cf.x, this.cn.x) && this.at(this.cf.y, this.cn.y)) {
            this.a0 = b;
            this.az = c;
            if (this.ct == 0) {
                b += this.aw;
                c += this.av;
                this.ay = this.a0 + this.aw;
                this.ax = this.az + this.av;
            }
            return new Size(1, b, c);
        }
        let e = { $type: Point_$type, x: 0, y: 0 };
        let f = { $type: Point_$type, x: b * 0.5, y: 0 };
        let g = { $type: Point_$type, x: b, y: 0 };
        let h = { $type: Point_$type, x: b, y: c };
        let i = { $type: Point_$type, x: b * 0.5, y: c };
        let j = { $type: Point_$type, x: 0, y: c };
        let k = { $type: Point_$type, x: 0, y: c * 0.5 };
        let l = { $type: Point_$type, x: b, y: c * 0.5 };
        let m = b;
        let n = c;
        let o = b;
        let p = c;
        let q = { $type: Point_$type, x: 0, y: 0 };
        let r = { $type: Point_$type, x: 0, y: 0 };
        let s = { $type: Point_$type, x: 0, y: 0 };
        let t = { $type: Point_$type, x: 0, y: 0 };
        let u = this.a1;
        let v = this.a2;
        let w = this.al;
        let x = this.cn;
        let y = 0;
        let z = 0;
        let aa = Math.pow(e.x - x.x, 2) + Math.pow(e.y - x.y, 2);
        let ab = Math.pow(f.x - x.x, 2) + Math.pow(f.y - x.y, 2);
        let ac = Math.pow(g.x - x.x, 2) + Math.pow(g.y - x.y, 2);
        let ad = Math.pow(l.x - x.x, 2) + Math.pow(l.y - x.y, 2);
        let ae = Math.pow(h.x - x.x, 2) + Math.pow(h.y - x.y, 2);
        let af = Math.pow(i.x - x.x, 2) + Math.pow(i.y - x.y, 2);
        let ag = Math.pow(j.x - x.x, 2) + Math.pow(j.y - x.y, 2);
        let ah = Math.pow(k.x - x.x, 2) + Math.pow(k.y - x.y, 2);
        let ai = 1.7976931348623157E+308;
        ai = Math.min(ai, aa);
        ai = Math.min(ai, ab);
        ai = Math.min(ai, ac);
        ai = Math.min(ai, ad);
        ai = Math.min(ai, ae);
        ai = Math.min(ai, af);
        ai = Math.min(ai, ag);
        ai = Math.min(ai, ah);
        if (w == 0) {
            if (ai == aa) {
                w = 12;
                if (x.x >= e.x) {
                    w = 1;
                }
            }
            if (ai == ah) {
                w = 11;
            }
            if (ai == ag) {
                w = 10;
                if (x.x >= j.x) {
                    w = 9;
                }
            }
            if (ai == ac) {
                w = 4;
                if (x.x <= g.x) {
                    w = 3;
                }
            }
            if (ai == ad) {
                w = 5;
            }
            if (ai == ae) {
                w = 6;
                if (x.x <= h.x) {
                    w = 7;
                }
            }
            if (ai == ab) {
                w = 2;
            }
            if (ai == af) {
                w = 8;
            }
        }
        let aj = DeviceUtils.g(3);
        switch (w) {
            case 1:
                q = { $type: Point_$type, x: e.x + u, y: e.y };
                r = { $type: Point_$type, x: e.x + u + v, y: e.y };
                s = { $type: Point_$type, x: e.x + u, y: e.y + aj };
                t = { $type: Point_$type, x: e.x + u + v, y: e.y + aj };
                break;
            case 2:
                q = { $type: Point_$type, x: ((e.x + g.x) / 2) - (v / 2), y: e.y };
                r = { $type: Point_$type, x: ((e.x + g.x) / 2) + (v / 2), y: e.y };
                s = { $type: Point_$type, x: ((e.x + g.x) / 2) - (v / 2), y: e.y + aj };
                t = { $type: Point_$type, x: ((e.x + g.x) / 2) + (v / 2), y: e.y + aj };
                break;
            case 3:
                q = { $type: Point_$type, x: g.x - u, y: e.y };
                r = { $type: Point_$type, x: (g.x - u) - v, y: e.y };
                s = { $type: Point_$type, x: g.x - u, y: e.y + aj };
                t = { $type: Point_$type, x: (g.x - u) - v, y: e.y + aj };
                break;
            case 4:
                q = { $type: Point_$type, x: g.x, y: g.y + u };
                r = { $type: Point_$type, x: g.x, y: g.y + u + v };
                s = { $type: Point_$type, x: g.x - aj, y: g.y + u };
                t = { $type: Point_$type, x: g.x - aj, y: g.y + u + v };
                break;
            case 5:
                q = { $type: Point_$type, x: g.x, y: ((g.y + h.y) / 2) - (v / 2) };
                r = { $type: Point_$type, x: g.x, y: ((g.y + h.y) / 2) + (v / 2) };
                s = { $type: Point_$type, x: g.x - aj, y: ((g.y + h.y) / 2) - (v / 2) };
                t = { $type: Point_$type, x: g.x - aj, y: ((g.y + h.y) / 2) + (v / 2) };
                break;
            case 6:
                q = { $type: Point_$type, x: h.x, y: h.y - u };
                r = { $type: Point_$type, x: h.x, y: h.y - u - v };
                s = { $type: Point_$type, x: h.x - aj, y: h.y - u };
                t = { $type: Point_$type, x: h.x - aj, y: h.y - u - v };
                break;
            case 7:
                q = { $type: Point_$type, x: h.x - u, y: h.y };
                r = { $type: Point_$type, x: (h.x - u) - v, y: h.y };
                s = { $type: Point_$type, x: h.x - u, y: h.y - aj };
                t = { $type: Point_$type, x: (h.x - u) - v, y: h.y - aj };
                break;
            case 8:
                q = { $type: Point_$type, x: ((j.x + h.x) / 2) - (v / 2), y: h.y };
                r = { $type: Point_$type, x: ((j.x + h.x) / 2) + (v / 2), y: h.y };
                s = { $type: Point_$type, x: ((j.x + h.x) / 2) - (v / 2), y: h.y - aj };
                t = { $type: Point_$type, x: ((j.x + h.x) / 2) + (v / 2), y: h.y - aj };
                break;
            case 9:
                q = { $type: Point_$type, x: j.x + u, y: j.y };
                r = { $type: Point_$type, x: j.x + u + v, y: j.y };
                s = { $type: Point_$type, x: j.x + u, y: j.y - aj };
                t = { $type: Point_$type, x: j.x + u + v, y: j.y - aj };
                break;
            case 10:
                q = { $type: Point_$type, x: e.x, y: j.y - u };
                r = { $type: Point_$type, x: e.x, y: (j.y - u) - v };
                s = { $type: Point_$type, x: e.x + aj, y: j.y - u };
                t = { $type: Point_$type, x: e.x + aj, y: (j.y - u) - v };
                break;
            case 11:
                q = { $type: Point_$type, x: e.x, y: ((e.y + j.y) / 2) - (v / 2) };
                r = { $type: Point_$type, x: e.x, y: ((e.y + j.y) / 2) + (v / 2) };
                s = { $type: Point_$type, x: e.x + aj, y: ((e.y + j.y) / 2) - (v / 2) };
                t = { $type: Point_$type, x: e.x + aj, y: ((e.y + j.y) / 2) + (v / 2) };
                break;
            case 12:
                q = { $type: Point_$type, x: e.x, y: e.y + u };
                r = { $type: Point_$type, x: e.x, y: e.y + u + v };
                s = { $type: Point_$type, x: e.x + aj, y: e.y + u };
                t = { $type: Point_$type, x: e.x + aj, y: e.y + u + v };
                break;
        }
        let ak = { $type: Point_$type, x: x.x, y: x.y };
        if (ak.y < e.y) {
            let al = e.y - ak.y;
            ak = { $type: Point_$type, x: ak.x, y: 0 };
            p += al;
            e = { $type: Point_$type, x: e.x, y: e.y + al };
            g = { $type: Point_$type, x: g.x, y: g.y + al };
            j = { $type: Point_$type, x: j.x, y: j.y + al };
            h = { $type: Point_$type, x: h.x, y: h.y + al };
            q = { $type: Point_$type, x: q.x, y: q.y + al };
            r = { $type: Point_$type, x: r.x, y: r.y + al };
            s = { $type: Point_$type, x: s.x, y: s.y + al };
            t = { $type: Point_$type, x: t.x, y: t.y + al };
        }
        else {
            p = Math.max(ak.y, n);
        }
        if (ak.x < e.x) {
            let am = e.x - ak.x;
            ak = { $type: Point_$type, x: 0, y: ak.y };
            o += am;
            e = { $type: Point_$type, x: e.x + am, y: e.y };
            g = { $type: Point_$type, x: g.x + am, y: g.y };
            j = { $type: Point_$type, x: j.x + am, y: j.y };
            h = { $type: Point_$type, x: h.x + am, y: h.y };
            q = { $type: Point_$type, x: q.x + am, y: q.y };
            r = { $type: Point_$type, x: r.x + am, y: r.y };
            s = { $type: Point_$type, x: s.x + am, y: s.y };
            t = { $type: Point_$type, x: t.x + am, y: t.y };
        }
        else {
            o = Math.max(ak.x, m);
        }
        y = o - m;
        z = p - n;
        this.aw = y;
        this.av = z;
        this.ak = this.al;
        this.cf = this.cn;
        this.cm = ak;
        this.ck = q;
        this.cl = r;
        this.a0 = m;
        this.az = n;
        this.ay = o;
        this.ax = p;
        this.ci = e;
        this.cj = g;
        this.ch = h;
        this.cg = j;
        let an = new PointCollection(0);
        an.add(t);
        an.add(this.cl);
        an.add(this.cm);
        an.add(this.ck);
        an.add(s);
        this.cp = an;
        if (this.cq != null) {
            this.cq.aj = an;
        }
        let ao = new PointCollection(0);
        ao.add(this.cl);
        ao.add(this.cm);
        ao.add(this.ck);
        this.co = ao;
        if (this.cr != null) {
            this.cr.aj = ao;
        }
        if (this.ct == 1) {
            return new Size(1, b, c);
        }
        return new Size(1, o, p);
    }
    bo() {
        this.bv();
        this.am.s();
    }
    bp() {
        this._visibility = 1;
        this.am.t();
    }
    bu(a, b) {
        if (this.au) {
            this.cs(new Size(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY));
        }
        this.am.w(a, b);
    }
    bs(a) {
        this.am.v(a);
    }
    bm() {
        if (!this.as) {
            if (this.ao != null && this.am.m != null) {
                this.as = true;
                this.ao.am(this.am.m, "pointerTooltip" + Base.getHashCodeStatic(this));
            }
        }
    }
    bv() {
        if (this.as) {
            if (this.ao != null && this.am.m != null) {
                this.as = false;
                this.ao.a8(this.am.m, "pointerTooltip" + Base.getHashCodeStatic(this));
            }
            this.ao = null;
        }
    }
    a3() {
        return this.am.r();
    }
}
PointerTooltip.$t = markType(PointerTooltip, 'PointerTooltip', ContentControl.$, [INotifyPropertyChanged_$type]);
Type.dep(DependencyProperty, PropertyMetadata, PointerTooltip, 'bt', ['ActualBoxBottomLeftPosition:cg:bx', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ActualBoxBottomRightPosition:ch:by', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ActualBoxFullHeight:ax:bz', [1, 0], 'ActualBoxFullWidth:ay:b0', [1, 0], 'ActualBoxHeight:az:b1', [1, 0], 'ActualBoxTopLeftPosition:ci:b2', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ActualBoxTopRightPosition:cj:b3', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ActualBoxWidth:a0:b4', [1, 0], 'ActualPointerFirstPosition:ck:b5', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ActualPointerSecondPosition:cl:b6', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'ActualPointerStartPosition:cm:b7', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'PointerInset:a1:b8', [1, DeviceUtils.g(7.5)], 'PointerLocation:al:b9', [PointerTooltipPointerLocation_$type, enumGetBox(PointerTooltipPointerLocation_$type, 0)], 'PointerOutlinePoints:co:ca', [PointCollection.$, null], 'PointerPoints:cp:cb', [PointCollection.$, null], 'PointerPosition:cn:cc', [Point_$type, { $type: Point_$type, x: 0, y: 0 }], 'PointerVisibility:ct:cd', [Visibility_$type, enumGetBox(Visibility_$type, 0)], 'PointerWidth:a2:ce', [1, DeviceUtils.g(5)]]);
export class PointerTooltipView extends Base {
    constructor(a) {
        super();
        this.j = null;
        this.a = null;
        this.o = null;
        this.q = null;
        this.p = null;
        this.m = null;
        this.l = null;
        this.b = null;
        this.n = null;
        this.x = null;
        this.c = false;
        this.i = 0;
        this.h = 0;
        this.g = -1;
        this.e = -1;
        this.f = 1;
        this.k = null;
        this.a = a;
        this.a.cq = new Polygon();
        this.a.cr = new Polyline();
        this.m = null;
        this.u();
    }
    u() {
        if (this.j == null) {
            this.j = (a) => {
                if (window.devicePixelRatio != undefined && window.devicePixelRatio != this.f) {
                    this.f = window.devicePixelRatio;
                    if (this.m != null) {
                        this.m.hide();
                    }
                }
            };
            window.addEventListener("resize", this.j, false);
        }
        this.j(null);
    }
    y(a) {
        let b = this.a.content;
        b = b.clone();
        let c = new Size(1, 0, 0);
        if (this.o == null) {
            this.o = this.k.createElement("div");
            this.o.addClass("ui-chart-pointer-tooltip-container");
            this.o.setStyleProperty("position", "absolute");
            this.o.setStyleProperty("visibility", "hidden");
            this.o.setStyleProperty("top", "0px");
            this.o.setStyleProperty("left", "0px");
            this.q = this.k.createElement("div");
            this.q.setStyleProperty("position", "relative");
            this.p = this.k.createElement("div");
            this.p.addClass("ui-chart-pointer-tooltip-content-container");
            this.p.setStyleProperty("position", "absolute");
            this.p.setStyleProperty("top", "0px");
            this.p.setStyleProperty("left", "0px");
            this.o.append(this.q);
            this.q.append(this.p);
        }
        this.o.remove();
        this.k.appendToBody(this.o);
        this.p.append(b);
        c = new Size(1, this.p.outerWidthWithMargin(), this.p.outerHeightWithMargin());
        this.o.remove();
        b.remove();
        return c;
    }
    w(a, b) {
        if (this.m == null) {
            this.m = this.k.createElement("div");
            this.m.addClass("ui-chart-pointer-tooltip-container");
            this.m.setStyleProperty("position", "absolute");
            this.m.setStyleProperty("top", "0px");
            this.m.setStyleProperty("left", "0px");
            let c = this.k.createElement("div");
            c.setStyleProperty("position", "relative");
            this.l = this.k.createElement("canvas");
            this.l.setStyleProperty("position", "absolute");
            this.l.setStyleProperty("top", "0px");
            this.l.setStyleProperty("left", "0px");
            this.n = this.k.createElement("div");
            this.n.addClass("ui-chart-pointer-tooltip-content-container");
            this.n.setStyleProperty("position", "absolute");
            this.n.setStyleProperty("top", "0px");
            this.n.setStyleProperty("left", "0px");
            c.append(this.l);
            c.append(this.n);
            this.m.append(c);
            this.b = new RenderingContext(new CanvasViewRenderer(), this.k.get2DCanvasContext(this.l));
            this.m.hide();
            this.k.appendToBody(this.m);
        }
        this.a.bm();
        if (this.a._visibility == 1 && this.c) {
            this.m.hide();
            this.c = false;
            return;
        }
        let d = null;
        if (this.a.content != null) {
            d = this.a.content;
            d.remove();
        }
        this.n.removeChildren();
        if (d != null) {
            let cont_ = this.n;
            let xPos_ = this.a.ci.x.toString() + "px";
            let yPos_ = this.a.ci.y.toString() + "px";
            cont_.setRawStyleProperty("left", xPos_);
            cont_.setRawStyleProperty("top", yPos_);
            this.n.append(d);
        }
        let e = this.a.ap;
        let f = 1;
        if (e != null) {
            f = !isNaN_(e.b) ? e.b : 1;
        }
        let g = truncate(Math.ceil(this.a.ay + (f * 2)));
        let h = truncate(Math.ceil(this.a.ax + (f * 2)));
        if (g != this.i || h != this.h) {
            this.l.setStyleProperty("width", g.toString() + "px");
            this.l.setStyleProperty("height", h.toString() + "px");
            this.l.setAttribute("width", (g * this.f).toString());
            this.l.setAttribute("height", (h * this.f).toString());
            this.i = g;
            this.h = h;
        }
        if (this.b.d && this.f != 1) {
            this.b.z();
            this.b.aa(this.f, this.f);
        }
        this.b.k(0, 0, this.i, this.h);
        let i = new Rectangle();
        i.width = this.a.a0;
        i.height = this.a.az;
        i.n = this.a.ci.x;
        i.o = this.a.ci.y;
        if (e != null) {
            i._fill = e.c != null ? e.c : ((() => {
                let $ret = new Brush();
                $ret.fill = "white";
                return $ret;
            })());
            i._stroke = e.d != null ? e.d : ((() => {
                let $ret = new Brush();
                $ret.fill = "black";
                return $ret;
            })());
            i.ac = !isNaN_(e.b) ? e.b : 1;
            i.al = !isNaN_(e.a) ? e.a : 0;
            i.am = !isNaN_(e.a) ? e.a : 0;
        }
        else {
            i._fill = ((() => {
                let $ret = new Brush();
                $ret.fill = "white";
                return $ret;
            })());
            i._stroke = ((() => {
                let $ret = new Brush();
                $ret.fill = "black";
                return $ret;
            })());
            i.ac = 1;
        }
        this.x = i;
        let j = this.a.cq;
        let k = this.a.cr;
        j._fill = i._fill;
        k._stroke = i._stroke;
        this.b.v(i);
        this.b.t(j);
        this.b.u(k);
        let x_ = a + "px";
        let y_ = b + "px";
        let container_ = this.m;
        container_.setRawStyleProperty("left", x_);
        container_.setRawStyleProperty("top", y_);
        if (this.a._visibility == 0 && !this.c) {
            this.m.show();
            this.c = true;
        }
        if (this.b.d && this.f != 1) {
            this.b.y();
        }
    }
    r() {
        return this.a.aj.exportPointerTooltipData(this.a.cq, this.a.cr, this.x, new Rect(0, 0, 0, this.a.ay, this.a.ax));
    }
    d(a) {
        let b = this.g;
        let c = this.e;
        let d = this.y(new Size(1, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY));
        if (d.width != b || d.height != c) {
            return true;
        }
        return false;
    }
    s() {
        this.k = null;
        this.m.hide();
        this.m.remove();
        this.m = null;
        this.o = null;
        this.q = null;
        this.p = null;
        this.m = null;
        this.l = null;
        this.n = null;
        if (this.j != null) {
            window.removeEventListener("resize", this.j, false);
            this.j = null;
        }
    }
    t() {
        this.m.hide();
    }
    v(a) {
        this.k = a;
    }
}
PointerTooltipView.$t = markType(PointerTooltipView, 'PointerTooltipView');
/*<BeginStatics Name="Infragistics.Controls.Charts.PointerTooltip" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.PointerTooltip" />*/
