/*
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 { __extends, __values } from "tslib";
import { ScatterTriangulationSeries } from "./ScatterTriangulationSeries";
import { DependencyProperty } from "igniteui-react-core";
import { Point_$type, typeCast, Number_$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 { DataLegendSeriesValueInfo } from "igniteui-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { ContourBuilder } from "./ContourBuilder";
import { Clipper } from "igniteui-react-core";
import { RectUtil } from "igniteui-react-core";
import { Brush } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { BrushCollection } 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 { PathGeometry } from "igniteui-react-core";
import { PathFigure } from "igniteui-react-core";
import { PointCollectionUtil } from "igniteui-react-core";
import { PolyLineSegment } from "igniteui-react-core";
import { Tuple$2 } from "igniteui-react-core";
import { GeometryUtil } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
/**
 * @hidden
 */
var ScatterContourSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScatterContourSeries, _super);
    function ScatterContourSeries() {
        var _this = _super.call(this) || this;
        _this.v1 = null;
        _this.vw = null;
        FastItemIntColumn.m();
        _this.ab = ScatterContourSeries.$;
        _this.vx = new LinearContourValueResolver();
        return _this;
    }
    ScatterContourSeries.prototype.bc = function () {
        return new ScatterContourSeries();
    };
    ScatterContourSeries.prototype.get_ex = function () {
        return true;
    };
    ScatterContourSeries.prototype.jv = function (a, b) {
        var c = this.lw(b);
        if (c == ScatterContourSeries.$$p[4]) {
            return this.jw(a, b, this.wa);
        }
        return _super.prototype.jv.call(this, a, b);
    };
    ScatterContourSeries.prototype.cd = function () {
        this.vy = new ScatterContourSeriesView(this);
        return this.vy;
    };
    Object.defineProperty(ScatterContourSeries.prototype, "v2", {
        get: function () {
            return this.v1;
        },
        set: function (a) {
            var b = this.v2 != a;
            if (b) {
                var c = this.v2;
                this.v1 = a;
                this.raisePropertyChanged("ValueColumn", c, this.v2);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterContourSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.js(c);
        var e = d == null ? NaN : this.h2(d, "XMemberPath");
        var f = d == null ? NaN : this.h2(d, "YMemberPath");
        var g = d == null ? NaN : this.h2(d, "ValueMemberPath");
        var h = new DataLegendSeriesValueInfo();
        h.a = 13;
        h.l = e;
        h.p = "X";
        h.q = this.u5 != null ? this.u5 : "X";
        h.r = this.u1 != null ? this.u1 : "X:";
        h.s = this.u3 != null ? this.u3 : "";
        var i = new DataLegendSeriesValueInfo();
        i.a = 14;
        i.l = f;
        i.p = "Y";
        i.q = this.vd != null ? this.vd : "Y";
        i.r = this.u9 != null ? this.u9 : "Y:";
        i.s = this.vb != null ? this.vb : "";
        var j = new DataLegendSeriesValueInfo();
        j.a = 0;
        j.l = g;
        j.p = "Value";
        j.q = this.wa != null ? this.wa : "Value";
        j.r = this.v6 != null ? this.v6 : "V:";
        j.s = this.v8 != null ? this.v8 : "";
        var k = new DataLegendSeriesContext();
        k.f = ((function () {
            var $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
            $ret.add(h);
            $ret.add(i);
            $ret.add(j);
            return $ret;
        })());
        k.b = this.aw();
        return k;
    };
    ScatterContourSeries.prototype.pa = function (a, b, c, d) {
        _super.prototype.pa.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.v2);
                    this.v2 = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.v2 = this.c4(this.wa);
                }
                this.pr(this.fr && c != null);
                break;
            case ScatterContourSeries.$$p[4]:
                if (this.c7 != null) {
                    this.c7.deregisterColumn(this.v2);
                    this.v2 = this.c4(this.wa);
                }
                this.pr(false);
                this.om();
                break;
            case "ValueResolver":
                this.pr(false);
                this.om();
                break;
            case ScatterContourSeries.$$p[1]:
                var g = c;
                var h = d;
                if (g != null) {
                    g.unregisterSeries(this);
                }
                if (h != null) {
                    h.registerSeries(this);
                }
                this.we();
                this.pr(false);
                this.om();
                break;
            case "ActualBrush":
                this.we();
                this.pr(false);
                this.om();
                break;
        }
    };
    ScatterContourSeries.prototype.nk = function (a, b) {
        _super.prototype.nk.call(this, a, b);
        if (a) {
            b.b6(a);
        }
    };
    ScatterContourSeries.prototype.ps = function (a) {
        _super.prototype.ps.call(this, a);
        this.wd(this.cg);
    };
    ScatterContourSeries.prototype.pq = function (a, b, c, d, e) {
        _super.prototype.pq.call(this, a, b, c, d, e);
        var f = this.a3.a$h.item(d);
        f.a3(c);
        if (this.dm(f)) {
            return;
        }
        this.wd(f);
    };
    ScatterContourSeries.prototype.wd = function (a) {
        var e_1, _a;
        if (this.dm(a)) {
            return;
        }
        var b;
        var c;
        var d = a;
        var e = a.getViewInfo(c, b);
        c = e.p0;
        b = e.p1;
        var f = new ScalerParams(1, b, c, this.t3.ch);
        f.c = this.getEffectiveViewport1(a);
        var g = new ScalerParams(1, b, c, this.t4.ch);
        g.c = this.getEffectiveViewport1(a);
        var h = this.t3;
        var i = this.t4;
        var j = this.ud.count;
        var k;
        var xArr_ = this.ug.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.uh.asArray();
        l = (yArr_.slice(0));
        var m = this.v2.asArray();
        var n = this.ud.asArray();
        var o = this.ue.asArray();
        var p = this.uf.asArray();
        var q = this.vx.j(this.v2);
        var r = new List$1(Number_$type, 1, q).toArray();
        h.hn(boxArray$1(k), 0, k.length, f);
        i.hn(boxArray$1(l), 0, l.length, g);
        var s = r.length;
        var t = new Array(s);
        for (var u = 0; u < s; ++u) {
            t[u] = new ContourBuilder();
        }
        var v = c.top;
        var w = c.left;
        var x = c.right;
        var y = c.bottom;
        var z;
        var aa;
        var ab;
        var ac;
        var ad = k.length;
        for (var ae = 0; ae < j; ae++) {
            var af = n[ae];
            var ag = o[ae];
            var ah = p[ae];
            if ((af >= ad) || (ag >= ad) || (ah >= ad) || (af < 0) || (ag < 0) || (ah < 0)) {
                continue;
            }
            var ai = k[af];
            var aj = l[af];
            var ak = { $type: Point_$type, x: ai, y: aj };
            var al = k[ag];
            var am = l[ag];
            var an = { $type: Point_$type, x: al, y: am };
            var ao = k[ah];
            var ap = l[ah];
            var 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) {
                var ar = m[af];
                var as = m[ag];
                var at = m[ah];
                if (isNaN_(ar) || isNaN_(as) || isNaN_(at)) {
                    continue;
                }
                for (var au = 0; au < s; au++) {
                    var av = r[au];
                    var 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;
                    }
                }
            }
        }
        var ax = new Clipper(0, RectUtil.r(c, 2), false);
        var ay = new List$1(List$1.$.specialize(List$1.$.specialize(Point_$type)), 0);
        for (var az = 0; az < s; ++az) {
            var a0 = t[az];
            var a1 = new List$1(List$1.$.specialize(Point_$type), 0);
            var a2 = a0.c();
            for (var a3 = 0; a3 < a2.count; a3++) {
                var a4 = a2._inner[a3];
                var a5 = new List$1(Point_$type, 0);
                ax.i = a5;
                try {
                    for (var _b = (e_1 = void 0, __values(fromEnum(a4))), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var a6 = _c.value;
                        ax.j({ $type: Point_$type, x: a0.g.item(a6), y: a0.h.item(a6) });
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return))
                            _a.call(_b);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
                ax.i = null;
                a1.add(a5);
            }
            ay.add(a1);
        }
        d.b5(ay, r);
    };
    ScatterContourSeries.prototype.qf = function () {
        _super.prototype.qf.call(this);
        this.we();
    };
    ScatterContourSeries.prototype.we = function () {
        var e_2, _a;
        var a = this.su;
        if (a == null) {
            a = this.sy;
        }
        if (a == null) {
            a = BrushUtil.h(255, 255, 255, 255);
        }
        var b = new ValueBrushScale();
        b.brushes = new BrushCollection();
        if (this.v0 == null || this.v0.brushes == null || this.v0.brushes.count == 0) {
            b.brushes.add(BrushUtil.m(a, -0.5));
            b.brushes.add(a);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.v0.brushes)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var c = _c.value;
                    b.brushes.add(c);
                }
            }
            catch (e_2_1) {
                e_2 = { error: e_2_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_2)
                        throw e_2.error;
                }
            }
        }
        if (this.v0 != null) {
            if (!isNaN_(this.v0.minimumValue)) {
                b.minimumValue = this.v0.minimumValue;
            }
            if (!isNaN_(this.v0.maximumValue)) {
                b.maximumValue = this.v0.maximumValue;
            }
            b.logarithmBase = this.v0.logarithmBase;
            b.isLogarithmic = this.v0.isLogarithmic;
        }
        this.vz = b;
    };
    Object.defineProperty(ScatterContourSeries.prototype, "vx", {
        get: function () {
            return this.vw;
        },
        set: function (a) {
            var b = a != this.vx;
            if (b) {
                if (this.vw != null) {
                    var c = this.vw;
                    c.updated = delegateRemove(c.updated, runOn(this, this.wf));
                }
                var d = this.vw;
                this.vw = a;
                if (this.vw != null) {
                    var e = this.vw;
                    e.updated = delegateCombine(e.updated, runOn(this, this.wf));
                }
                this.raisePropertyChanged("ValueResolver", d, a);
                this.pr(false);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterContourSeries.prototype.wf = function (a, b) {
        this.pr(false);
    };
    ScatterContourSeries.prototype.gm = function (a, b, c) {
        return _super.prototype.gm.call(this, a, b, c) && this.vx != null && this.ug != null && this.uh != null && this.ud != null && this.ue != null && this.uf != null && this.ug.count > 0 && this.uh.count > 0 && this.ud.count > 0 && this.ue.count > 0 && this.uf.count > 0;
    };
    ScatterContourSeries.prototype.au = function (a, b) {
        var c = this.vy.ca(a, b);
        if (c != null) {
            return c.dataContext;
        }
        return null;
    };
    ScatterContourSeries.$t = markType(ScatterContourSeries, 'ScatterContourSeries', ScatterTriangulationSeries.$);
    ScatterContourSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterContourSeries, 'raisePropertyChanged', ['ActualFillScale:vz:wg', [ValueBrushScale.$, null], 'FillScale:v0:wh', [ValueBrushScale.$, null], 'ValueMemberAsLegendLabel:v6:wi', [2, null], 'ValueMemberAsLegendUnit:v8:wj', [2, null], 'ValueMemberPath:wa:wk', [2, null]]);
    return ScatterContourSeries;
}(ScatterTriangulationSeries));
export { ScatterContourSeries };
/**
 * @hidden
 */
var ScatterContourSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScatterContourSeriesView, _super);
    function ScatterContourSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.b2 = null;
        _this.b1 = null;
        _this.b4 = null;
        _this.b3 = new List$1(Brush.$, 0);
        _this.b0 = null;
        _this.b4 = new List$1(Path.$, 0);
        _this.b1 = a;
        _this.b2 = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.cb);
            $ret.destroy = runOn(_this, _this.b9);
            $ret.activate = runOn(_this, _this.b7);
            $ret.disactivate = runOn(_this, _this.b8);
            return $ret;
        })());
        return _this;
    }
    ScatterContourSeriesView.prototype.cb = function () {
        var _this = this;
        var a = new Path();
        a.dataContext = ((function () {
            var $ret = new DataContext();
            $ret.series = _this.e;
            return $ret;
        })());
        this.b4.add(a);
        return a;
    };
    ScatterContourSeriesView.prototype.b7 = function (a) {
        a._visibility = 0;
    };
    ScatterContourSeriesView.prototype.b8 = function (a) {
        a._visibility = 1;
    };
    ScatterContourSeriesView.prototype.b9 = function (a) {
        this.b4.remove(a);
    };
    ScatterContourSeriesView.prototype.b5 = function (a, b) {
        var c = 0;
        this.b0 = b;
        this.b3.clear();
        var d = this.b1.vz;
        for (var e = 0; e < b.length; e++) {
            var f = b[e];
            var g = a._inner[c];
            var h = new PathGeometry();
            var _loop_1 = function (i) {
                var j = g._inner[i];
                if (j.count == 0) {
                    return "continue";
                }
                var k = PointCollectionUtil.f(j);
                var l = ((function () {
                    var $ret = new PathFigure();
                    $ret.isClosed = false;
                    $ret.isFilled = false;
                    $ret.startPoint = k._inner[0];
                    return $ret;
                })());
                l._segments.add(((function () {
                    var $ret = new PolyLineSegment();
                    $ret.points = k;
                    return $ret;
                })()));
                h.c.add(l);
            };
            for (var i = 0; i < g.count; i++) {
                _loop_1(i);
            }
            this.b2.item(c).an = h;
            if (this.b2.item(c).dataContext != null) {
                this.b2.item(c).dataContext.item = f;
            }
            if (d != null) {
                var m = d.getBrushByValue(f, this.b1.v2);
                if (m == null) {
                    m = this.e.su;
                }
                this.b3.add(m);
            }
            else {
                this.b3.add(this.e.su);
            }
            c++;
        }
        this.b2.count = c;
        this.as();
    };
    ScatterContourSeriesView.prototype.bg = function (a, b) {
        _super.prototype.bg.call(this, a, b);
        var c = a;
        c._stroke = this.b3._inner[b];
        c.ad = this.e.hl;
        if (c.y != null) {
            this.k.j(c, c.y);
        }
    };
    ScatterContourSeriesView.prototype.bh = function (a, b) {
        _super.prototype.bh.call(this, a, b);
        var c = a;
        var d = this.bs(b);
        c._stroke = d;
        c.ad = this.e.hl + 3;
    };
    ScatterContourSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        for (var c = 0; c < this.b4.count; c++) {
            var d = this.b4._inner[c];
            if (d._visibility != 1) {
                this.bf(d, c, b);
                a.t(d);
            }
        }
    };
    ScatterContourSeriesView.prototype.b6 = function (a) {
        this.b2.count = 0;
        this.as();
    };
    ScatterContourSeriesView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        var b = new List$1(Tuple$2.$.specialize(Number_$type, Path.$), 0);
        if (this.b0 != null) {
            for (var c = 0; c < this.b2.count; c++) {
                b.add(new Tuple$2(Number_$type, Path.$, this.b0[c], this.b2.item(c)));
            }
        }
        b.aa(function (d, e) {
            if (d.c < e.c) {
                return -1;
            }
            else if (d.c > e.c) {
                return 1;
            }
            return 0;
        });
        for (var d = 0; d < b.count; d++) {
            var e = typeCast(Path.$, b._inner[d].d);
            if (e._visibility != 1) {
                this.e.a5.exportPathData(a, e, "contour" + d, ["Main "]);
            }
        }
    };
    ScatterContourSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.e.a3.a$r(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.b1.title + "</span><br/>";
        if (!stringIsNullOrEmpty(this.b1.wa)) {
            a += "<span>Value: ${item}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterContourSeriesView.prototype.ca = function (a, b) {
        for (var c = 0; c < this.b4.count; c++) {
            var d = this.b4._inner[c];
            var e = typeCast(PathGeometry.$, d.an);
            if (e != null) {
                for (var f = 0; f < e.c.count; f++) {
                    var g = e.c._inner[f];
                    var h = e.c._inner[f]._startPoint;
                    for (var i = 0; i < g._segments.count; i++) {
                        var j = typeCast(PolyLineSegment.$, g._segments._inner[i]);
                        if (j != null) {
                            var k = this.b1.hl / 2 + this.b1.hz(b);
                            if (j._points.count > 0 && GeometryUtil.b(a, h, j._points, k)) {
                                return d;
                            }
                        }
                    }
                }
            }
        }
        return null;
    };
    ScatterContourSeriesView.$t = markType(ScatterContourSeriesView, 'ScatterContourSeriesView', SeriesView.$);
    return ScatterContourSeriesView;
}(SeriesView));
export { ScatterContourSeriesView };
