/*
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 { Series } from "./Series";
import { IHasCategoryModePreference_$type } from "./IHasCategoryModePreference";
import { Axis } from "./Axis";
import { DependencyProperty } from "igniteui-angular-core";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { Point_$type, typeCast, Delegate_$type, enumGetBox, markType, markDep, runOn } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { Thickness } from "igniteui-angular-core";
import { OverlayTextLocation_$type } from "./OverlayTextLocation";
import { AnnotationAppearanceMode_$type } from "./AnnotationAppearanceMode";
import { OverlayTextUtil } from "./OverlayTextUtil";
import { List$1 } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { AxisAnnotation } from "./AxisAnnotation";
import { SeriesView } from "./SeriesView";
import { Rect } from "igniteui-angular-core";
import { NotImplementedException } from "igniteui-angular-core";
import { AxisRange } from "./AxisRange";
import { NumericAxisBase } from "./NumericAxisBase";
import { AxisAnnotationFrame } from "./AxisAnnotationFrame";
import { ScalerParams } from "./ScalerParams";
import { CategoryXAxis } from "./CategoryXAxis";
import { OverlayTextUpdatingEventArgs } from "./OverlayTextUpdatingEventArgs";
import { OverlayTextInfo } from "./OverlayTextInfo";
import { AxisAnnotationFrameManager } from "./AxisAnnotationFrameManager";
import { TextBlock } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { DeviceUtils } from "igniteui-angular-core";
import { isNaN_, isInfinity } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
import { stringFormat } from "igniteui-angular-core";
import { Path } from "igniteui-angular-core";
/**
 * @hidden
 */
