/*
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 * as tslib_1 from "tslib";
import { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { SplineType_$type } from "./SplineType";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { ScalerParams } from "./ScalerParams";
import { CollisionAvoider } from "./CollisionAvoider";
import { ISortingAxis_$type } from "./ISortingAxis";
import { Type, typeCast, Point_$type, enumGetBox, markType } from "igniteui-react-core/ES5/type";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
import { SafeSortedReadOnlyDoubleCollection } from "./SafeSortedReadOnlyDoubleCollection";
import { Numeric } from "igniteui-react-core/ES5/Numeric";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { truncate, isNaN_ } from "igniteui-react-core/ES5/number";
import { Color } from "igniteui-react-core/ES5/Color";
var SplineSeriesBase = /** @class */ (function (_super) {
    tslib_1.__extends(SplineSeriesBase, _super);
    function SplineSeriesBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.p6 = null;
        return _this;
    }
    SplineSeriesBase.prototype.bf = function () {
        return new SplineSeriesBaseView(this);
    };
    SplineSeriesBase.prototype.ii = function (a) {
        _super.prototype.ii.call(this, a);
        this.p7 = a;
    };
    SplineSeriesBase.prototype.get_cj = function () {
        return true;
    };
    Object.defineProperty(SplineSeriesBase.prototype, "cj", {
        get: function () {
            return this.get_cj();
        },
        enumerable: true,
        configurable: true
    });
    SplineSeriesBase.prototype.qd = function (a, b, c, d, e, f) {
        var _this = this;
        var g = typeCast(ISortingAxis_$type, d);
        var h = this.getEffectiveViewport1(f);
        if (g == null) {
            return;
        }
        var i = new ScalerParams(0, b, c, d.b8, h);
        var j = new ScalerParams(0, b, c, e.b8, h);
        var k = this.lr();
        var l = 0;
        var m = this.qb(d, b, c, h);
        var n = function (o) { return o; };
        var o = function (p) { return _this.valueColumn.item(g.i$b._inner[p]); };
        var p = this.m3.cl.f;
        var q = this.m3.cl.e;
        var r = truncate(Math.ceil(c.width / (p - q)));
        var s = new CollisionAvoider();
        var t = this.m3.cl.d;
        if (t <= 0 || (q <= 0 && p <= 0)) {
            this.m3.co.count = l;
            return;
        }
        var u = 0;
        var v = 0;
        for (var w = q; w < p + 1; ++w) {
            var x = null;
            var y = w * t;
            if (g != null && g.i$b != null && y >= 0 && y < g.i$b.count) {
                y = g.i$b._inner[y];
            }
            if (w >= (this.valueColumn.count - 1)) {
                if (k && this.p9(a, a.f._inner[a.f.count - 1], s, Math.min(y, this.bz.count - 1), l, f, u - 1)) {
                    ++l;
                }
                break;
            }
            var z = n(w);
            var aa = o(w);
            var ab = n(w + 1);
            var ac = o(w + 1);
            var ad = ab - z;
            var ae = this.p6[w];
            var af = this.p6[w + 1];
            var ag = g.i$d(g.i$b._inner[w]);
            var ah = d.dt(ag, i) + m;
            var ai = e.dt(aa, j);
            a.f.add([ah, ai, ai]);
            u++;
            v = u;
            for (var aj = 1; aj < r; ++aj) {
                var ak = aj / r;
                var al = z + ad * ak;
                var am = (ab - al) / ad;
                var an = (al - z) / ad;
                var ao = am * aa + an * ac + ((am * am * am - am) * ae + (an * an * an - an) * af) * (ad * ad) / 6;
                var ap = g.i$d(g.i$b._inner[w]);
                var aq = g.i$d(g.i$b._inner[w + 1]);
                var ar = ap + (aq - ap) * ak;
                al = d.dt(ar, i) + m;
                ao = e.dt(ao, j);
                a.f.add([al, ao, ao]);
                u++;
            }
            if (k) {
                x = [ah, ai, ai];
            }
            if (k && this.p9(a, x, s, Math.min(y, this.bz.count - 1), l, f, v - 1)) {
                ++l;
            }
        }
        f.co.count = l;
    };
    SplineSeriesBase.prototype.p9 = function (a, b, c, d, e, f, g) {
        var h = b[0];
        var i = b[1];
        var j = new Rect(0, h - 5, i - 5, 11, 11);
        if (!isNaN_(h) && !isNaN_(i) && c.tryAdd(j)) {
            a.m.add({ $type: Point_$type, x: h, y: i });
            var k = f.co.item(e);
            k.content.item = this.bz.item(d);
            k.al = g;
            return true;
        }
        return false;
    };
    SplineSeriesBase.prototype.aj = function (a, b, c, d, e, f) {
        if (a == null || a.cc || this.nv(this.bi) > 1 || this.nv(this.bi) == 0) {
            return _super.prototype.aj.call(this, this.mu(), this.mv.f, this.nv(this.bi), this.nw(this.bi), e, f);
        }
        var g = this.p7.cl.f;
        var h = this.bi.bp;
        var i = truncate(Math.ceil(h.width / (g - d)));
        var j = -1;
        var k = -1;
        var l = this.d6(e);
        var m = this.e8(e, f);
        var n = this.e6(e, f);
        var o = truncate(Math.floor(m / this.nv(this.bi)));
        var p = truncate(Math.floor(n / this.nv(this.bi)));
        j = o - this.nw(this.bi);
        k = p - this.nw(this.bi);
        var q = j * i;
        var r = k * i;
        var s = 0;
        if (m != n) {
            s = (l - m) / (n - m);
        }
        var t = truncate(Math.floor(q + s * (r - q)));
        j = t;
        k = t + 1;
        if (j < 0) {
            j = 0;
        }
        if (j > this.mv.f.count - 1) {
            j = this.mv.f.count - 1;
        }
        if (k < 0) {
            k = 0;
        }
        if (k > this.mv.f.count - 1) {
            k = this.mv.f.count - 1;
        }
        var u = this.mv.f._inner[j];
        var v = this.mv.f._inner[k];
        var w = new Array(2);
        w[0] = u;
        w[1] = v;
        return w;
    };
    SplineSeriesBase.prototype.n8 = function (a, b) {
        var _this = this;
        _super.prototype.n8.call(this, a, b);
        if (a.f.count <= 1) {
            return;
        }
        if (b.cl.d == 0) {
            return;
        }
        var c = b.bq;
        var d = b.bp;
        var e = this.getEffectiveViewport1(b);
        var f = this.pn;
        var g = this.pt;
        var h = new ScalerParams(0, c, d, f.b8, e);
        var i = ((function () {
            var $ret = new ScalerParams(0, c, d, g.b8, e);
            $ret.b = _this.ec();
            return $ret;
        })());
        a.f.clear();
        a.m.clear();
        var j = this.lr();
        var k = 0;
        var l = typeCast(ISortingAxis_$type, this.pn);
        if (l != null && l.i$b.count != this.bz.count) {
            return;
        }
        var m = this.qb(f, c, d, e);
        var n = function (o) { return o; };
        var o = function (p) { return _this.valueColumn.item(p); };
        var p = b.cl.d;
        if ((this.p6 == null || this.p6.length != this.valueColumn.count) && p == 1) {
            var q = this.p8 == 0 ? NaN : 0;
            if (this.pn != null && typeCast(ISortingAxis_$type, this.pn) !== null && this.pn.i$b != null) {
                var r_1 = new SafeSortedReadOnlyDoubleCollection(1, this.valueColumn, this.pn.i$b, NaN);
                o = function (s) { return r_1.item(s); };
            }
            this.p6 = Numeric.c(this.valueColumn.count, n, o, q, q);
        }
        var s = b.cl.f;
        var t = b.cl.e;
        var u = truncate(Math.ceil(d.width / (s - t)));
        var v = new CollisionAvoider();
        if (l != null) {
            this.qd(a, c, d, f, g, b);
            return;
        }
        var w = b;
        w.c0();
        var x = 0;
        var y = 0;
        for (var z = t; z <= s; ++z) {
            var aa = null;
            if (p == 1) {
                if (z >= (this.valueColumn.count - 1)) {
                    if (j && this.p9(a, a.f._inner[a.f.count - 1], v, Math.min(z * p, this.bz.count - 1), k, b, x - 1)) {
                        ++k;
                    }
                    break;
                }
                var ab = n(z);
                var ac = o(z);
                var ad = n(z + 1);
                var ae = o(z + 1);
                var af = ad - ab;
                var ag = this.p6[z];
                var ah = this.p6[z + 1];
                var ai = f.dt(ab, h) + m;
                var aj = g.dt(ac, i);
                a.f.add([ai, aj, aj]);
                x++;
                y = x;
                for (var ak = 1; ak < u; ++ak) {
                    var al = ab + af * ak / u;
                    var am = (ad - al) / af;
                    var an = (al - ab) / af;
                    var ao = am * ac + an * ae + ((am * am * am - am) * ag + (an * an * an - an) * ah) * (af * af) / 6;
                    al = f.dt(al, h) + m;
                    ao = g.dt(ao, i);
                    a.f.add([al, ao, ao]);
                    x++;
                }
                if (j) {
                    aa = b.cl.getBucket(z);
                    aa[0] = (f.dt(aa[0], h) + m);
                    aa[1] = g.dt(aa[1], i);
                    aa[2] = g.dt(aa[2], i);
                }
            }
            else {
                aa = b.cl.getBucket(z);
                if (!isNaN_(aa[0])) {
                    aa[0] = (f.dt(aa[0], h) + m);
                    aa[1] = g.dt(aa[1], i);
                    aa[2] = g.dt(aa[2], i);
                    a.f.add(aa);
                    x++;
                }
            }
            if (j && this.p9(a, aa, v, Math.min(z * p, this.bz.count - 1), k, b, y - 1)) {
                ++k;
            }
        }
        w.c2();
        b.co.count = k;
    };
    SplineSeriesBase.prototype.qa = function (a, b, c, d, e, f, g) {
        var h = d - b;
        var i = b + h * a;
        var j = (d - i) / h;
        var k = (i - b) / h;
        var l = j * c + k * e + ((j * j * j - j) * f + (k * k * k - k) * g) * (h * h) / 6;
        return l;
    };
    SplineSeriesBase.prototype.ea = function (a, b, c, d, e, f, g, h) {
        var i = NaN;
        if (c >= 0 && c < b.count) {
            i = b.item(c);
        }
        var j = NaN;
        if (d >= 0 && d < b.count) {
            j = b.item(d);
        }
        if (f == 0) {
            return j;
        }
        if (e == b.count - 1) {
            return i;
        }
        if (isNaN_(j) && g != 0 && a <= 0.5 && !h) {
            return i;
        }
        if (isNaN_(i) && g != 0 && a >= 0.5 && !h) {
            return j;
        }
        var k = e;
        var l = f;
        var m = i;
        var n = j;
        var o = NaN;
        var p = NaN;
        if (this.p6 != null && e >= 0 && e < this.p6.length) {
            o = this.p6[e];
        }
        if (this.p6 != null && f >= 0 && f < this.p6.length) {
            p = this.p6[f];
        }
        return this.qa(a, k, m, l, n, o, p);
    };
    SplineSeriesBase.prototype.qb = function (a, b, c, d) {
        var e = this.preferredCategoryMode(a);
        if (e == 0 && a.categoryMode != 0) {
            e = 1;
        }
        var f = 0;
        switch (e) {
            case 0:
                f = 0;
                break;
            case 1:
                f = 0.5 * a.getCategorySize(b, c, d);
                break;
            case 2:
                f = a.getGroupCenter(this.fb, b, c, d);
                break;
        }
        if (a.b8) {
            f = -f;
        }
        return f;
    };
    SplineSeriesBase.prototype.qe = function () {
        this.p6 = null;
    };
    SplineSeriesBase.prototype.io = function (a, b, c, d) {
        switch (b) {
            case "ValueColumn":
            case "FastItemsSource":
                this.qe();
                break;
        }
        _super.prototype.io.call(this, a, b, c, d);
        switch (b) {
            case SplineSeriesBase.$$p[0]:
                this.qe();
                this.i1(false);
                this.h8();
                break;
        }
    };
    SplineSeriesBase.prototype.ho = function (a, b, c, d) {
        this.qe();
        _super.prototype.ho.call(this, a, b, c, d);
    };
    Object.defineProperty(SplineSeriesBase.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.nq;
        },
        enumerable: true,
        configurable: true
    });
    SplineSeriesBase.$t = markType(SplineSeriesBase, 'SplineSeriesBase', HorizontalAnchoredCategorySeries.$);
    return SplineSeriesBase;
}(HorizontalAnchoredCategorySeries));
export { SplineSeriesBase };
Type.dep(DependencyProperty, PropertyMetadata, SplineSeriesBase, 'raisePropertyChanged', ['SplineType:p8:qf', [SplineType_$type, enumGetBox(SplineType_$type, 0)]]);
var SplineSeriesBaseView = /** @class */ (function (_super) {
    tslib_1.__extends(SplineSeriesBaseView, _super);
    function SplineSeriesBaseView(a) {
        var _this = _super.call(this, a) || this;
        _this.c4 = null;
        _this.c4 = a;
        return _this;
    }
    SplineSeriesBaseView.prototype.ac = function () {
        var a = new Color();
        a.colorString = "rgba(95,95,95,0.5)";
        this.e.ky = a;
        this.e.ep = 3;
        this.e.eq = 1;
        this.e.er = 4;
        this.e.dr = false;
    };
    SplineSeriesBaseView.$t = markType(SplineSeriesBaseView, 'SplineSeriesBaseView', AnchoredCategorySeriesView.$);
    return SplineSeriesBaseView;
}(AnchoredCategorySeriesView));
export { SplineSeriesBaseView };
/*<BeginStatics Name="Infragistics.Controls.Charts.SplineSeriesBase" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.SplineSeriesBase" />*/
