/*
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 { PointCollectionUtil } from "igniteui-angular-core";
import { PolyLineSegment } 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.y6 = null;
        _this.y1 = null;
        FastItemIntColumn.m();
        _this.ab = ScatterContourSeries.$;
        _this.y2 = new LinearContourValueResolver();
        return _this;
    }
    ScatterContourSeries.prototype.bk = function () {
        return new ScatterContourSeries();
    };
    ScatterContourSeries.prototype.get_fk = function () {
        return true;
    };
    ScatterContourSeries.prototype.ku = function (a, b) {
        var c = this.ni(b);
        if (c == ScatterContourSeries.$$p[4]) {
            return this.kv(a, b, this.zf);
        }
        return _super.prototype.ku.call(this, a, b);
    };
    ScatterContourSeries.prototype.mi = function (a) {
        var b = this.ni(a);
        if (b == ScatterContourSeries.$$p[4]) {
            return this.zf;
        }
        return _super.prototype.mi.call(this, a);
    };
    ScatterContourSeries.prototype.ct = function () {
        this.y3 = new ScatterContourSeriesView(this);
        return this.y3;
    };
    Object.defineProperty(ScatterContourSeries.prototype, "y7", {
        get: function () {
            return this.y6;
        },
        set: function (a) {
            var b = this.y7 != a;
            if (b) {
                var c = this.y7;
                this.y6 = a;
                this.raisePropertyChanged("ValueColumn", c, this.y7);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterContourSeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = { $type: Point_$type, x: a, y: b };
        var d = this.kr(c);
        var e = d == null ? NaN : this.iz(d, "XMemberPath");
        var f = d == null ? NaN : this.iz(d, "YMemberPath");
        var g = d == null ? NaN : this.iz(d, "ValueMemberPath");
        var h = new DataLegendSeriesValueInfo();
        h.a = 13;
        h.l = e;
        h.q = "X";
        h.r = this.ya != null ? this.ya : "X";
        h.s = this.x6 != null ? this.x6 : "X:";
        h.t = this.x8 != null ? this.x8 : "";
        var i = new DataLegendSeriesValueInfo();
        i.a = 14;
        i.l = f;
        i.q = "Y";
        i.r = this.yi != null ? this.yi : "Y";
        i.s = this.ye != null ? this.ye : "Y:";
        i.t = this.yg != null ? this.yg : "";
        var j = new DataLegendSeriesValueInfo();
        j.a = 0;
        j.l = g;
        j.q = "Value";
        j.r = this.zf != null ? this.zf : "Value";
        j.s = this.zb != null ? this.zb : "V:";
        j.t = this.zd != null ? this.zd : "";
        var k = new DataLegendSeriesContext();
        k.e = ((function () {
            var $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
            $ret.add(h);
            $ret.add(i);
            $ret.add(j);
            return $ret;
        })());
        k.h = this.mh();
        return k;
    };
    ScatterContourSeries.prototype.rg = function (a, b, c, d) {
        _super.prototype.rg.call(this, a, b, c, d);
        switch (b) {
            case ScatterContourSeries.$$p[2]:
            case ScatterContourSeries.$$p[3]:
                this.ql();
                break;
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.y7);
                    this.y7 = null;
                }
                var f = typeCast(IFastItemsSource_$type, d);
                if (f != null) {
                    this.y7 = this.dl(this.zf);
                }
                this.ry(this.gh && c != null);
                break;
            case ScatterContourSeries.$$p[4]:
                if (this.dp != null) {
                    this.dp.deregisterColumn(this.y7);
                    this.y7 = this.dl(this.zf);
                }
                this.ry(false);
                this.qr();
                break;
            case "ValueResolver":
                this.ry(false);
                this.qr();
                break;
            case ScatterContourSeries.$$p[1]:
                var g = c;
                var h = d;
                if (g != null) {
                    g.unregisterSeries(this);
                }
                if (h != null) {
                    h.registerSeries(this);
                }
                this.zj();
                this.ry(false);
                this.qr();
                break;
            case "ActualBrush":
                this.zj();
                this.ry(false);
                this.qr();
                break;
        }
    };
    ScatterContourSeries.prototype.pb = function (a, b) {
        _super.prototype.pb.call(this, a, b);
        if (a) {
            b.cj(a);
        }
    };
    ScatterContourSeries.prototype.rz = function (a) {
        _super.prototype.rz.call(this, a);
        this.zi(this.cw);
    };
    ScatterContourSeries.prototype.rx = function (a, b, c, d, e) {
        _super.prototype.rx.call(this, a, b, c, d, e);
        var f = this.ba.a$j.item(d);
        f.bd(c);
        if (this.d7(f)) {
            return;
        }
        this.zi(f);
    };
    ScatterContourSeries.prototype.zi = function (a) {
        var e_1, _a;
        if (this.d7(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.w8.df);
        f.c = this.getEffectiveViewport1(a);
        var g = new ScalerParams(1, b, c, this.w9.df);
        g.c = this.getEffectiveViewport1(a);
        var h = this.w8;
        var i = this.w9;
        var j = this.xi.count;
        var k;
        var xArr_ = this.xl.asArray();
        k = (xArr_.slice(0));
        var l;
        var yArr_ = this.xm.asArray();
        l = (yArr_.slice(0));
        var m = this.y7.asArray();
        var n = this.xi.asArray();
        var o = this.xj.asArray();
        var p = this.xk.asArray();
        var q = this.y2.j(this.y7);
        var r = new List$1(Number_$type, 1, q).toArray();
        h.j6(boxArray$1(k), 0, k.length, f);
        i.j6(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.ci(ay, r);
    };
    ScatterContourSeries.prototype.sp = function () {
        _super.prototype.sp.call(this);
        this.zj();
    };
    ScatterContourSeries.prototype.zj = function () {
        var e_2, _a;
        var a = this.vj;
        if (a == null) {
            a = this.vp;
        }
        if (a == null) {
            a = BrushUtil.j(255, 255, 255, 255);
        }
        var b = new ValueBrushScale();
        b.brushes = new BrushCollection();
        if (this.y5 == null || this.y5.brushes == null || this.y5.brushes.count == 0) {
            b.brushes.add(BrushUtil.o(a, -0.5));
            b.brushes.add(a);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.y5.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.y5 != null) {
            if (!isNaN_(this.y5.minimumValue)) {
                b.minimumValue = this.y5.minimumValue;
            }
            if (!isNaN_(this.y5.maximumValue)) {
                b.maximumValue = this.y5.maximumValue;
            }
            b.logarithmBase = this.y5.logarithmBase;
            b.isLogarithmic = this.y5.isLogarithmic;
        }
        this.y4 = b;
    };
    Object.defineProperty(ScatterContourSeries.prototype, "y2", {
        get: function () {
            return this.y1;
        },
        set: function (a) {
            var b = a != this.y2;
            if (b) {
                if (this.y1 != null) {
                    var c = this.y1;
                    c.updated = delegateRemove(c.updated, runOn(this, this.zk));
                }
                var d = this.y1;
                this.y1 = a;
                if (this.y1 != null) {
                    var e = this.y1;
                    e.updated = delegateCombine(e.updated, runOn(this, this.zk));
                }
                this.raisePropertyChanged("ValueResolver", d, a);
                this.ry(false);
            }
        },
        enumerable: false,
        configurable: true
    });
    ScatterContourSeries.prototype.zk = function (a, b) {
        this.ry(false);
    };
    ScatterContourSeries.prototype.hf = function (a, b, c) {
        return _super.prototype.hf.call(this, a, b, c) && this.y2 != null && this.xl != null && this.xm != null && this.xi != null && this.xj != null && this.xk != null && this.xl.count > 0 && this.xm.count > 0 && this.xi.count > 0 && this.xj.count > 0 && this.xk.count > 0;
    };
    ScatterContourSeries.prototype.a2 = function (a, b) {
        var c = this.y3.cn(a, b);
        if (c != null) {
            return c.dataContext;
        }
        return null;
    };
    ScatterContourSeries.$t = markType(ScatterContourSeries, 'ScatterContourSeries', ScatterTriangulationSeries.$);
    ScatterContourSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ScatterContourSeries, 'raisePropertyChanged', ['ActualFillScale:y4:zl', [ValueBrushScale.$, null], 'FillScale:y5:zm', [ValueBrushScale.$, null], 'ValueMemberAsLegendLabel:zb:zn', [2, null], 'ValueMemberAsLegendUnit:zd:zo', [2, null], 'ValueMemberPath:zf:zp', [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.cf = null;
        _this.ce = null;
        _this.ch = null;
        _this.cg = new List$1(Brush.$, 0);
        _this.cd = null;
        _this.ch = new List$1(Path.$, 0);
        _this.ce = a;
        _this.cf = ((function () {
            var $ret = new Pool$1(Path.$);
            $ret.create = runOn(_this, _this.co);
            $ret.destroy = runOn(_this, _this.cm);
            $ret.activate = runOn(_this, _this.ck);
            $ret.disactivate = runOn(_this, _this.cl);
            return $ret;
        })());
        return _this;
    }
    ScatterContourSeriesView.prototype.co = function () {
        var _this = this;
        var a = new Path();
        a.dataContext = ((function () {
            var $ret = new DataContext();
            $ret.series = _this.f;
            return $ret;
        })());
        this.ch.add(a);
        return a;
    };
    ScatterContourSeriesView.prototype.ck = function (a) {
        a._visibility = 0;
    };
    ScatterContourSeriesView.prototype.cl = function (a) {
        a._visibility = 1;
    };
    ScatterContourSeriesView.prototype.cm = function (a) {
        this.ch.remove(a);
    };
    ScatterContourSeriesView.prototype.ci = function (a, b) {
        var c = 0;
        this.cd = b;
        this.cg.clear();
        var d = this.ce.y4;
        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.cf.item(c).an = h;
            if (this.cf.item(c).dataContext != null) {
                this.cf.item(c).dataContext.item = f;
            }
            if (d != null) {
                var m = d.getBrushByValue(f, this.ce.y7);
                if (m == null) {
                    m = this.f.vj;
                }
                this.cg.add(m);
            }
            else {
                this.cg.add(this.f.vj);
            }
            c++;
        }
        this.cf.count = c;
        this.a2();
    };
    ScatterContourSeriesView.prototype.bs = function (a, b) {
        _super.prototype.bs.call(this, a, b);
        var c = a;
        c._stroke = this.cg._inner[b];
        c.ad = this.f.ig;
        if (c.y != null) {
            this.m.j(c, c.y);
        }
    };
    ScatterContourSeriesView.prototype.bt = function (a, b) {
        _super.prototype.bt.call(this, a, b);
        var c = a;
        var d = this.b4(b);
        c._stroke = d;
        c.ad = this.f.ig + 3;
    };
    ScatterContourSeriesView.prototype.bj = function (a, b) {
        _super.prototype.bj.call(this, a, b);
        for (var c = 0; c < this.ch.count; c++) {
            var d = this.ch._inner[c];
            if (d._visibility != 1) {
                this.br(d, c, b);
                a.t(d);
            }
        }
    };
    ScatterContourSeriesView.prototype.cj = function (a) {
        this.cf.count = 0;
        this.a2();
    };
    ScatterContourSeriesView.prototype.ax = function (a) {
        _super.prototype.ax.call(this, a);
        var b = new List$1(Tuple$2.$.specialize(Number_$type, Path.$), 0);
        if (this.cd != null) {
            for (var c = 0; c < this.cf.count; c++) {
                b.add(new Tuple$2(Number_$type, Path.$, this.cd[c], this.cf.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.f.bc.exportPathData(a, e, "contour" + d, ["Main "]);
            }
        }
    };
    ScatterContourSeriesView.prototype.getDefaultTooltipTemplate = function () {
        var a = "<div class='ui-chart-default-tooltip-content'><span";
        var b = this.f.ba.a$u(this.f);
        if (!stringIsNullOrEmpty(b)) {
            a += " style='color:" + b + "'";
        }
        a += ">" + this.ce.title + "</span><br/>";
        if (!stringIsNullOrEmpty(this.ce.zf)) {
            a += "<span>Value: ${item}</span>";
        }
        a += "</div>";
        return a;
    };
    ScatterContourSeriesView.prototype.cn = function (a, b) {
        for (var c = 0; c < this.ch.count; c++) {
            var d = this.ch._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.ce.ig / 2 + this.ce.iw(b);
                            if (j._points.count > 0 && GeometryUtil.e(a, h, j._points, k)) {
                                return d;
                            }
                        }
                    }
                }
            }
        }
        return null;
    };
    ScatterContourSeriesView.$t = markType(ScatterContourSeriesView, 'ScatterContourSeriesView', SeriesView.$);
    return ScatterContourSeriesView;
}(SeriesView));
export { ScatterContourSeriesView };
