/*
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 { ScatterTriangulationSeries } from "./ScatterTriangulationSeries";
import { DependencyProperty } from "igniteui-react-core";
import { typeCast, Number_$type, Point_$type, fromEnum, runOn, delegateRemove, delegateCombine, markType, markDep } from "igniteui-react-core";
import { ValueBrushScale } from "./ValueBrushScale";
import { FastItemIntColumn } from "igniteui-react-core";
import { LinearContourValueResolver } from "./LinearContourValueResolver";
import { SeriesView } from "./SeriesView";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { ContourBuilder } from "./ContourBuilder";
import { Clipper } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { RectUtil } from "igniteui-react-core";
import { DataContext } from "igniteui-react-core";
import { Path } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { boxArray$1 } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Brush } from "igniteui-react-core";
import { PathGeometry } from "igniteui-react-core";
import { PathFigure } from "igniteui-react-core";
import { PolyLineSegment } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { BrushCollection } from "igniteui-react-core";
import { PointCollectionUtil } from "igniteui-react-core";
import { Tuple$2 } from "igniteui-react-core";
import { GeometryUtil } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
/**
 * @hidden
 */
export let ScatterContourSeries = /*@__PURE__*/ (() => {
    class ScatterContourSeries extends ScatterTriangulationSeries {
        constructor() {
            super();
            this.pu = null;
            this.pq = null;
            FastItemIntColumn.m();
            this.ab = ScatterContourSeries.$;
            this.pr = new LinearContourValueResolver();
        }
        gt(a, b) {
            let c = this.ic(b);
            if (c == ScatterContourSeries.$$p[1]) {
                return this.gu(a, b, this.py);
            }
            return super.gt(a, b);
        }
        bp() {
            this.ps = new ScatterContourSeriesView(this);
            return this.ps;
        }
        get pv() {
            return this.pu;
        }
        set pv(a) {
            let b = this.pv != a;
            if (b) {
                let c = this.pv;
                this.pu = a;
                this.raisePropertyChanged("ValueColumn", c, this.pv);
            }
        }
        kp(a, b, c, d) {
            super.kp(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.pv);
                        this.pv = null;
                    }
                    let f = typeCast(IFastItemsSource_$type, d);
                    if (f != null) {
                        this.pv = this.ca(this.py);
                    }
                    this.k3(false);
                    break;
                case ScatterContourSeries.$$p[1]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.pv);
                        this.pv = this.ca(this.py);
                    }
                    this.k3(false);
                    this.ka();
                    break;
                case "ValueResolver":
                    this.k3(false);
                    this.ka();
                    break;
                case ScatterContourSeries.$$p[0]:
                    let g = c;
                    let h = d;
                    if (g != null) {
                        g.unregisterSeries(this);
                    }
                    if (h != null) {
                        h.registerSeries(this);
                    }
                    this.k3(false);
                    this.ka();
                    break;
                case "ActualBrush":
                    this.k3(false);
                    this.ka();
                    break;
            }
        }
        jl(a, b) {
            super.jl(a, b);
            if (a) {
                b.b3(a);
            }
        }
        k4(a) {
            super.k4(a);
            this.p1(this.bs);
        }
        k2(a, b, c, d, e) {
            super.k2(a, b, c, d, e);
            let f = this.a3.a$h.item(d);
            f.a1(c);
            if (this.cp(f)) {
                return;
            }
            this.p1(f);
        }
        p1(a) {
            if (this.cp(a)) {
                return;
            }
            let b;
            let c;
            let d = a;
            let e = a.getViewInfo(c, b);
            c = e.p0;
            b = e.p1;
            let f = new ScalerParams(1, b, c, this.n9.ca);
            f.c = this.getEffectiveViewport1(a);
            let g = new ScalerParams(1, b, c, this.oa.ca);
            g.c = this.getEffectiveViewport1(a);
            let h = this.n9;
            let i = this.oa;
            let j = this.oj.count;
            let k;
            let xArr_ = this.om.asArray();
            k = (xArr_.slice(0));
            let l;
            let yArr_ = this.on.asArray();
            l = (yArr_.slice(0));
            let m = this.pv.asArray();
            let n = this.oj.asArray();
            let o = this.ok.asArray();
            let p = this.ol.asArray();
            let q = this.pr.j(this.pv);
            let r = new List$1(Number_$type, 1, q).toArray();
            h.gt(boxArray$1(k), 0, k.length, f);
            i.gt(boxArray$1(l), 0, l.length, g);
            let s = r.length;
            let t = new Array(s);
            for (let u = 0; u < s; ++u) {
                t[u] = new ContourBuilder();
            }
            let v = c.top;
            let w = c.left;
            let x = c.right;
            let y = c.bottom;
            let z;
            let aa;
            let ab;
            let ac;
            let ad = k.length;
            for (let ae = 0; ae < j; ae++) {
                let af = n[ae];
                let ag = o[ae];
                let ah = p[ae];
                if ((af >= ad) || (ag >= ad) || (ah >= ad) || (af < 0) || (ag < 0) || (ah < 0)) {
                    continue;
                }
                let ai = k[af];
                let aj = l[af];
                let ak = { $type: Point_$type, x: ai, y: aj };
                let al = k[ag];
                let am = l[ag];
                let an = { $type: Point_$type, x: al, y: am };
                let ao = k[ah];
                let ap = l[ah];
                let aq = { $type: Point_$type, x: ao, y: ap };
                z = an.y < aq.y ? an.y : aq.y;
                z = ak.y < z ? ak.y : z;
                aa = an.y > aq.y ? an.y : aq.y;
                aa = ak.y > aa ? ak.y : aa;
                ab = an.x < aq.x ? an.x : aq.x;
                ab = ak.x < ab ? ak.x : ab;
                ac = an.x > aq.x ? an.x : aq.x;
                ac = ak.x > ac ? ak.x : ac;
                if (z < y && aa > v && ab < x && ac > w) {
                    let ar = m[af];
                    let as = m[ag];
                    let at = m[ah];
                    if (isNaN_(ar) || isNaN_(as) || isNaN_(at)) {
                        continue;
                    }
                    for (let au = 0; au < s; au++) {
                        let av = r[au];
                        let aw = t[au];
                        switch ((ar < av ? 1 : 0) | (as < av ? 2 : 0) | (at < av ? 4 : 0)) {
                            case 0: break;
                            case 1:
                                aw.d(aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av), aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av));
                                break;
                            case 2:
                                aw.d(aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av), aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av));
                                break;
                            case 3:
                                aw.d(aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av), aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av));
                                break;
                            case 4:
                                aw.d(aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av), aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av));
                                break;
                            case 5:
                                aw.d(aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av), aw.k(ag, an.x, an.y, as, ah, aq.x, aq.y, at, av));
                                break;
                            case 6:
                                aw.d(aw.k(ah, aq.x, aq.y, at, af, ak.x, ak.y, ar, av), aw.k(af, ak.x, ak.y, ar, ag, an.x, an.y, as, av));
                                break;
                            case 7: break;
                        }
                    }
                }
            }
            let ax = new Clipper(0, RectUtil.r(c, 2), false);
            let ay = new List$1(List$1.$.specialize(List$1.$.specialize(Point_$type)), 0);
            for (let az = 0; az < s; ++az) {
                let a0 = t[az];
                let a1 = new List$1(List$1.$.specialize(Point_$type), 0);
                let a2 = a0.c();
                for (let a3 = 0; a3 < a2.count; a3++) {
                    let a4 = a2._inner[a3];
                    let a5 = new List$1(Point_$type, 0);
                    ax.i = a5;
                    for (let a6 of fromEnum(a4)) {
                        ax.j({ $type: Point_$type, x: a0.g.item(a6), y: a0.h.item(a6) });
                    }
                    ax.i = null;
                    a1.add(a5);
                }
                ay.add(a1);
            }
            d.b2(ay, r);
        }
        get pr() {
            return this.pq;
        }
        set pr(a) {
            let b = a != this.pr;
            if (b) {
                if (this.pq != null) {
                    let c = this.pq;
                    c.updated = delegateRemove(c.updated, runOn(this, this.p2));
                }
                let d = this.pq;
                this.pq = a;
                if (this.pq != null) {
                    let e = this.pq;
                    e.updated = delegateCombine(e.updated, runOn(this, this.p2));
                }
                this.raisePropertyChanged("ValueResolver", d, a);
                this.k3(false);
            }
        }
        p2(a, b) {
            this.k3(false);
        }
        ec(a, b, c) {
            return super.ec(a, b, c) && this.pr != null && this.om != null && this.on != null && this.oj != null && this.ok != null && this.ol != null && this.om.count > 0 && this.on.count > 0 && this.oj.count > 0 && this.ok.count > 0 && this.ol.count > 0;
        }
        as(a, b) {
            let c = this.ps.b7(a, b);
            if (c != null) {
                return c.dataContext;
            }
            return null;
        }
    }
    ScatterContourSeries.$t = /*@__PURE__*/ markType(ScatterContourSeries, 'ScatterContourSeries', ScatterTriangulationSeries.$);
    ScatterContourSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ScatterContourSeries, 'raisePropertyChanged', ['FillScale:pt:p3', [ValueBrushScale.$, null], 'ValueMemberPath:py:p4', [2, null]]);
    return ScatterContourSeries;
})();
/**
 * @hidden
 */
