/*
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 { ScatterBase } from "./ScatterBase";
import { UnknownValuePlotting_$type } from "igniteui-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { Point_$type, typeCast, runOn, Number_$type, enumGetBox, markType, markDep } from "igniteui-react-core";
import { OwnedPoint } from "./OwnedPoint";
import { ScatterFrame } from "./ScatterFrame";
import { ScatterLineSeriesView } from "./ScatterLineSeriesView";
import { Defaults } from "./Defaults";
import { PathGeometry } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { Clipper } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { RectUtil } from "igniteui-react-core";
import { PolyLineSegment } from "igniteui-react-core";
import { PathFigure } from "igniteui-react-core";
import { PathFigureCollection } from "igniteui-react-core";
import { Flattener } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { boxArray$1, arrayShallowClone } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
/**
 * @hidden
 */
export let ScatterLineSeries = /*@__PURE__*/ (() => {
    class ScatterLineSeries extends ScatterBase {
        bi() {
            return new ScatterLineSeries();
        }
        get_fi() {
            return true;
        }
        constructor() {
            super();
            this.ab = ScatterLineSeries.$;
            this.yt = new ScatterFrame();
            this.yv = new ScatterFrame();
            this.yr = new ScatterFrame();
            let a = (b, c, d) => {
                let e = this.dl.indexOf(b.a);
                if (e == -1 || e == 0) {
                    return b;
                }
                let f = this.dl.item(e - 1);
                let g;
                if (!((() => { let h = c.g.tryGetValue(f, g); g = h.p1; return h.ret; })())) {
                    return b;
                }
                return g;
            };
            this.yt.o = a;
            this.yv.o = a;
            this.yr.o = a;
        }
        cq() {
            return new ScatterLineSeriesView(this);
        }
        zn() {
            return true;
        }
        ji() {
            if (!isNaN_(this.jh)) {
                return super.ji();
            }
            return Defaults.x;
        }
        gu(a, b) {
            if (this.w8(a, b)) {
                return true;
            }
            if (this.ace(a, b)) {
                return true;
            }
            return false;
        }
        ace(a, b) {
            let c = this.ct;
            let d = c.dl;
            return this.gv(a, b, d.an);
        }
        aa5(a, b) {
            super.aa5(a, b);
            a.m.clear();
            a.u.clear();
            let c = b.by;
            let d = b.bx;
            let e = this.getEffectiveViewport1(b);
            let f = this.ib * this.ib;
            let g = 0;
            if (this.y8 != null) {
                g = this.y8.count;
            }
            if (this.y9 != null) {
                g = Math.min(this.y9.count, g);
            }
            let h = new ScalerParams(0, c, d, this.yn.d, e);
            let i = ((() => {
                let $ret = new ScalerParams(0, c, d, this.yn.e, e);
                $ret.b = this.iw();
                return $ret;
            })());
            let j = arrayShallowClone(this.y8.asArray());
            let k = arrayShallowClone(this.y9.asArray());
            this.xAxis.ho(boxArray$1(j), 0, j.length, h);
            this.yAxis.ho(boxArray$1(k), 0, k.length, i);
            let l = d.top - 10;
            let m = d.bottom + 10;
            let n = d.left - 10;
            let o = d.right + 10;
            let p = ((() => {
                let $ret = new Clipper(1, n, m, o, l, false);
                $ret.i = a.m;
                return $ret;
            })());
            for (let q = 0; q < g;) {
                let r = q;
                ++q;
                if (g > this.z0) {
                    while (q < g) {
                        let s = j[q] - j[r];
                        let t = k[q] - k[r];
                        let u = s * s + t * t;
                        if (isNaN_(u) || u >= f) {
                            break;
                        }
                        ++q;
                    }
                    p.j(this.acl(j, k, r, q - 1));
                }
                else {
                    let v = new OwnedPoint();
                    v.c = { $type: Point_$type, x: j[r], y: k[r] };
                    v.a = this.dl.item(r);
                    if (!a.u.containsKey(v.a)) {
                        a.u.addItem(v.a, v);
                    }
                }
            }
            if (g > this.z0) {
                p.i = null;
            }
        }
        acl(a, b, c, d) {
            if (c == d) {
                return { $type: Point_$type, x: a[c], y: b[c] };
            }
            let e = 0;
            let f = 0;
            let g = (d - c + 1);
            for (let h = c; h <= d; ++h) {
                e += a[h];
                f += b[h];
            }
            return { $type: Point_$type, x: e / g, y: f / g };
        }
        get_zh() {
            return true;
        }
        abg(a, b) {
            b.c9(false);
            super.abg(a, b);
            let c = this.getEffectiveViewport1(b);
            let d = new Rect(0, b.bx.left, b.bx.top, b.bx.width, b.bx.height);
            d = RectUtil.t(d, this.ic, this.ic);
            this.aa9(a, new Clipper(0, d, false));
            let e = typeCast(ScatterLineSeriesView.$, b);
            this.y0.az(this, this.zm(), runOn(this, this.yg));
            let f = false;
            let g = this.y0.b;
            if (g != null) {
                f = true;
            }
            if (f) {
                this.aa1(-1, this.y8.count, b.q);
            }
            this.y0.ad(e.dl, true, false, true, false);
            this.acj(e.dl, a.m.count, (h) => a.m._inner[h].x, (h) => a.m._inner[h].y, this.acd, this.ib);
        }
        acj(a, b, c, d, e, f) {
            let g = new PathGeometry();
            a.an = g;
            g.c = new PathFigureCollection();
            let h = new List$1(PolyLineSegment.$, 0);
            let i = 0;
            for (let j = 0; j < b; j++) {
                if (isNaN_(c(j)) || isNaN_(d(j))) {
                    let k = j - i;
                    if (k > 0) {
                        if (e == 1 || h.count == 0) {
                            let l = new PolyLineSegment();
                            h.add(l);
                        }
                        this.aci(h._inner[h.count - 1]._points, i, j - 1, c, d, f);
                    }
                    i = j + 1;
                }
            }
            if (e == 1 || h.count == 0) {
                let m = new PolyLineSegment();
                h.add(m);
            }
            this.aci(h._inner[h.count - 1]._points, i, b - 1, c, d, f);
            for (let n = 0; n < h.count; n++) {
                let o = h._inner[n];
                if (o._points.count > 0) {
                    let p = ((() => {
                        let $ret = new PathFigure();
                        $ret.startPoint = o._points._inner[0];
                        return $ret;
                    })());
                    p._segments.add(o);
                    g.c.add(p);
                }
            }
        }
        acf(a, b, c, d, e, f) {
            let g = new List$1(Number_$type, 0);
            let h = d;
            let i = e;
            let j = i - h + 1;
            while (j > 0) {
                if (j <= 512) {
                    Flattener.c(g, b, c, h, i, f);
                    h = i + 1;
                }
                else {
                    let k = h + 512 - 1;
                    Flattener.c(g, b, c, h, k, f);
                    h = k + 1;
                }
                j = i - h + 1;
            }
            return g;
        }
        aci(a, b, c, d, e, f) {
            if (c > -1) {
                let g = !isNaN_(this.jh) ? f : 1;
                let h = this.acf(new List$1(Number_$type, 0), d, e, b, c, g);
                let i;
                for (let j = 0; j < h.count; j++) {
                    i = h.item(j);
                    a.add({ $type: Point_$type, x: d(i), y: e(i) });
                }
            }
        }
        q4(a, b, c, d) {
            super.q4(a, b, c, d);
            switch (b) {
                case ScatterLineSeries.$$p[0]:
                    this.rm(false);
                    this.qg();
                    break;
            }
        }
    }
    ScatterLineSeries.$t = /*@__PURE__*/ markType(ScatterLineSeries, 'ScatterLineSeries', ScatterBase.$);
    ScatterLineSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ScatterLineSeries, 'raisePropertyChanged', ['UnknownValuePlotting:acd:ack', [UnknownValuePlotting_$type, /*@__PURE__*/ enumGetBox(UnknownValuePlotting_$type, 1)]]);
    return ScatterLineSeries;
})();
