/*
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";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { typeCast, Point_$type, enumGetBox, markType, markDep } from "igniteui-react-core";
import { CollisionAvoider } from "./CollisionAvoider";
import { ISortingAxis_$type } from "./ISortingAxis";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
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) {
    tslib_1.__extends(SplineSeriesBase, _super);
    function SplineSeriesBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.s6 = null;
        return _this;
    }
    SplineSeriesBase.prototype.bp = function () {
        return new SplineSeriesBaseView(this);
    };
    SplineSeriesBase.prototype.kk = function (a) {
        _super.prototype.kk.call(this, a);
        this.s7 = a;
    };
    SplineSeriesBase.prototype.get_cy = function () {
        return true;
    };
    SplineSeriesBase.prototype.td = 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.ca, h);
        var j = new ScalerParams(0, b, c, e.ca, h);
        j.b = this.fa();
        var k = this.ok();
        var l = 0;
        var m = this.tb(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.p3.cr.f;
        var q = this.p3.cr.e;
        var r = truncate(Math.ceil(c.width / (p - q)));
        var s = new CollisionAvoider();
        var t = this.p3.cr.d;
        if (t <= 0 || (q <= 0 && p <= 0)) {
            this.p3.cu.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.s9(a, a.f._inner[a.f.count - 1], s, Math.min(y, this.cd.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.s6[w];
            var af = this.s6[w + 1];
            var ag = g.i$d(g.i$b._inner[w]);
            var ah = d.dz(ag, i) + m;
            var ai = e.dz(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.dz(ar, i) + m;
                ao = e.dz(ao, j);
                a.f.add([al, ao, ao]);
                u++;
            }
            if (k) {
                x = [ah, ai, ai];
            }
            if (k && this.s9(a, x, s, Math.min(y, this.cd.count - 1), l, f, v - 1)) {
                ++l;
            }
        }
        f.cu.count = l;
    };
    SplineSeriesBase.prototype.s9 = 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.cu.item(e);
            k.content.item = this.cd.item(d);
            k.al = g;
            return true;
        }
        return false;
    };
    SplineSeriesBase.prototype.aj = function (a, b, c, d, e, f) {
        if (a == null || a.cf || this.qu(this.bs) > 1 || this.qu(this.bs) == 0) {
            return _super.prototype.aj.call(this, this.pu(), this.pv.f, this.qu(this.bs), this.qv(this.bs), e, f);
        }
        if (this.pv.f.count == 0) {
            return null;
        }
        var g = this.s7.cr.f;
        var h = this.bs.bu;
        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.e4(e);
        var m = this.gf(e, f);
        var n = this.gd(e, f);
        var o = truncate(Math.floor(m / this.qu(this.bs)));
        var p = truncate(Math.floor(n / this.qu(this.bs)));
        j = o - this.qv(this.bs);
        k = p - this.qv(this.bs);
        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.pv.f.count - 1) {
            j = this.pv.f.count - 1;
        }
        if (k < 0) {
            k = 0;
        }
        if (k > this.pv.f.count - 1) {
            k = this.pv.f.count - 1;
        }
        var u = this.pv.f._inner[j];
        var v = this.pv.f._inner[k];
        var w = new Array(2);
        w[0] = u;
        w[1] = v;
        return w;
    };
    SplineSeriesBase.prototype.q9 = function (a, b) {
        var _this = this;
        _super.prototype.q9.call(this, a, b);
        if (a.f.count <= 1) {
            return;
        }
        if (b.cr.d == 0) {
            return;
        }
        var c = b.bv;
        var d = b.bu;
        var e = this.getEffectiveViewport1(b);
        var f = this.sn;
        var g = this.st;
        var h = new ScalerParams(0, c, d, f.ca, e);
        var i = ((function () {
            var $ret = new ScalerParams(0, c, d, g.ca, e);
            $ret.b = _this.fa();
            return $ret;
        })());
        a.f.clear();
        a.m.clear();
        var j = this.ok();
        var k = 0;
        var l = typeCast(ISortingAxis_$type, this.sn);
        if (l != null && l.i$b.count != this.cd.count) {
            return;
        }
        var m = this.tb(f, c, d, e);
        var n = function (o) { return o; };
        var o = function (p) { return _this.valueColumn.item(p); };
        var p = b.cr.d;
        if ((this.s6 == null || this.s6.length != this.valueColumn.count) && p == 1) {
            var q = this.s8 == 0 ? NaN : 0;
            if (this.sn != null && typeCast(ISortingAxis_$type, this.sn) !== null && this.sn.i$b != null) {
                var r_1 = new SafeSortedReadOnlyDoubleCollection(1, this.valueColumn, this.sn.i$b, NaN);
                o = function (s) { return r_1.item(s); };
            }
            this.s6 = Numeric.c(this.valueColumn.count, n, o, q, q);
        }
        var s = b.cr.f;
        var t = b.cr.e;
        var u = truncate(Math.ceil(d.width / (s - t)));
        var v = new CollisionAvoider();
        if (l != null) {
            this.td(a, c, d, f, g, b);
            return;
        }
        var w = b;
        w.c6();
        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.s9(a, a.f._inner[a.f.count - 1], v, Math.min(z * p, this.cd.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.s6[z];
                var ah = this.s6[z + 1];
                var ai = f.dz(ab, h) + m;
                var aj = g.dz(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.dz(al, h) + m;
                    ao = g.dz(ao, i);
                    a.f.add([al, ao, ao]);
                    x++;
                }
                if (j) {
                    aa = b.cr.getBucket(z);
                    aa[0] = (f.dz(aa[0], h) + m);
                    aa[1] = g.dz(aa[1], i);
                    aa[2] = g.dz(aa[2], i);
                }
            }
            else {
                aa = b.cr.getBucket(z);
                if (!isNaN_(aa[0])) {
                    aa[0] = (f.dz(aa[0], h) + m);
                    aa[1] = g.dz(aa[1], i);
                    aa[2] = g.dz(aa[2], i);
                    a.f.add(aa);
                    x++;
                }
            }
            if (j && this.s9(a, aa, v, Math.min(z * p, this.cd.count - 1), k, b, y - 1)) {
                ++k;
            }
        }
        w.c8();
        b.cu.count = k;
    };
    SplineSeriesBase.prototype.ta = 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.e8 = 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.s6 != null && e >= 0 && e < this.s6.length) {
            o = this.s6[e];
        }
        if (this.s6 != null && f >= 0 && f < this.s6.length) {
            p = this.s6[f];
        }
        return this.ta(a, k, m, l, n, o, p);
    };
    SplineSeriesBase.prototype.tb = 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.gi, b, c, d);
                break;
        }
        if (a.ca) {
            f = -f;
        }
        return f;
    };
    SplineSeriesBase.prototype.te = function () {
        this.s6 = null;
    };
    SplineSeriesBase.prototype.kp = function (a, b, c, d) {
        switch (b) {
            case "ValueColumn":
            case "FastItemsSource":
                this.te();
                break;
        }
        _super.prototype.kp.call(this, a, b, c, d);
        switch (b) {
            case SplineSeriesBase.$$p[0]:
                this.te();
                this.k3(false);
                this.ka();
                break;
        }
    };
    SplineSeriesBase.prototype.jo = function (a, b, c, d) {
        this.te();
        _super.prototype.jo.call(this, a, b, c, d);
    };
    Object.defineProperty(SplineSeriesBase.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.qp;
        },
        enumerable: true,
        configurable: true
    });
    SplineSeriesBase.$t = markType(SplineSeriesBase, 'SplineSeriesBase', HorizontalAnchoredCategorySeries.$);
    SplineSeriesBase.$$p = markDep(DependencyProperty, PropertyMetadata, SplineSeriesBase, 'raisePropertyChanged', ['SplineType:s8:tf', [SplineType_$type, enumGetBox(SplineType_$type, 0)]]);
    return SplineSeriesBase;
}(HorizontalAnchoredCategorySeries));
export { SplineSeriesBase };
/**
 * @hidden
 */
var SplineSeriesBaseView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(SplineSeriesBaseView, _super);
    function SplineSeriesBaseView(a) {
        var _this = _super.call(this, a) || this;
        _this.da = null;
        _this.da = a;
        return _this;
    }
    SplineSeriesBaseView.prototype.af = function () {
        var a = new Color();
        a.colorString = "rgba(95,95,95,0.5)";
        this.e.ni = a;
        this.e.fs = 3;
        this.e.ft = 1;
        this.e.fu = 4;
        this.e.ea = false;
    };
    SplineSeriesBaseView.$t = markType(SplineSeriesBaseView, 'SplineSeriesBaseView', AnchoredCategorySeriesView.$);
    return SplineSeriesBaseView;
}(AnchoredCategorySeriesView));
export { SplineSeriesBaseView };
//# sourceMappingURL=SplineSeriesBase_combined.js.map