export let ValueOverlay = /*@__PURE__*/ (() => {
    class ValueOverlay extends Series {
        constructor() {
            super();
            this.ya = 0;
            this.yb = 0;
            this.xx = 0;
            this.xc = null;
            this.xq = null;
            this.xp = null;
            this.stylingOverlayText = null;
            this.xh = null;
            this.ab = ValueOverlay.$;
            this.xh = OverlayTextUtil.c();
        }
        bk() {
            return new ValueOverlay();
        }
        i8(a, b, c) {
            return this.yc;
        }
        xy(a, b) {
            let c = Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
            let d = Math.acos((a.x - b.x) / c);
            if ((a.y - b.y) < 0) {
                d = (2 * Math.PI) - d;
            }
            return d;
        }
        wm(a, b, c) {
            if (this.xb == null) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let d = this.x9();
            let e = NaN;
            let f = NaN;
            let g = NaN;
            let h = { $type: Point_$type, x: 0.5, y: 0.5 };
            let i = NaN;
            switch (this.xb.bk) {
                case 2:
                    i = Math.sqrt(Math.pow(a.x - h.x, 2) + Math.pow(a.y - h.y, 2));
                    g = d;
                    e = h.x + Math.cos(g) * i;
                    f = h.y + Math.sin(g) * i;
                    f = this.cw.b9.top + this.cw.b9.height * (f - this.cw.ca.top) / this.cw.ca.height;
                    e = this.cw.b9.left + this.cw.b9.width * (e - this.cw.ca.left) / this.cw.ca.width;
                    break;
                case 0:
                    e = d;
                    f = a.y;
                    f = this.cw.b9.top + this.cw.b9.height * (f - this.cw.ca.top) / this.cw.ca.height;
                    break;
                case 1:
                    f = d;
                    e = a.x;
                    e = this.cw.b9.left + this.cw.b9.width * (e - this.cw.ca.left) / this.cw.ca.width;
                    break;
                case 3:
                    g = this.xy(a, h);
                    i = d;
                    e = h.x + Math.cos(g) * i;
                    f = h.y + Math.sin(g) * i;
                    f = this.cw.b9.top + this.cw.b9.height * (f - this.cw.ca.top) / this.cw.ca.height;
                    e = this.cw.b9.left + this.cw.b9.width * (e - this.cw.ca.left) / this.cw.ca.width;
                    break;
            }
            return { $type: Point_$type, x: e, y: f };
        }
        j7(a) {
            throw new NotImplementedException(0);
        }
        kr(a) {
            return this;
        }
        ge(a) {
            return false;
        }
        ay(a) {
            let b = typeCast(NumericAxisBase.$, a);
            let c = this.yc;
            if (isNaN_(c) || isInfinity(c)) {
                return null;
            }
            return new AxisRange(c, c);
        }
        rz(a) {
            this.pb(true, this.cw);
            if (!this.xo()) {
                if (this.xc != null) {
                    this.zk(NaN, this.d4());
                }
                return;
            }
            if (this.gg(a)) {
                if (this.d4()) {
                    if (this.dd.g) {
                        this.dd.t();
                    }
                    let b = this.ya;
                    this.ya = this.yb;
                    this.yb = b;
                }
                else {
                    this.ya = this.xx;
                }
                this.xx = this.x9();
                this.sf();
            }
            else {
                this.xx = this.x9();
                this.zj(this.xx, this.xg);
            }
        }
        x9() {
            let a, b;
            let c = this.getViewInfo(b, a);
            b = c.p0;
            a = c.p1;
            let d = this.getEffectiveViewport1(this.cw);
            let e = new ScalerParams(0, a, b, this.xb.df, d);
            return this.xb.ft(this.yc, e);
        }
        zj(a, b) {
            if (this.xb == null) {
                return;
            }
            let c = typeCast(CategoryAxisBase.$, this.xb);
            if (c != null && !c.dc) {
                if (this.yc > c.o6 - 1) {
                    return;
                }
                if (c.categoryMode != 0) {
                    let d = this.getEffectiveViewport1(b);
                    let e = 0.5 * c.getCategorySize(b.ca, b.b9, d);
                    let f = false;
                    if (c.dq && !c.df) {
                        f = true;
                    }
                    if (typeCast(CategoryXAxis.$, c) !== null && c.df) {
                        f = true;
                    }
                    if (f) {
                        e = -e;
                    }
                    a += e;
                }
            }
            let g = typeCast(NumericAxisBase.$, this.xb);
            if (g != null) {
                if (this.yc < g.pr || this.yc > g.pq) {
                    return;
                }
                if (g.pc && this.yc < 0) {
                    return;
                }
            }
            let h;
            switch (this.xb.bk) {
                case 2:
                case 3:
                    h = this.xb.ns(a, b.ca, b.b9, this.getEffectiveViewport1(b), this.wt(b));
                    break;
                default:
                    h = this.xb.ns(a, b.ca, b.b9, this.getEffectiveViewport1(b), this.wt(b));
                    break;
            }
            if (h != null) {
                b.cp(h);
            }
            if (!b.t) {
                this.zk(a, this.d4());
            }
        }
        hf(a, b, c) {
            let d = true;
            d = super.hf(a, b, c);
            if (!c.r() || b.isEmpty || a.isEmpty || this.xb == null || this.xb.b0 == null) {
                d = false;
            }
            return d;
        }
        sz(a, b) {
            this.ry(false);
        }
        sy(a, b) {
            this.ry(false);
        }
        ph(a, b, c, d) {
            throw new NotImplementedException(0);
        }
        rg(a, b, c, d) {
            super.rg(a, b, c, d);
            switch (b) {
                case ValueOverlay.$$p[11]:
                    if (c != null) {
                        c.cq(this);
                    }
                    if (d != null) {
                        d.du(this);
                    }
                    this.ry(false);
                    this.qr();
                    break;
                case "TransitionProgress":
                    this.yb = this.ya + this.ju * (this.xx - this.ya);
                    if (this.d7(this.cw)) {
                        return;
                    }
                    if (this.ju == 1) {
                        this.zj(this.xx, this.xg);
                        this.qu();
                    }
                    else {
                        this.zj(this.yb, this.xg);
                    }
                    if (this.dc != null) {
                        this.dc.rz(this);
                    }
                    break;
                case ValueOverlay.$$p[35]:
                    let e = typeCast(NumericAxisBase.$, this.xb);
                    if (e != null) {
                        e.d2();
                    }
                    this.ry(true);
                    this.qs();
                    break;
                case ValueOverlay.$$p[12]:
                case ValueOverlay.$$p[10]:
                case ValueOverlay.$$p[1]:
                case ValueOverlay.$$p[0]:
                case ValueOverlay.$$p[3]:
                case ValueOverlay.$$p[4]:
                case ValueOverlay.$$p[9]:
                case ValueOverlay.$$p[5]:
                case ValueOverlay.$$p[6]:
                case ValueOverlay.$$p[7]:
                case ValueOverlay.$$p[8]:
                    this.ry(true);
                    break;
                case ValueOverlay.$$p[31]:
                case ValueOverlay.$$p[34]:
                case ValueOverlay.$$p[30]:
                case ValueOverlay.$$p[13]:
                case ValueOverlay.$$p[24]:
                case ValueOverlay.$$p[25]:
                case ValueOverlay.$$p[27]:
                case ValueOverlay.$$p[26]:
                case ValueOverlay.$$p[14]:
                case ValueOverlay.$$p[15]:
                case ValueOverlay.$$p[17]:
                case ValueOverlay.$$p[16]:
                case ValueOverlay.$$p[19]:
                case ValueOverlay.$$p[20]:
                case ValueOverlay.$$p[22]:
                case ValueOverlay.$$p[18]:
                case ValueOverlay.$$p[21]:
                case ValueOverlay.$$p[23]:
                case ValueOverlay.$$p[28]:
                case ValueOverlay.$$p[29]:
                case ValueOverlay.$$p[33]:
                case ValueOverlay.$$p[32]:
                    this.ry(true);
                    break;
                case "SeriesViewer":
                    if (d == null) {
                        if (this.xp != null && this.xp.count > 0 && this.xc != null) {
                            this.zk(NaN, this.d4());
                        }
                    }
                    break;
            }
        }
        qh() {
            super.qh();
            if (this.xb != null) {
                this.xb.k3(false);
            }
        }
        pb(a, b) {
            super.pb(a, b);
            let c = b;
            c.ci();
        }
        xo() {
            if (this.xb == null || this.xb.b0 == null || isNaN_(this.yc) || this._visibility != 0) {
                return false;
            }
            let a = typeCast(CategoryAxisBase.$, this.xb);
            if (a != null && a.o6 == 0) {
                return false;
            }
            return true;
        }
        preferredCategoryMode(a) {
            return 0;
        }
        get categoryAxis() {
            return typeCast(CategoryAxisBase.$, this.xb);
        }
        ct() {
            return new ValueOverlayView(this);
        }
        q7(a) {
            super.q7(a);
            this.xg = typeCast(ValueOverlayView.$, a);
        }
        r0(a, b) {
            super.r0(a, b);
            if (!this.g1) {
                this.cw.be(b);
                return;
            }
            this.cw.be(b);
            if (this.d7(this.cv) || !this.xo()) {
                return;
            }
            let c = this.getEffectiveViewport1(this.cw);
            let d = this.xb.ft(this.yc, new ScalerParams(0, this.cv.ca, a, this.xb.df, c));
            this.zj(d, typeCast(ValueOverlayView.$, this.cv));
            this.g1 = false;
        }
        getOffsetValue() {
            return 0;
        }
        getCategoryWidth() {
            return 0;
        }
        get aar() {
            return new Thickness(1, this.xt, this.xv, this.xu, this.xs);
        }
        ai() {
            return [this.xb];
        }
        zi() {
            if (OverlayTextUtil.q(this.xh)) {
                this.xh = OverlayTextUtil.c();
            }
            else if (OverlayTextUtil.k(this.xh)) {
                this.xh = this.cw.l(this.xh.fontString);
            }
        }
        zk(a, b) {
            if (isNaN_(a)) {
                if (this.xc != null) {
                    AxisAnnotationFrameManager.b(this.xc);
                    AxisAnnotationFrameManager.d(this, this.xc, true, this.xp, this.xq, b, this.yd, this.yd, this.xd, this.xd);
                }
                return;
            }
            let c = false;
            if (this.xp == null) {
                c = true;
                this.xq = new List$1(Axis.$, 0);
                this.xp = new Dictionary$2(Axis.$, Pool$1.$.specialize(AxisAnnotation.$), 0);
            }
            this.xc = new AxisAnnotationFrame();
            let d = this.vj;
            if (d == null) {
                d = this.vp;
            }
            this.xg.ch();
            if (this.xb.bk == 0 || this.xb.bk == 1) {
                this.zi();
                let e = this.xi;
                let f = OverlayTextUtil.o(e, this.xn);
                let g = this.xe;
                if (g == 18) {
                    f = false;
                }
                if (f && !stringIsNullOrEmpty(this.yt)) {
                    let h = this.xb.dq;
                    let i = this.vj;
                    let j = this.aaq;
                    if (j == null && this.xm) {
                        j = i;
                    }
                    let k = this.aao;
                    if (k == null && this.xk) {
                        k = i;
                    }
                    let l = this.aap;
                    if (l == null && this.xl) {
                        l = i;
                    }
                    let m = new OverlayTextUpdatingEventArgs();
                    m.textLocation = this.xe;
                    m.textAngle = this.xz;
                    m.textVisible = this.xn;
                    m.textContent = this.yt;
                    m.textColorMode = this.xa;
                    m.textColorShift = this.x4;
                    m.textColor = j;
                    m.backgroundMode = this.w8;
                    m.backgroundShift = this.x0;
                    m.background = k;
                    m.borderMode = this.w9;
                    m.borderShift = this.x2;
                    m.borderStroke = l;
                    m.borderRadius = this.x1;
                    m.borderThickness = this.x3;
                    m.shapeBrush = this.vj;
                    m.shapeOutline = this.vn;
                    m.f = h;
                    m.horizontalMargin = this.x5;
                    m.verticalPadding = this.x8;
                    m.verticalMargin = this.x7;
                    m.horizontalPadding = this.x6;
                    if (this.stylingOverlayText != null) {
                        this.stylingOverlayText(this, m);
                    }
                    OverlayTextUtil.ad(m);
                    let n = OverlayTextInfo.d(m);
                    if (n.textVisible && !n.h) {
                        this.xg.ce.count = 1;
                        this.xg.cd.count = 1;
                        n.f = e;
                        n.ad = this.cw.cc(n.textContent, n.f);
                        n.u = this.xg.ce.item(0);
                        n.ac = this.xg.cd.item(0);
                        if (n.g) {
                            let o = this.dc.xe({ $type: Point_$type, x: 0, y: NaN });
                            let p = this.dc.xe({ $type: Point_$type, x: 1, y: NaN });
                            let q = p.x - o.x;
                            n.ab = new Rect(0, o.x, a, q, 1);
                        }
                        else {
                            let r = this.dc.xe({ $type: Point_$type, x: NaN, y: 0 });
                            let s = this.dc.xe({ $type: Point_$type, x: NaN, y: 1 });
                            let t = s.y - r.y;
                            n.ab = new Rect(0, a, r.y, 1, t);
                        }
                        OverlayTextUtil.ac(n);
                        this.cw.av(n.u, n.f);
                        this.cw.aw(n.u, n.f);
                    }
                }
            }
            let u = this.xb.dq;
            AxisAnnotationFrameManager.c(this.xc, { $type: Point_$type, x: a, y: a }, this, this.dc, this.getEffectiveViewport(), d, this.aal, this.xr, this.aan, this.aam, this.aar, this.xw, this.aal, this.xr, this.aan, this.aam, this.aar, this.xw, !u && this.xj, u && this.xj);
            AxisAnnotationFrameManager.d(this, this.xc, c, this.xp, this.xq, b, this.yd, this.yd, this.xd, this.xd);
        }
        get_isValueOverlay() {
            return true;
        }
        yq(a) {
            if (this.xb != null) {
                return this.xb.ih(a);
            }
            return null;
        }
        get ys() {
            let a = this.yq(this.yc);
            return a != null ? a : stringFormat("{0:0.##}", this.yc);
        }
        get xi() {
            return this.xh;
        }
        set xi(a) {
            let b = this.xh;
            if (OverlayTextUtil.q(a)) {
                a = OverlayTextUtil.c();
            }
            this.xh = a;
            if (b != this.xh) {
                this.raisePropertyChanged("OverlayTextStyle", b, this.xh);
            }
        }
    }
    ValueOverlay.$t = markType(ValueOverlay, 'ValueOverlay', Series.$, [IHasCategoryModePreference_$type]);
    ValueOverlay.$$p = markDep(DependencyProperty, PropertyMetadata, ValueOverlay, 'raisePropertyChanged', ['AxisAnnotationBackgroundCornerRadius:xr:zl', [1, DeviceUtils.g(3)], 'AxisAnnotationBackground:aal:zm', [Brush.$, null], 'AxisAnnotationFormatLabel:xd:zn', [Delegate_$type], 'AxisAnnotationInterpolatedValuePrecision:yd:zo', [1, -1], 'AxisAnnotationOutline:aam:zp', [Brush.$, null], 'AxisAnnotationPaddingBottom:xs:zq', [1, NaN], 'AxisAnnotationPaddingLeft:xt:zr', [1, NaN], 'AxisAnnotationPaddingRight:xu:zs', [1, NaN], 'AxisAnnotationPaddingTop:xv:zt', [1, NaN], 'AxisAnnotationStrokeThickness:xw:zu', [1, NaN], 'AxisAnnotationTextColor:aan:zv', [Brush.$, null], 'Axis:xb:zw', [Axis.$, null], 'IsAxisAnnotationEnabled:xj:zx', [0, false], 'OverlayTextAngle:xz:zy', [1, NaN], 'OverlayTextBackgroundMatchLayer:xk:zz', [0, false], 'OverlayTextBackgroundMode:w8:z0', [AnnotationAppearanceMode_$type, enumGetBox(AnnotationAppearanceMode_$type, 0)], 'OverlayTextBackground:aao:z1', [Brush.$, null], 'OverlayTextBackgroundShift:x0:z2', [1, NaN], 'OverlayTextBorderColor:aap:z3', [Brush.$, null], 'OverlayTextBorderMatchLayer:xl:z4', [0, false], 'OverlayTextBorderMode:w9:z5', [AnnotationAppearanceMode_$type, enumGetBox(AnnotationAppearanceMode_$type, 0)], 'OverlayTextBorderRadius:x1:z6', [1, NaN], 'OverlayTextBorderShift:x2:z7', [1, NaN], 'OverlayTextBorderThickness:x3:z8', [1, 1], 'OverlayTextColorMatchLayer:xm:z9', [0, true], 'OverlayTextColorMode:xa:aaa', [AnnotationAppearanceMode_$type, enumGetBox(AnnotationAppearanceMode_$type, 0)], 'OverlayTextColor:aaq:aab', [Brush.$, null], 'OverlayTextColorShift:x4:aac', [1, NaN], 'OverlayTextHorizontalMargin:x5:aad', [1, NaN], 'OverlayTextHorizontalPadding:x6:aae', [1, NaN], 'OverlayTextLocation:xe:aaf', [OverlayTextLocation_$type, enumGetBox(OverlayTextLocation_$type, 0)], 'OverlayText:yt:aag', [2, null], 'OverlayTextVerticalMargin:x7:aah', [1, NaN], 'OverlayTextVerticalPadding:x8:aai', [1, NaN], 'OverlayTextVisible:xn:aaj', [0, true], 'Value:yc:aak', [1, 0]]);
    return ValueOverlay;
})();
/**
 * @hidden
 */
