/*
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 { CategoryBucketCalculator } from "./CategoryBucketCalculator";
import { markType, typeCast, markDep, Point_$type } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { CategorySeries } from "./CategorySeries";
import { IIsCategoryBased_$type } from "./IIsCategoryBased";
import { IHasHighLowValueCategory_$type } from "./IHasHighLowValueCategory";
import { RangeCategoryFramePreparer } from "./RangeCategoryFramePreparer";
import { DependencyProperty } from "igniteui-angular-core";
import { Series } from "./Series";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { ICategoryScaler_$type } from "./ICategoryScaler";
import { IScaler_$type } from "./IScaler";
import { CategorySeriesView } from "./CategorySeriesView";
import { CategoryFrame } from "./CategoryFrame";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { AxisRange } from "./AxisRange";
import { ISortingAxis_$type } from "./ISortingAxis";
import { CollisionAvoider } from "./CollisionAvoider";
import { ISupportsMarkers_$type } from "./ISupportsMarkers";
import { PropertyMetadata } from "igniteui-angular-core";
import { FastFlattener } from "igniteui-angular-core";
/**
 * @hidden
 */
var RangeCategoryBucketCalculator = /** @class */ (function (_super) {
    tslib_1.__extends(RangeCategoryBucketCalculator, _super);
    function RangeCategoryBucketCalculator(a) {
        var _this = _super.call(this, a) || this;
        _this.j = null;
        _this.l = 0;
        _this.k = 0;
        _this.i = null;
        _this.h = null;
        _this.j = a;
        return _this;
    }
    RangeCategoryBucketCalculator.prototype.getBucketWithoutUnknowns = function (a) {
        var b = false;
        var c = this.i;
        var d = this.h;
        var e = this.l;
        var f = this.k;
        var g = Math.min(e, f);
        var h = a * this.d;
        var i = Math.min(h + this.d - 1, g - 1);
        var j = 1.7976931348623157E+308;
        var k = -1.7976931348623157E+308;
        var l = true;
        var m = 0;
        var n = 0;
        var o;
        var p;
        for (var q = h; q <= i; ++q) {
            m = c[q];
            n = d[q];
            if (m < n) {
                o = m;
                p = n;
            }
            else {
                p = m;
                o = n;
            }
            if (!l) {
                j = j < o ? j : o;
                k = k > o ? k : o;
                j = j < p ? j : p;
                k = k > p ? k : p;
            }
            else {
                j = Math.min(j, o);
                k = Math.max(k, o);
                k = Math.max(k, p);
                j = Math.min(j, p);
                l = false;
            }
        }
        if (b && n < m) {
            var r = j;
            j = k;
            k = r;
        }
        if (!l) {
            var s = new Array(3);
            s[0] = 0.5 * (h + i);
            s[1] = j;
            s[2] = k;
            return s;
        }
        var t = new Array(3);
        t[0] = NaN;
        t[1] = NaN;
        t[2] = NaN;
        return t;
    };
    RangeCategoryBucketCalculator.prototype.getBucket = function (a) {
        var b = false;
        var c = this.i;
        var d = this.h;
        var e = this.l;
        var f = this.k;
        var g = Math.min(e, f);
        var h = a * this.d;
        var i = Math.min(h + this.d - 1, g - 1);
        var j = NaN;
        var k = NaN;
        var l = true;
        var m = 0;
        var n = 0;
        var o;
        var p;
        for (var q = h; q <= i; ++q) {
            m = c[q];
            n = d[q];
            if (m < n) {
                o = m;
                p = n;
            }
            else {
                p = m;
                o = n;
            }
            if (!l) {
                if (!isNaN_(o)) {
                    j = j < o ? j : o;
                    k = k > o ? k : o;
                }
                if (!isNaN_(p)) {
                    j = j < p ? j : p;
                    k = k > p ? k : p;
                }
            }
            else {
                if (!isNaN_(o)) {
                    if (isNaN_(j)) {
                        j = o;
                    }
                    else {
                        j = Math.min(j, o);
                    }
                    if (!isNaN_(k)) {
                        k = Math.max(k, o);
                    }
                }
                if (!isNaN_(p)) {
                    if (isNaN_(k)) {
                        k = p;
                    }
                    else {
                        k = Math.max(k, p);
                    }
                    if (!isNaN_(j)) {
                        j = Math.min(j, p);
                    }
                }
                if (!isNaN_(j) && !isNaN_(k)) {
                    l = false;
                }
            }
        }
        if (n < m && b) {
            var r = j;
            j = k;
            k = r;
        }
        if (!l) {
            var s = new Array(3);
            s[0] = 0.5 * (h + i);
            s[1] = j;
            s[2] = k;
            return s;
        }
        var t = new Array(3);
        t[0] = NaN;
        t[1] = NaN;
        t[2] = NaN;
        return t;
    };
    RangeCategoryBucketCalculator.prototype.cacheValues = function () {
        this.l = this.j.cw.lowColumn.count;
        this.k = this.j.cw.highColumn.count;
        this.i = this.j.cw.lowColumn.asArray();
        this.h = this.j.cw.highColumn.asArray();
    };
    RangeCategoryBucketCalculator.prototype.unCacheValues = function () {
        this.i = null;
        this.h = null;
    };
    RangeCategoryBucketCalculator.$t = markType(RangeCategoryBucketCalculator, 'RangeCategoryBucketCalculator', CategoryBucketCalculator.$);
    return RangeCategoryBucketCalculator;
}(CategoryBucketCalculator));
export { RangeCategoryBucketCalculator };
/**
 * @hidden
 */
