/*
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 } from "tslib";
import { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { DependencyProperty } from "igniteui-react-core";
import { SplineType_$type } from "./SplineType";
import { AxisRange } from "./AxisRange";
import { Array_$type, typeCast, Point_$type, enumGetBox, markType, markDep } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { ISortingAxis_$type } from "./ISortingAxis";
import { CollisionAvoider } from "./CollisionAvoider";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
import { ScalerParams } from "./ScalerParams";
import { SafeSortedReadOnlyDoubleCollection } from "./SafeSortedReadOnlyDoubleCollection";
import { Numeric } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_ } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
/**
 * @hidden
 */
var SplineSeriesBase = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(SplineSeriesBase, _super);
    function SplineSeriesBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.ace = null;
        _this.ack = NaN;
        _this.acj = NaN;
        return _this;
    }
    SplineSeriesBase.prototype.ji = function () {
        if (!isNaN_(this.jh)) {
            return _super.prototype.ji.call(this);
        }
        return this.acf.dg();
    };
    SplineSeriesBase.prototype.cq = function () {
        return new SplineSeriesBaseView(this);
    };
    SplineSeriesBase.prototype.qw = function (a) {
        _super.prototype.qw.call(this, a);
        this.acf = a;
    };
    SplineSeriesBase.prototype.rx = function (a) {
        _super.prototype.rx.call(this, a);
        this.ach = true;
    };
    SplineSeriesBase.prototype.ax = function (a) {
        if (!this.ach || this.ace == null || this.ace.length == 0) {
            return _super.prototype.ax.call(this, a);
        }
        if (this.valueColumn == null || this.valueColumn.count == 0) {
            return null;
        }
        if (a == this.fetchXAxis()) {
            return new AxisRange(0, this.valueColumn.count - 1);
        }
        this.acr(this.acf);
        if (this.ace == null || this.ace.length == 0) {
            return null;
        }
        if (a == this.fetchYAxis()) {
            if (isNaN_(this.acn) || isNaN_(this.aco)) {
                return null;
            }
            return new AxisRange(this.aco, this.acn);
        }
        return null;
    };
    SplineSeriesBase.prototype.get_et = function () {
        return true;
    };
    SplineSeriesBase.prototype.acc = function (a) {
        var _this = this;
        if (a.cw.d == 0) {
            return null;
        }
        var b = new List$1(Array_$type, 0);
        var c = a.by;
        var d = a.bx;
        var e = this.getEffectiveViewport1(a);
        var f = 0;
        var g = 0;
        var h = 0;
        var i = this;
        var j = typeCast(CategoryAxisBase.$, i.fetchXAxis());
        var k = i.wc(this.ct);
        var l = i.dl;
        if (c.isEmpty || d.isEmpty || j == null || l == null || l.count == 0) {
            f = 0;
            return null;
        }
        var m = this.ib;
        var n = typeCast(ISortingAxis_$type, j);
        if (n == null || n.i$b == null) {
            var o = new ScalerParams(0, c, d, j.ch, e);
            var p = 0;
            var q = j.lh - 1;
            var r = Math.floor((q - p + 1) * m / k.width);
            f = truncate(Math.max(1, r));
            g = truncate(Math.max(0, Math.floor(p / f) - 1));
            h = truncate(Math.ceil(q / f));
        }
        else {
            g = 0;
            h = j.lh - 1;
            f = 1;
        }
        if (n != null && n.i$b.count != this.dl.count) {
            return null;
        }
        this.acr(a);
        var s = truncate(Math.ceil(d.width / (h - g)));
        var t = new CollisionAvoider();
        if (n != null) {
            return this.acd(a);
        }
        var u = function (v) { return v; };
        var v = function (w) { return _this.valueColumn.item(w); };
        var w = a;
        w.db();
        for (var x = g; x <= h; ++x) {
            var y = null;
            if (f == 1) {
                if (x >= (this.valueColumn.count - 1)) {
                    break;
                }
                var z = u(x);
                var aa = v(x);
                var ab = u(x + 1);
                var ac = v(x + 1);
                var ad = ab - z;
                var ae = this.ace[x];
                var af = this.ace[x + 1];
                b.add([aa, ac]);
                for (var ag = 1; ag < s; ++ag) {
                    var ah = z + ad * ag / s;
                    var ai = (ab - ah) / ad;
                    var aj = (ah - z) / ad;
                    var ak = ai * aa + aj * ac + ((ai * ai * ai - ai) * ae + (aj * aj * aj - aj) * af) * (ad * ad) / 6;
                    b.add([ak, ak]);
                }
            }
            else {
                y = a.cw.getBucket(x);
                if (!isNaN_(y[0])) {
                    b.add([y[1], y[2]]);
                }
            }
        }
        w.dd();
        return b.toArray();
    };
    SplineSeriesBase.prototype.acd = function (a) {
        var _this = this;
        var b = typeCast(ISortingAxis_$type, this.abt);
        var c = this.getEffectiveViewport1(a);
        var d = a.by;
        var e = a.bx;
        var f = new List$1(Array_$type, 0);
        if (b == null) {
            return null;
        }
        var g = this.abt;
        var h = 0;
        var i = 0;
        var j = 0;
        var k = this.ib;
        var l = this.wc(this.ct);
        if (b == null || b.i$b == null) {
            var m = new ScalerParams(0, d, e, g.ch, c);
            var n = 0;
            var o = g.lh - 1;
            var p = Math.floor((o - n + 1) * k / l.width);
            h = truncate(Math.max(1, p));
            i = truncate(Math.max(0, Math.floor(n / h) - 1));
            j = truncate(Math.ceil(o / h));
        }
        else {
            i = 0;
            j = g.lh - 1;
            h = 1;
        }
        var q = function (r) { return r; };
        var r = function (s) { return _this.valueColumn.item(b.i$b._inner[s]); };
        var s = truncate(Math.ceil(e.width / (j - i)));
        var t = new CollisionAvoider();
        if (h <= 0 || (i <= 0 && j <= 0)) {
            return null;
        }
        for (var u = i; u < j + 1; ++u) {
            var v = null;
            var w = u * h;
            if (b != null && b.i$b != null && w >= 0 && w < b.i$b.count) {
                w = b.i$b._inner[w];
            }
            if (u >= (this.valueColumn.count - 1)) {
                break;
            }
            var x = q(u);
            var y = r(u);
            var z = q(u + 1);
            var aa = r(u + 1);
            var ab = z - x;
            var ac = this.ace[u];
            var ad = this.ace[u + 1];
            f.add([y, y]);
            for (var ae = 1; ae < s; ++ae) {
                var af = ae / s;
                var ag = x + ab * af;
                var ah = (z - ag) / ab;
                var ai = (ag - x) / ab;
                var aj = ah * y + ai * aa + ((ah * ah * ah - ah) * ac + (ai * ai * ai - ai) * ad) * (ab * ab) / 6;
                f.add([aj, aj]);
            }
        }
        return f.toArray();
    };
    SplineSeriesBase.prototype.acs = 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.ch, h);
        var j = new ScalerParams(0, b, c, e.ch, h);
        j.b = this.iw();
        var k = this.w7();
        var l = 0;
        var m = this.acm(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.yt.cw.f;
        var q = this.yt.cw.e;
        var r = truncate(Math.ceil(c.width / (p - q)));
        var s = new CollisionAvoider();
        var t = this.yt.cw.d;
        if (t <= 0 || (q <= 0 && p <= 0)) {
            this.yt.cz.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.aci(a, a.f._inner[a.f.count - 1], s, Math.min(y, this.dl.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.ace[w];
            var af = this.ace[w + 1];
            var ag = g.i$d(g.i$b._inner[w]);
            var ah = d.ek(ag, i) + m;
            var ai = e.ek(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.ek(ar, i) + m;
                ao = e.ek(ao, j);
                a.f.add([al, ao, ao]);
                u++;
            }
            if (k) {
                x = [ah, ai, ai];
            }
            if (k && this.aci(a, x, s, Math.min(y, this.dl.count - 1), l, f, v - 1)) {
                ++l;
            }
        }
        f.cz.count = l;
    };
    SplineSeriesBase.prototype.aci = 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.n.add({ $type: Point_$type, x: h, y: i });
            var k = f.cz.item(e);
            k.content.item = this.dl.item(d);
            k.al = g;
            k.ak = d;
            return true;
        }
        return false;
    };
    SplineSeriesBase.prototype.am = function (a, b, c, d, e, f) {
        if (a == null || a.cn || this.zl(this.ct) > 1 || this.zl(this.ct) == 0) {
            return _super.prototype.am.call(this, this.yj(), this.yk.f, this.zl(this.ct), this.zm(this.ct), e, f);
        }
        if (this.yk.f.count == 0) {
            return null;
        }
        var g = this.acf.cw.f;
        var h = this.ct.bx;
        var i = truncate(Math.ceil(h.width));
        if (g != d) {
            i = truncate(Math.ceil(h.width / (g - d)));
        }
        var j = -1;
        var k = -1;
        var l = this.ip(e);
        var m = this.j8(e, f);
        var n = this.j6(e, f);
        var o = truncate(Math.floor(m / this.zl(this.ct)));
        var p = truncate(Math.floor(n / this.zl(this.ct)));
        j = o - this.zm(this.ct);
        k = p - this.zm(this.ct);
        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.yk.f.count - 1) {
            j = this.yk.f.count - 1;
        }
        if (k < 0) {
            k = 0;
        }
        if (k > this.yk.f.count - 1) {
            k = this.yk.f.count - 1;
        }
        var u = this.yk.f._inner[j];
        var v = this.yk.f._inner[k];
        var w = new Array(2);
        w[0] = u;
        w[1] = v;
        return w;
    };
    SplineSeriesBase.prototype.z0 = function (a, b) {
        var _this = this;
        _super.prototype.z0.call(this, a, b);
        if (a.f.count <= 1) {
            return;
        }
        if (b.cw.d == 0) {
            return;
        }
        var c = b.by;
        var d = b.bx;
        var e = this.getEffectiveViewport1(b);
        var f = this.abt;
        var g = this.abz;
        var h = new ScalerParams(0, c, d, f.ch, e);
        var i = ((function () {
            var $ret = new ScalerParams(0, c, d, g.ch, e);
            $ret.b = _this.iw();
            return $ret;
        })());
        a.f.clear();
        a.n.clear();
        var j = this.w7();
        var k = 0;
        var l = typeCast(ISortingAxis_$type, this.abt);
        if (l != null && l.i$b.count != this.dl.count) {
            return;
        }
        var m = this.acm(f, c, d, e);
        var n = b.cw.d;
        this.acr(b);
        var o = b.cw.f;
        var p = b.cw.e;
        var q = truncate(Math.ceil(d.width / (o - p)));
        var r = new CollisionAvoider();
        if (l != null) {
            this.acs(a, c, d, f, g, b);
            return;
        }
        var s = function (t) { return t; };
        var t = function (u) { return _this.valueColumn.item(u); };
        var u = b;
        u.db();
        var v = 0;
        var w = 0;
        for (var x = p; x <= o; ++x) {
            var y = null;
            if (n == 1) {
                if (x >= (this.valueColumn.count - 1)) {
                    if (j && this.aci(a, a.f._inner[a.f.count - 1], r, Math.min(x * n, this.dl.count - 1), k, b, v - 1)) {
                        ++k;
                    }
                    break;
                }
                var z = s(x);
                var aa = t(x);
                var ab = s(x + 1);
                var ac = t(x + 1);
                var ad = ab - z;
                var ae = this.ace[x];
                var af = this.ace[x + 1];
                var ag = f.ek(z, h) + m;
                var ah = g.ek(aa, i);
                a.f.add([ag, ah, ah]);
                v++;
                w = v;
                for (var ai = 1; ai < q; ++ai) {
                    var aj = z + ad * ai / q;
                    var ak = (ab - aj) / ad;
                    var al = (aj - z) / ad;
                    var am = ak * aa + al * ac + ((ak * ak * ak - ak) * ae + (al * al * al - al) * af) * (ad * ad) / 6;
                    aj = f.ek(aj, h) + m;
                    am = g.ek(am, i);
                    a.f.add([aj, am, am]);
                    v++;
                }
                if (j) {
                    y = b.cw.getBucket(x);
                    y[0] = (f.ek(y[0], h) + m);
                    y[1] = g.ek(y[1], i);
                    y[2] = g.ek(y[2], i);
                }
            }
            else {
                y = b.cw.getBucket(x);
                if (!isNaN_(y[0])) {
                    y[0] = (f.ek(y[0], h) + m);
                    y[1] = g.ek(y[1], i);
                    y[2] = g.ek(y[2], i);
                    a.f.add(y);
                    v++;
                    w = v;
                }
            }
            if (j && this.aci(a, y, r, Math.min(x * n, this.dl.count - 1), k, b, w - 1)) {
                ++k;
            }
        }
        u.dd();
        b.cz.count = k;
    };
    SplineSeriesBase.prototype.acr = function (a) {
        var _this = this;
        var b = a.cw.d;
        var c = function (d) { return d; };
        var d = function (e) { return _this.valueColumn.item(e); };
        if (b < 1 || this.valueColumn == null || this.valueColumn.count == 0) {
            return;
        }
        if ((this.ace == null || this.ace.length != this.valueColumn.count) && b == 1) {
            var e = this.acg == 0 ? NaN : 0;
            if (this.abt != null && typeCast(ISortingAxis_$type, this.abt) !== null && this.abt.i$b != null) {
                var f_1 = new SafeSortedReadOnlyDoubleCollection(1, this.valueColumn, this.abt.i$b, NaN);
                d = function (g) { return f_1.item(g); };
            }
            this.ace = Numeric.c(this.valueColumn.count, c, d, e, e);
            if (this.ach) {
                var g = -1.7976931348623157E+308;
                var h = 1.7976931348623157E+308;
                var i = this.acc(a);
                if (i == null) {
                    return;
                }
                for (var j = 0; j < i.length; j++) {
                    if (isNaN_(i[j][0]) || isNaN_(i[j][1])) {
                        continue;
                    }
                    if (i[j][1] > g) {
                        g = i[j][1];
                    }
                    if (i[j][0] < h) {
                        h = i[j][0];
                    }
                }
                this.aco = h;
                this.acn = g;
            }
        }
    };
    SplineSeriesBase.prototype.acl = 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.it = 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.ace != null && e >= 0 && e < this.ace.length) {
            o = this.ace[e];
        }
        if (this.ace != null && f >= 0 && f < this.ace.length) {
            p = this.ace[f];
        }
        return this.acl(a, k, m, l, n, o, p);
    };
    SplineSeriesBase.prototype.acm = 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.index, b, c, d);
                break;
        }
        if (a.ch) {
            f = -f;
        }
        return f;
    };
    Object.defineProperty(SplineSeriesBase.prototype, "aco", {
        get: function () {
            return this.ack;
        },
        set: function (a) {
            this.ack = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(SplineSeriesBase.prototype, "acn", {
        get: function () {
            return this.acj;
        },
        set: function (a) {
            this.acj = a;
        },
        enumerable: false,
        configurable: true
    });
    SplineSeriesBase.prototype.act = function () {
        this.ace = null;
        this.aco = NaN;
        this.acn = NaN;
        if (this.yAxis != null) {
            this.yAxis.c1();
        }
    };
    SplineSeriesBase.prototype.q4 = function (a, b, c, d) {
        switch (b) {
            case "ValueColumn":
            case "FastItemsSource":
                this.act();
                break;
        }
        _super.prototype.q4.call(this, a, b, c, d);
        switch (b) {
            case SplineSeriesBase.$$p[1]:
                this.act();
                this.rm(false);
                this.qg();
                break;
        }
    };
    SplineSeriesBase.prototype.o8 = function (a, b, c, d) {
        this.act();
        _super.prototype.o8.call(this, a, b, c, d);
    };
    Object.defineProperty(SplineSeriesBase.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.zg;
        },
        enumerable: false,
        configurable: true
    });
    SplineSeriesBase.$t = markType(SplineSeriesBase, 'SplineSeriesBase', HorizontalAnchoredCategorySeries.$);
    SplineSeriesBase.$$p = markDep(DependencyProperty, PropertyMetadata, SplineSeriesBase, 'raisePropertyChanged', ['IsSplineShapePartOfRange:ach:acu', [0, false], 'SplineType:acg:acv', [SplineType_$type, enumGetBox(SplineType_$type, 0)]]);
    return SplineSeriesBase;
}(HorizontalAnchoredCategorySeries));
export { SplineSeriesBase };
/**
 * @hidden
 */
var SplineSeriesBaseView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(SplineSeriesBaseView, _super);
    function SplineSeriesBaseView(a) {
        var _this = _super.call(this, a) || this;
        _this.df = null;
        _this.df = a;
        return _this;
    }
    SplineSeriesBaseView.prototype.dg = function () {
        var a = 1;
        if (this.df.c9 != null) {
            a = this.df.c9.hb;
        }
        return Math.max(1 / (a * 3), 0.3);
    };
    SplineSeriesBaseView.prototype.af = function () {
        var a = new Color();
        a.colorString = "rgba(95,95,95,0.5)";
        this.e.vu = a;
        this.e.jk = 3;
        this.e.jl = 1;
        this.e.jm = 4;
        this.e.ha = false;
    };
    SplineSeriesBaseView.$t = markType(SplineSeriesBaseView, 'SplineSeriesBaseView', AnchoredCategorySeriesView.$);
    return SplineSeriesBaseView;
}(AnchoredCategorySeriesView));
export { SplineSeriesBaseView };