export let ValueOverlayView = /*@__PURE__*/ (() => {
    class ValueOverlayView extends SeriesView {
        constructor(a) {
            super(a);
            this.cr = null;
            this.cg = null;
            this.ce = null;
            this.cf = null;
            this.cd = null;
            this.cr = new Path();
        }
        bp() {
            super.bp();
            this.cr._stroke = this.f.vj;
            this.cr.ad = this.f.ig;
            this.cr.ai = this.f.wc;
            this.cr.aj = this.f.wd;
        }
        bq() {
            super.bq();
            let a = this.b3();
            this.cr._stroke = a;
            this.cr.ad = this.f.ig + 3;
            this.cr._stroke = a;
            this.cr.ad = this.f.ig + 3;
        }
        cp(a) {
            this.cr.an = a;
            this.a2();
        }
        ci() {
            this.cr.an = null;
            this.a2();
        }
        bj(a, b) {
            super.bj(a, b);
            if (a.d) {
                a.t(this.cr);
                for (let c = 0; c < this.cd.count; c++) {
                    let d = this.cd.item(c);
                    if (d.j != null) {
                        a.aa();
                        a.k(d.j);
                    }
                    if (d._visibility == 0) {
                        a.w(d);
                    }
                    if (d.j != null) {
                        a.z();
                    }
                }
                for (let e = 0; e < this.ce.count; e++) {
                    let f = this.ce.item(e);
                    if (f.j != null) {
                        a.k(f.j);
                    }
                    a.ae(f.dataContext);
                    a.x(f);
                    if (f.j != null) {
                    }
                }
            }
        }
        ax(a) {
            super.ax(a);
            this.f.bc.exportPathData(a, this.cr, "ValueOverlayPath", []);
        }
        ch() {
        }
        a4() {
            super.a4();
            this.cg = new List$1(TextBlock.$, 0);
            this.ce = ((() => {
                let $ret = new Pool$1(TextBlock.$);
                $ret.create = runOn(this, this.cq);
                $ret.activate = runOn(this, this.cm);
                $ret.disactivate = runOn(this, this.co);
                $ret.destroy = runOn(this, this.cn);
                return $ret;
            })());
            this.cf = new List$1(Rectangle.$, 0);
            this.cd = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.cs);
                $ret.activate = runOn(this, this.cj);
                $ret.disactivate = runOn(this, this.cl);
                $ret.destroy = runOn(this, this.ck);
                return $ret;
            })());
        }
        cq() {
            let a = new TextBlock();
            this.cg.add(a);
            return a;
        }
        cn(a) {
            if (this.cg.contains(a)) {
                this.cg.remove(a);
            }
        }
        cm(a) {
            a._visibility = 0;
            a.s = 0;
        }
        co(a) {
            a._visibility = 1;
        }
        cs() {
            let a = new Rectangle();
            this.cf.add(a);
            return a;
        }
        ck(a) {
            a.dataContext = null;
            if (this.cf.contains(a)) {
                this.cf.remove(a);
            }
        }
        cj(a) {
            a._visibility = 0;
        }
        cl(a) {
            a._visibility = 1;
        }
    }
    ValueOverlayView.$t = markType(ValueOverlayView, 'ValueOverlayView', SeriesView.$);
    return ValueOverlayView;
})();