var RangeCategorySeries = /** @class */ (function (_super) {
    tslib_1.__extends(RangeCategorySeries, _super);
    function RangeCategorySeries() {
        var _this = _super.call(this) || this;
        _this._RangeFramePreparer = null;
        _this.o0 = null;
        _this.oy = null;
        _this.ov = null;
        _this.RangeFramePreparer = new RangeCategoryFramePreparer(1, _this, _this.ox, _this, _this, _this.ox.cn);
        return _this;
    }
    RangeCategorySeries.prototype.bf = function () {
        return new RangeCategorySeriesView(this);
    };
    RangeCategorySeries.prototype.getHostReferenceValue = function () {
        return this.eh();
    };
    RangeCategorySeries.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.ox = a;
    };
    Object.defineProperty(RangeCategorySeries.prototype, "RangeFramePreparer", {
        get: function () {
            return this._RangeFramePreparer;
        },
        set: function (a) {
            this._RangeFramePreparer = a;
        },
        enumerable: true,
        configurable: true
    });
    RangeCategorySeries.prototype.fs = function (a, b) {
        var c = this.gu(b);
        if (c == RangeCategorySeries.$$p[0]) {
            return this.ft(a, b, this.o3);
        }
        if (c == RangeCategorySeries.$$p[0]) {
            return this.ft(a, b, this.o3);
        }
        return _super.prototype.fs.call(this, a, b);
    };
    Object.defineProperty(RangeCategorySeries.prototype, "lowColumn", {
        get: function () {
            return this.o0;
        },
        set: function (a) {
            if (this.o0 != a) {
                var b = this.o0;
                this.o0 = a;
                this.raisePropertyChanged("LowColumn", b, this.o0);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RangeCategorySeries.prototype, "highColumn", {
        get: function () {
            return this.oy;
        },
        set: function (a) {
            if (this.oy != a) {
                var b = this.oy;
                this.oy = a;
                this.raisePropertyChanged("HighColumn", b, this.oy);
            }
        },
        enumerable: true,
        configurable: true
    });
    RangeCategorySeries.prototype.ng = function () {
        return 11;
    };
    RangeCategorySeries.prototype.oo = function (a, b) {
        _super.prototype.oo.call(this, a, b);
        b.b0 = true;
        CategoryMarkerManager.b(this, a.m, b.cq, this.l5);
        this.oi(b, a);
    };
    RangeCategorySeries.prototype.o8 = function (a, b, c, d, e, f) {
        this.ox.cx(a, b, c, d, e, f);
    };
    RangeCategorySeries.prototype.c9 = function (a) {
        var b = new Rect(0, 0, 0, 1, 1);
        var c = this.bi != null ? this.bi.bs : Rect.empty;
        c = c.copy();
        var d = this.bi != null ? this.bi.br : Rect.empty;
        var e = !c.isEmpty && !d.isEmpty && this.bz != null ? this.bz.indexOf(a) : -1;
        var f = this.fetchXAxis();
        var g = this.fetchYAxis();
        var h = this.ls(this.bi);
        var i;
        if (f != null) {
            var j = new ScalerParams(0, b, b, f.b8, h);
            i = f.dw(e, j);
        }
        else {
            i = NaN;
        }
        var k = f != null ? this.RangeFramePreparer.r(typeCast(ICategoryScaler_$type, f), b, b, h) : 0;
        i += k;
        if (e >= 0 && Rect.l_op_Inequality(c, null) && Rect.l_op_Inequality(d, null)) {
            if (!isNaN_(i)) {
                if (i < c.left + 0.1 * c.width) {
                    i = i + 0.4 * c.width;
                }
                if (i > c.right - 0.1 * c.width) {
                    i = i - 0.4 * c.width;
                }
                c.x = i - 0.5 * c.width;
            }
            if (g != null && this.highColumn != null && e < this.highColumn.count) {
                var l = new ScalerParams(0, b, b, g.b8, h);
                l.b = this.eh();
                var m = g.dw(this.highColumn.item(e), l);
                var n = g.dw(this.lowColumn.item(e), l);
                if (!isNaN_(m) && !isNaN_(n)) {
                    var o = Math.abs(n - m);
                    if (c.height < o) {
                        c.height = o;
                        c.y = Math.min(n, m);
                    }
                    else {
                        if (n < c.top + 0.1 * c.height) {
                            n = n + 0.4 * c.height;
                        }
                        if (n > c.bottom - 0.1 * c.height) {
                            n = n - 0.4 * c.height;
                        }
                        c.y = n - 0.5 * c.height;
                    }
                }
            }
            if (this.bn != null) {
                this.bn.ap(this.bs, c, true);
            }
        }
        return e >= 0;
    };
    RangeCategorySeries.prototype.iz = function (a, b, c, d) {
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.lowColumn);
                    c.deregisterColumn(this.highColumn);
                    this.lowColumn = null;
                    this.highColumn = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.lowColumn = this.bw(this.o6);
                    this.highColumn = this.bw(this.o3);
                }
                if (!this.n1()) {
                    this.nf.cn.g(this.eu);
                    this.jd(false);
                }
                break;
            case RangeCategorySeries.$$p[1]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.lowColumn);
                    this.lowColumn = this.bw(this.o6);
                }
                break;
            case "LowColumn":
                if (!this.n1()) {
                    this.nf.cn.g(this.eu);
                    this.jd(false);
                }
                break;
            case RangeCategorySeries.$$p[0]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.highColumn);
                    this.highColumn = this.bw(this.o3);
                }
                break;
            case "HighColumn":
                if (!this.n1()) {
                    this.nf.cn.g(this.eu);
                    this.jd(false);
                }
                break;
        }
    };
    RangeCategorySeries.prototype.an = function (a) {
        if (this.lowColumn == null || this.lowColumn.count == 0 || this.highColumn == null || this.highColumn.count == 0) {
            return null;
        }
        if (a == this.fetchXAxis()) {
            var b = Math.min(this.lowColumn.count, this.highColumn.count);
            return new AxisRange(0, b - 1);
        }
        if (a == this.fetchYAxis()) {
            var c = Math.min(this.lowColumn.minimum, this.highColumn.minimum);
            var d = Math.max(this.lowColumn.maximum, this.highColumn.maximum);
            return new AxisRange(Math.min(c, d), Math.max(c, d));
        }
        return null;
    };
    RangeCategorySeries.prototype.hy = function (a, b, c, d) {
        if (this.fetchXAxis() != null && typeCast(ISortingAxis_$type, this.fetchXAxis()) !== null) {
            this.fetchXAxis().i$i();
        }
        var e = this.fetchXAxis();
        switch (a) {
            case 3:
                if (d == this.o6 || d == this.o3) {
                    if (e != null) {
                        e.cl();
                    }
                    if (!this.n1()) {
                        this.jd(true);
                    }
                }
                break;
            case 1:
                if (e != null) {
                    e.cl();
                }
                this.nf.cn.g(this.eu);
                if (!this.n1()) {
                    this.jd(true);
                }
                break;
            case 0:
                if (e != null) {
                    e.cl();
                }
                this.nf.cn.g(this.eu);
                if (!this.n1()) {
                    this.jd(true);
                }
                break;
            case 2:
                if (e != null) {
                    e.cl();
                }
                if (this.o6 != null && this.o3 != null && this.nf.cn.d > 0 && !this.n1()) {
                    this.jd(true);
                }
                break;
            case 4:
                if (e != null) {
                    e.cl();
                }
                this.nf.cn.g(this.eu);
                if (!this.n1()) {
                    this.jd(true);
                }
                break;
        }
    };
    RangeCategorySeries.prototype.dw = function (a, b, c) {
        var d = _super.prototype.dw.call(this, a, b, c);
        if (this.lowColumn == null || this.lowColumn.count == 0 || this.highColumn == null || this.highColumn.count == 0) {
            d = false;
        }
        return d;
    };
    RangeCategorySeries.prototype.ol = function (a, b) {
        _super.prototype.ol.call(this, a, b);
        this.RangeFramePreparer.d(a, b);
    };
    Object.defineProperty(RangeCategorySeries.prototype, "currentCategoryMode", {
        get: function () {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.fetchXAxis()));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RangeCategorySeries.prototype, "scaler", {
        get: function () {
            return typeCast(ICategoryScaler_$type, this.fetchXAxis());
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RangeCategorySeries.prototype, "yScaler", {
        get: function () {
            return typeCast(IScaler_$type, this.fetchYAxis());
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RangeCategorySeries.prototype, "bucketizer", {
        get: function () {
            return this.nf.cn;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(RangeCategorySeries.prototype, "currentMode2Index", {
        get: function () {
            return this.n9();
        },
        enumerable: true,
        configurable: true
    });
    RangeCategorySeries.prototype.provideCollisionDetector = function () {
        return new CollisionAvoider();
    };
    Object.defineProperty(RangeCategorySeries.prototype, "mayContainUnknowns", {
        get: function () {
            return this.lowColumn == null || this.lowColumn.mayContainUnknowns || this.highColumn == null || this.highColumn.mayContainUnknowns;
        },
        enumerable: true,
        configurable: true
    });
    RangeCategorySeries.prototype.jf = function (a, b) {
        var c = this.dl;
        _super.prototype.jf.call(this, a, b);
        if (!c) {
            this.bi.az(b);
            return;
        }
        this.bi.az(b);
        if (this.cc(this.bh)) {
            return;
        }
        var d = new RangeCategoryFramePreparer(1, this, typeCast(ISupportsMarkers_$type, this.bh), this.bs.bn.m, this, this.bh.cn);
        if (!this.df) {
            this.m9 = new CategoryFrame(3);
            this.m9.u();
            d.d(this.m9, this.bh);
        }
        this.df = false;
        this.oo(this.m9, this.bh);
        this.dl = false;
    };
    RangeCategorySeries.prototype.jc = function (a, b, c, d, e) {
        _super.prototype.jc.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        var g = f;
        g.cn.g(this.eu);
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        var h = new RangeCategoryFramePreparer(1, this, typeCast(ISupportsMarkers_$type, f), f, this, f.cn);
        if (this.ov == null) {
            this.ov = new CategoryFrame(3);
        }
        this.ov.u();
        h.d(this.ov, g);
        this.oo(this.ov, g);
    };
    RangeCategorySeries.prototype.eh = function () {
        return Series.ei(this.lowColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
    };
    Object.defineProperty(RangeCategorySeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.n2;
        },
        enumerable: true,
        configurable: true
    });
    RangeCategorySeries.$t = markType(RangeCategorySeries, 'RangeCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasHighLowValueCategory_$type]);
    RangeCategorySeries.$$p = markDep(DependencyProperty, PropertyMetadata, RangeCategorySeries, 'raisePropertyChanged', ['HighMemberPath:o3:o9', [2, null], 'LowMemberPath:o6:pa', [2, null]]);
    return RangeCategorySeries;
}(CategorySeries));
export { RangeCategorySeries };
/**
 * @hidden
 */
var RangeCategorySeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(RangeCategorySeriesView, _super);
    function RangeCategorySeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.cw = null;
        _this.cw = a;
        return _this;
    }
    RangeCategorySeriesView.prototype.cx = function (a, b, c, d, e, f) {
        a.ak.clear();
        b.ak.clear();
        c.ak.clear();
        var g = FastFlattener.b(d, e, true, f, this.e.eu);
        var h = FastFlattener.b(d, e, false, f, this.e.eu);
        var i = g.count;
        var j = h.count;
        var k;
        var l;
        var m;
        var n;
        for (var o = 0; o < i; o++) {
            k = g.item(o);
            l = e._inner[k];
            m = l[0];
            n = l[1];
            a.ak.add({ $type: Point_$type, x: m, y: n });
            b.ak.add({ $type: Point_$type, x: m, y: n });
        }
        var p;
        var q;
        for (var r = 0; r < j; r++) {
            k = h.item(r);
            l = e._inner[k];
            if (f) {
                p = l[0];
                q = l[2];
            }
            else {
                p = l[2];
                q = l[3];
            }
            c.ak.add({ $type: Point_$type, x: p, y: q });
            b.ak.add({ $type: Point_$type, x: p, y: q });
        }
        a.ab = a.ak.count > 0;
        b.ab = b.ak.count > 0;
        c.ab = c.ak.count > 0;
    };
    RangeCategorySeriesView.prototype.co = function () {
        return new RangeCategoryBucketCalculator(this);
    };
    RangeCategorySeriesView.$t = markType(RangeCategorySeriesView, 'RangeCategorySeriesView', CategorySeriesView.$);
    return RangeCategorySeriesView;
}(CategorySeriesView));
export { RangeCategorySeriesView };
//# sourceMappingURL=RangeCategoryBucketCalculator_combined.js.map