/*
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-angular-core";
import { Point_$type, typeCast, Number_$type, fromEnum, runOn, delegateRemove, delegateCombine, markType, markDep } from "igniteui-angular-core";
import { ValueBrushScale } from "./ValueBrushScale";
import { FastItemIntColumn } from "igniteui-angular-core";
import { LinearContourValueResolver } from "./LinearContourValueResolver";
import { SeriesView } from "./SeriesView";
import { DataLegendSeriesValueInfo } from "igniteui-angular-core";
import { DataLegendSeriesContext } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { ContourBuilder } from "./ContourBuilder";
import { Clipper } from "igniteui-angular-core";
import { RectUtil } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { BrushCollection } from "igniteui-angular-core";
import { DataContext } from "igniteui-angular-core";
import { Path } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { boxArray$1 } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { PathGeometry } from "igniteui-angular-core";
import { PathFigure } from "igniteui-angular-core";
import { PolyLineSegment } from "igniteui-angular-core";
import { PointCollectionUtil } from "igniteui-angular-core";
import { Tuple$2 } from "igniteui-angular-core";
import { GeometryUtil } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
/**
 * @hidden
 */
var ScatterContourSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScatterContourSeries, _super);
    function ScatterContourSeries() {
        var _this = _super.call(this) || this;
        _this.r1 = null;
        _this.rw = null;
        FastItemIntColumn.m();
        _this.ab = ScatterContourSeries.$;
        _this.rx = new LinearContourValueResolver();
        return _this;
    }
    ScatterContourSeries.prototype.get_d0 = function () {
        return true;
    };
    ScatterContourSeries.prototype.hw = function (a, b) {
        var c = this.jq(b);
        if (c == ScatterContourSeries.$$p[4]) {
            return this.hx(a, b, this.sa);
        }
        return _super.prototype.hw.call(this, a, b);
    };
    ScatterContourSeries.prototype.bx = function () {
        this.ry = new ScatterContourSeriesView(this);
        return this.ry;
    };
    Object.defineProperty(ScatterContourSeries.prototype, "r2", {
        get: function () {
            return this.r1;
        },
        set: function (a) {
            var b = this.r2 != a;
            if (b) {
                var c = this.r2;
                this.r1 = a;
                this.raisePropertyChanged("ValueColumn", c, this.r2);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterContourSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.ht(c);
        var e = d == null ? NaN : this.gb(d, "XMemberPath");
        var f = d == null ? NaN : this.gb(d, "YMemberPath");
        var g = d == null ? NaN : this.gb(d, "ValueMemberPath");
        var h = new DataLegendSeriesValueInfo();
        h.a = 13;
        h.l = e;
        h.p = this.q5 != null ? this.q5 : "X";
        h.q = this.q1 != null ? this.q1 : "X:";
        h.r = this.q3 != null ? this.q3 : "";
        var i = new DataLegendSeriesValueInfo();
        i.a = 14;
        i.l = f;
        i.p = this.rd != null ? this.rd : "Y";
        i.q = this.q9 != null ? this.q9 : "Y:";
        i.r = this.rb != null ? this.rb : "";
        var j = new DataLegendSeriesValueInfo();
        j.a = 0;
        j.l = g;
        j.p = this.sa != null ? this.sa : "Value";
        j.q = this.r6 != null ? this.r6 : "V:";
        j.r = this.r8 != null ? this.r8 : "";
        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.av();
        return k;
    };
    ScatterContourSeries.prototype.l3 = function (a, b, c, d) {
        _super.prototype.l3.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.r2);
                    this.r2 = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.r2 = this.ch(this.sa);
                }
                this.mh(false);
                break;
            case ScatterContourSeries.$$p[4]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.r2);
                    this.r2 = this.ch(this.sa);
                }
                this.mh(false);
                this.lo();
                break;
            case "ValueResolver":
                this.mh(false);
                this.lo();
                break;
            case ScatterContourSeries.$$p[1]:
                var g = c;
                var h = d;
                if (g != null) {
                    g.unregisterSeries(this);
                }
                if (h != null) {
                    h.registerSeries(this);
                }
                this.se();
                this.mh(false);
                this.lo();
                break;
            case "ActualBrush":
                this.se();
                this.mh(false);
                this.lo();
                break;
        }
    };
    ScatterContourSeries.prototype.kx = function (a, b) {
        _super.prototype.kx.call(this, a, b);
        if (a) {
            b.b3(a);
        }
    };
    ScatterContourSeries.prototype.mi = function (a) {
        _super.prototype.mi.call(this, a);
        this.sd(this.b0);
    };
    ScatterContourSeries.prototype.mg = function (a, b, c, d, e) {
        _super.prototype.mg.call(this, a, b, c, d, e);
        var f = this.a6.a$h.item(d);
        f.a1(c);
        if (this.cx(f)) {
            return;
        }
        this.sd(f);
    };
    ScatterContourSeries.prototype.sd = function (a) {
        var e_1, _a;
        if (this.cx(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.p3.cg);
        f.c = this.getEffectiveViewport1(a);
        var g = new ScalerParams(1, b, c, this.p4.cg);
        g.c = this.getEffectiveViewport1(a);
        var h = this.p3;
        var i = this.p4;
        var j = this.qd.count;
        var k;
        var xArr_ = this.qg.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.qh.asArray();
        l = (yArr_.slice(0));
        var m = this.r2.asArray();
        var n = this.qd.asArray();
        var o = this.qe.asArray();
        var p = this.qf.asArray();
        var q = this.rx.j(this.r2);
        var r = new List$1(Number_$type, 1, q).toArray();
        h.hm(boxArray$1(k), 0, k.length, f);
        i.hm(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.b2(ay, r);
    };
    ScatterContourSeries.prototype.mv = function () {
        _super.prototype.mv.call(this);
        this.se();
    };
    ScatterContourSeries.prototype.se = function () {
        var e_2, _a;
        var a = this.oy;
        if (a == null) {
            a = this.o2;
        }
        if (a == null) {
            a = BrushUtil.g(255, 255, 255, 255);
        }
        var b = new ValueBrushScale();
        b.brushes = new BrushCollection();
        if (this.r0 == null || this.r0.brushes == null || this.r0.brushes.count == 0) {
            b.brushes.add(BrushUtil.l(a, -0.5));
            b.brushes.add(a);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.r0.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.r0 != null) {
            if (!isNaN_(this.r0.minimumValue)) {
                b.minimumValue = this.r0.minimumValue;
            }
            if (!isNaN_(this.r0.maximumValue)) {
                b.maximumValue = this.r0.maximumValue;
            }
            b.logarithmBase = this.r0.logarithmBase;
            b.isLogarithmic = this.r0.isLogarithmic;
        }
        this.rz = b;
    };
    Object.defineProperty(ScatterContourSeries.prototype, "rx", {
        get: function () {
            return this.rw;
        },
        set: function (a) {
            var b = a != this.rx;
            if (b) {
                if (this.rw != null) {
                    var c = this.rw;
                    c.updated = delegateRemove(c.updated, runOn(this, this.sf));
                }
                var d = this.rw;
                this.rw = a;
                if (this.rw != null) {
                    var e = this.rw;
                    e.updated = delegateCombine(e.updated, runOn(this, this.sf));
                }
                this.raisePropertyChanged("ValueResolver", d, a);
                this.mh(false);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterContourSeries.prototype.sf = function (a, b) {
        this.mh(false);
    };
    ScatterContourSeries.prototype.e9 = function (a, b, c) {
        return _super.prototype.e9.call(this, a, b, c) && this.rx != null && this.qg != null && this.qh != null && this.qd != null && this.qe != null && this.qf != null && this.qg.count > 0 && this.qh.count > 0 && this.qd.count > 0 && this.qe.count > 0 && this.qf.count > 0;
    };
    ScatterContourSeries.prototype.at = function (a, b) {
        var c = this.ry.b7(a, b);
        if (c != null) {
            return c.dataContext;
        }
        return null;
    };
    ScatterContourSeries.$t = markType(ScatterContourSeries, 'ScatterContourSeries', ScatterTriangulationSeries.$);
    ScatterContourSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterContourSeries, 'raisePropertyChanged', ['ActualFillScale:rz:sg', [ValueBrushScale.$, null], 'FillScale:r0:sh', [ValueBrushScale.$, null], 'ValueMemberAsLegendLabel:r6:si', [2, null], 'ValueMemberAsLegendUnit:r8:sj', [2, null], 'ValueMemberPath:sa:sk', [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.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 = ((function () {
            var $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;
        })());
        return _this;
    }
    ScatterContourSeriesView.prototype.b8 = function () {
        var _this = this;
        var a = new Path();
        a.dataContext = ((function () {
            var $ret = new DataContext();
            $ret.series = _this.e;
            return $ret;
        })());
        this.b1.add(a);
        return a;
    };
    ScatterContourSeriesView.prototype.b4 = function (a) {
        a._visibility = 0;
    };
    ScatterContourSeriesView.prototype.b5 = function (a) {
        a._visibility = 1;
    };
    ScatterContourSeriesView.prototype.b6 = function (a) {
        this.b1.remove(a);
    };
    ScatterContourSeriesView.prototype.b2 = function (a, b) {
        var c = 0;
        this.bx = b;
        this.b0.clear();
        var d = this.by.rz;
        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.bz.item(c).ak = h;
            if (this.bz.item(c).dataContext != null) {
                this.bz.item(c).dataContext.item = f;
            }
            if (d != null) {
                var m = d.getBrushByValue(f, this.by.r2);
                if (m == null) {
                    m = this.e.oy;
                }
                this.b0.add(m);
            }
            else {
                this.b0.add(this.e.oy);
            }
            c++;
        }
        this.bz.count = c;
        this.aq();
    };
    ScatterContourSeriesView.prototype.be = function (a, b) {
        _super.prototype.be.call(this, a, b);
        var c = a;
        c._stroke = this.b0._inner[b];
        c.ac = this.e.fu;
        if (c.y != null) {
            this.k.i(c, c.y);
        }
    };
    ScatterContourSeriesView.prototype.bf = function (a, b) {
        _super.prototype.bf.call(this, a, b);
        var c = a;
        var d = this.bp(b);
        c._stroke = d;
        c.ac = this.e.fu + 3;
    };
    ScatterContourSeriesView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        for (var c = 0; c < this.b1.count; c++) {
            var d = this.b1._inner[c];
            if (d._visibility != 1) {
                this.bd(d, c, b);
                a.s(d);
            }
        }
    };
    ScatterContourSeriesView.prototype.b3 = function (a) {
        this.bz.count = 0;
        this.aq();
    };
    ScatterContourSeriesView.prototype.al = function (a) {
        _super.prototype.al.call(this, a);
        var b = new List$1(Tuple$2.$.specialize(Number_$type, Path.$), 0);
        if (this.bx != null) {
            for (var c = 0; c < this.bz.count; c++) {
                b.add(new Tuple$2(Number_$type, Path.$, this.bx[c], this.bz.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.a8.exportPathData(a, e, "contour" + d, ["Main "]);
            }
        }
    };
    ScatterContourSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.e.a6.a$r(this.e);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.by.title + "</span><br/>";
        if (!stringIsNullOrEmpty(this.by.sa)) {
            a += "<span>Value: ${item}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterContourSeriesView.prototype.b7 = function (a, b) {
        for (var c = 0; c < this.b1.count; c++) {
            var d = this.b1._inner[c];
            var e = typeCast(PathGeometry.$, d.ak);
            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.by.fu / 2 + this.by.f8(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 };