export let ScatterContourSeriesView = /*@__PURE__*/ (() => {
    class ScatterContourSeriesView extends SeriesView {
        constructor(a) {
            super(a);
            this.bz = null;
            this.by = null;
            this.b1 = null;
            this.b0 = new List$1(Brush.$, 0);
            this.bx = null;
            this.b1 = new List$1(Path.$, 0);
            this.by = a;
            this.bz = ((() => {
                let $ret = new Pool$1(Path.$);
                $ret.create = runOn(this, this.b8);
                $ret.destroy = runOn(this, this.b6);
                $ret.activate = runOn(this, this.b4);
                $ret.disactivate = runOn(this, this.b5);
                return $ret;
            })());
        }
        b8() {
            let a = new Path();
            a.dataContext = ((() => {
                let $ret = new DataContext();
                $ret.series = this.e;
                return $ret;
            })());
            this.b1.add(a);
            return a;
        }
        b4(a) {
            a._visibility = 0;
        }
        b5(a) {
            a._visibility = 1;
        }
        b6(a) {
            this.b1.remove(a);
        }
        b2(a, b) {
            let c = 0;
            this.bx = b;
            this.b0.clear();
            let d = this.by.pt;
            if (d == null) {
                d = new ValueBrushScale();
                d.brushes.add(BrushUtil.l(this.e.m9, -0.5));
                d.brushes.add(this.e.m9);
            }
            else if (d.brushes == null) {
                d.brushes = new BrushCollection();
                d.brushes.add(BrushUtil.l(this.e.m9, -0.5));
                d.brushes.add(this.e.m9);
            }
            else if (d.brushes.count == 0) {
                d.brushes.add(BrushUtil.l(this.e.m9, -0.5));
                d.brushes.add(this.e.m9);
            }
            for (let e = 0; e < b.length; e++) {
                let f = b[e];
                let g = a._inner[c];
                let h = new PathGeometry();
                for (let i = 0; i < g.count; i++) {
                    let j = g._inner[i];
                    if (j.count == 0) {
                        continue;
                    }
                    let k = PointCollectionUtil.f(j);
                    let l = ((() => {
                        let $ret = new PathFigure();
                        $ret.isClosed = false;
                        $ret.isFilled = false;
                        $ret.startPoint = k._inner[0];
                        return $ret;
                    })());
                    l._segments.add(((() => {
                        let $ret = new PolyLineSegment();
                        $ret.points = k;
                        return $ret;
                    })()));
                    h.c.add(l);
                }
                this.bz.item(c).ak = h;
                if (this.bz.item(c).dataContext != null) {
                    this.bz.item(c).dataContext.item = f;
                }
                if (d != null) {
                    let m = d.getBrushByValue(f, this.by.pv);
                    if (m == null) {
                        m = this.e.m9;
                    }
                    this.b0.add(m);
                }
                else {
                    this.b0.add(this.e.m9);
                }
                c++;
            }
            this.bz.count = c;
            this.aq();
        }
        be(a, b) {
            super.be(a, b);
            let c = a;
            c._stroke = this.b0._inner[b];
            c.ac = this.e.eu;
            if (c.y != null) {
                this.k.i(c, c.y);
            }
        }
        bf(a, b) {
            super.bf(a, b);
            let c = a;
            let d = this.bp(b);
            c._stroke = d;
            c.ac = this.e.eu + 3;
        }
        a6(a, b) {
            super.a6(a, b);
            for (let c = 0; c < this.b1.count; c++) {
                let d = this.b1._inner[c];
                if (d._visibility != 1) {
                    this.bd(d, c, b);
                    a.s(d);
                }
            }
        }
        b3(a) {
            this.bz.count = 0;
            this.aq();
        }
        al(a) {
            super.al(a);
            let b = new List$1(Tuple$2.$.specialize(Number_$type, Path.$), 0);
            if (this.bx != null) {
                for (let c = 0; c < this.bz.count; c++) {
                    b.add(new Tuple$2(Number_$type, Path.$, this.bx[c], this.bz.item(c)));
                }
            }
            b.aa((d, e) => {
                if (d.c < e.c) {
                    return -1;
                }
                else if (d.c > e.c) {
                    return 1;
                }
                return 0;
            });
            for (let d = 0; d < b.count; d++) {
                let e = typeCast(Path.$, b._inner[d].d);
                if (e._visibility != 1) {
                    this.e.a5.exportPathData(a, e, "contour" + d, ["Main "]);
                }
            }
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'><span";
            let b = this.e.a3.a$r(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.by.gy + "</span><br/>";
            if (!stringIsNullOrEmpty(this.by.py)) {
                a += "<span>Value: ${item}</span>";
            }
            a += "</div>";
            return a;
        }
        b7(a, b) {
            for (let c = 0; c < this.b1.count; c++) {
                let d = this.b1._inner[c];
                let e = typeCast(PathGeometry.$, d.ak);
                if (e != null) {
                    for (let f = 0; f < e.c.count; f++) {
                        let g = e.c._inner[f];
                        let h = e.c._inner[f]._startPoint;
                        for (let i = 0; i < g._segments.count; i++) {
                            let j = typeCast(PolyLineSegment.$, g._segments._inner[i]);
                            if (j != null) {
                                let k = this.by.eu / 2 + this.by.e7(b);
                                if (j._points.count > 0 && GeometryUtil.b(a, h, j._points, k)) {
                                    return d;
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
    }
    ScatterContourSeriesView.$t = /*@__PURE__*/ markType(ScatterContourSeriesView, 'ScatterContourSeriesView', SeriesView.$);
    return ScatterContourSeriesView;
})();
//# sourceMappingURL=ScatterContourSeries_combined.js.map
