/*
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-angular-core";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { typeCast, Point_$type, enumGetBox, markType, markDep } from "igniteui-angular-core";
import { CollisionAvoider } from "./CollisionAvoider";
import { ISortingAxis_$type } from "./ISortingAxis";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
import { SafeSortedReadOnlyDoubleCollection } from "./SafeSortedReadOnlyDoubleCollection";
import { Numeric } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_ } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
/**
 * @hidden
 */
var SplineSeriesBase = /** @class */ (function (_super) {
    tslib_1.__extends(SplineSeriesBase, _super);
    function SplineSeriesBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.qh = null;
        return _this;
    }
    SplineSeriesBase.prototype.bf = function () {
        return new SplineSeriesBaseView(this);
    };
    SplineSeriesBase.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.qi = a;
    };
    SplineSeriesBase.prototype.get_ck = function () {
        return true;
    };
    SplineSeriesBase.prototype.qo = 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);
        j.b = this.eh();
        var k = this.l3();
        var l = 0;
        var m = this.qm(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.nf.cn.f;
        var q = this.nf.cn.e;
        var r = truncate(Math.ceil(c.width / (p - q)));
        var s = new CollisionAvoider();
        var t = this.nf.cn.d;
        if (t <= 0 || (q <= 0 && p <= 0)) {
            this.nf.cq.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.qk(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.qh[w];
            var af = this.qh[w + 1];
            var ag = g.i$d(g.i$b._inner[w]);
            var ah = d.dw(ag, i) + m;
            var ai = e.dw(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.dw(ar, i) + m;
                ao = e.dw(ao, j);
                a.f.add([al, ao, ao]);
                u++;
            }
            if (k) {
                x = [ah, ai, ai];
            }
            if (k && this.qk(a, x, s, Math.min(y, this.bz.count - 1), l, f, v - 1)) {
                ++l;
            }
        }
        f.cq.count = l;
    };
    SplineSeriesBase.prototype.qk = 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.cq.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.cd || this.n7(this.bi) > 1 || this.n7(this.bi) == 0) {
            return _super.prototype.aj.call(this, this.m6(), this.m7.f, this.n7(this.bi), this.n8(this.bi), e, f);
        }
        if (this.m7.f.count == 0) {
            return null;
        }
        var g = this.qi.cn.f;
        var h = this.bi.br;
        var i = truncate(Math.ceil(h.width / (g - d)));
        var j = -1;
        var k = -1;
        var l = this.eb(e);
        var m = this.fe(e, f);
        var n = this.fc(e, f);
        var o = truncate(Math.floor(m / this.n7(this.bi)));
        var p = truncate(Math.floor(n / this.n7(this.bi)));
        j = o - this.n8(this.bi);
        k = p - this.n8(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.m7.f.count - 1) {
            j = this.m7.f.count - 1;
        }
        if (k < 0) {
            k = 0;
        }
        if (k > this.m7.f.count - 1) {
            k = this.m7.f.count - 1;
        }
        var u = this.m7.f._inner[j];
        var v = this.m7.f._inner[k];
        var w = new Array(2);
        w[0] = u;
        w[1] = v;
        return w;
    };
    SplineSeriesBase.prototype.ol = function (a, b) {
        var _this = this;
        _super.prototype.ol.call(this, a, b);
        if (a.f.count <= 1) {
            return;
        }
        if (b.cn.d == 0) {
            return;
        }
        var c = b.bs;
        var d = b.br;
        var e = this.getEffectiveViewport1(b);
        var f = this.py;
        var g = this.p4;
        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.eh();
            return $ret;
        })());
        a.f.clear();
        a.m.clear();
        var j = this.l3();
        var k = 0;
        var l = typeCast(ISortingAxis_$type, this.py);
        if (l != null && l.i$b.count != this.bz.count) {
            return;
        }
        var m = this.qm(f, c, d, e);
        var n = function (o) { return o; };
        var o = function (p) { return _this.valueColumn.item(p); };
        var p = b.cn.d;
        if ((this.qh == null || this.qh.length != this.valueColumn.count) && p == 1) {
            var q = this.qj == 0 ? NaN : 0;
            if (this.py != null && typeCast(ISortingAxis_$type, this.py) !== null && this.py.i$b != null) {
                var r_1 = new SafeSortedReadOnlyDoubleCollection(1, this.valueColumn, this.py.i$b, NaN);
                o = function (s) { return r_1.item(s); };
            }
            this.qh = Numeric.c(this.valueColumn.count, n, o, q, q);
        }
        var s = b.cn.f;
        var t = b.cn.e;
        var u = truncate(Math.ceil(d.width / (s - t)));
        var v = new CollisionAvoider();
        if (l != null) {
            this.qo(a, c, d, f, g, b);
            return;
        }
        var w = b;
        w.c2();
        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.qk(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.qh[z];
                var ah = this.qh[z + 1];
                var ai = f.dw(ab, h) + m;
                var aj = g.dw(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.dw(al, h) + m;
                    ao = g.dw(ao, i);
                    a.f.add([al, ao, ao]);
                    x++;
                }
                if (j) {
                    aa = b.cn.getBucket(z);
                    aa[0] = (f.dw(aa[0], h) + m);
                    aa[1] = g.dw(aa[1], i);
                    aa[2] = g.dw(aa[2], i);
                }
            }
            else {
                aa = b.cn.getBucket(z);
                if (!isNaN_(aa[0])) {
                    aa[0] = (f.dw(aa[0], h) + m);
                    aa[1] = g.dw(aa[1], i);
                    aa[2] = g.dw(aa[2], i);
                    a.f.add(aa);
                    x++;
                }
            }
            if (j && this.qk(a, aa, v, Math.min(z * p, this.bz.count - 1), k, b, y - 1)) {
                ++k;
            }
        }
        w.c4();
        b.cq.count = k;
    };
    SplineSeriesBase.prototype.ql = 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.ef = 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.qh != null && e >= 0 && e < this.qh.length) {
            o = this.qh[e];
        }
        if (this.qh != null && f >= 0 && f < this.qh.length) {
            p = this.qh[f];
        }
        return this.ql(a, k, m, l, n, o, p);
    };
    SplineSeriesBase.prototype.qm = 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.fh, b, c, d);
                break;
        }
        if (a.b8) {
            f = -f;
        }
        return f;
    };
    SplineSeriesBase.prototype.qp = function () {
        this.qh = null;
    };
    SplineSeriesBase.prototype.iz = function (a, b, c, d) {
        switch (b) {
            case "ValueColumn":
            case "FastItemsSource":
                this.qp();
                break;
        }
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case SplineSeriesBase.$$p[0]:
                this.qp();
                this.jd(false);
                this.ik();
                break;
        }
    };
    SplineSeriesBase.prototype.hy = function (a, b, c, d) {
        this.qp();
        _super.prototype.hy.call(this, a, b, c, d);
    };
    Object.defineProperty(SplineSeriesBase.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.n2;
        },
        enumerable: true,
        configurable: true
    });
    SplineSeriesBase.$t = markType(SplineSeriesBase, 'SplineSeriesBase', HorizontalAnchoredCategorySeries.$);
    SplineSeriesBase.$$p = markDep(DependencyProperty, PropertyMetadata, SplineSeriesBase, 'raisePropertyChanged', ['SplineType:qj:qq', [SplineType_$type, enumGetBox(SplineType_$type, 0)]]);
    return SplineSeriesBase;
}(HorizontalAnchoredCategorySeries));
export { SplineSeriesBase };
/**
 * @hidden
 */
var SplineSeriesBaseView = /** @class */ (function (_super) {
    tslib_1.__extends(SplineSeriesBaseView, _super);
    function SplineSeriesBaseView(a) {
        var _this = _super.call(this, a) || this;
        _this.c6 = null;
        _this.c6 = a;
        return _this;
    }
    SplineSeriesBaseView.prototype.ac = function () {
        var a = new Color();
        a.colorString = "rgba(95,95,95,0.5)";
        this.e.la = a;
        this.e.ev = 3;
        this.e.ew = 1;
        this.e.ex = 4;
        this.e.du = false;
    };
    SplineSeriesBaseView.$t = markType(SplineSeriesBaseView, 'SplineSeriesBaseView', AnchoredCategorySeriesView.$);
    return SplineSeriesBaseView;
}(AnchoredCategorySeriesView));
export { SplineSeriesBaseView };
//# sourceMappingURL=SplineSeriesBase_combined.js.map