/*
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 { CategorySeries } from "./CategorySeries";
import { IIsCategoryBased_$type } from "./IIsCategoryBased";
import { IHasSingleValueCategory_$type } from "./IHasSingleValueCategory";
import { IHasCategoryTrendline_$type } from "./IHasCategoryTrendline";
import { ITrendLineSeries_$type } from "./ITrendLineSeries";
import { IAnchoredCategorySeriesInteractionManager_$type } from "./IAnchoredCategorySeriesInteractionManager";
import { DVContainer } from "igniteui-react-core/ES5/DVContainer";
import { Type, enumGetBox, typeCast, Point_$type, markType } from "igniteui-react-core/ES5/type";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { TrendLineType_$type } from "igniteui-react-core/ES5/TrendLineType";
import { Brush } from "igniteui-react-core/ES5/Brush";
import { PenLineCap_$type } from "igniteui-react-core/ES5/PenLineCap";
import { DoubleCollection } from "igniteui-react-core/ES5/DoubleCollection";
import { CategoryFrame } from "./CategoryFrame";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { ICategoryScaler_$type } from "./ICategoryScaler";
import { IScaler_$type } from "./IScaler";
import { CategorySeriesView } from "./CategorySeriesView";
import { CategorySeriesMarkerCollisionAvoidance_$type } from "./CategorySeriesMarkerCollisionAvoidance";
import { ConsolidatedItemHitTestBehavior_$type } from "./ConsolidatedItemHitTestBehavior";
import { CategoryFramePreparer } from "./CategoryFramePreparer";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { NumericAxisBase } from "./NumericAxisBase";
import { CategoryBucketCalculator } from "./CategoryBucketCalculator";
import { AxisRange } from "./AxisRange";
import { NumericYAxis } from "./NumericYAxis";
import { ScalerParams } from "./ScalerParams";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { CollisionAvoider } from "./CollisionAvoider";
import { NonCollisionAvoider } from "./NonCollisionAvoider";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { truncate, isNaN_ } from "igniteui-react-core/ES5/number";
import { CategoryTrendLineManagerFactory } from "./CategoryTrendLineManagerFactory";
var AnchoredCategorySeries = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategorySeries, _super);
    function AnchoredCategorySeries() {
        var _this = _super.call(this) || this;
        _this.or = null;
        _this.ov = false;
        _this.ot = null;
        _this.oo = null;
        _this.oy = null;
        _this.mz = new CategoryFramePreparer(1, _this, _this.m3, _this, _this, _this.m3.cl);
        return _this;
    }
    Object.defineProperty(AnchoredCategorySeries.prototype, "os", {
        get: function () {
            var _this = this;
            if (this.or == null) {
                this.or = DVContainer.instance.createInstance(IAnchoredCategorySeriesInteractionManager_$type, function () { return _this.b2.n; });
            }
            return this.or;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.bf = function () {
        var a = new AnchoredCategorySeriesView(this);
        return a;
    };
    AnchoredCategorySeries.prototype.ii = function (a) {
        _super.prototype.ii.call(this, a);
        this.on = a;
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "valueColumn", {
        get: function () {
            return this.ot;
        },
        set: function (a) {
            if (this.ot != a) {
                var b = this.ot;
                this.ot = a;
                if (!this.ov) {
                    this.raisePropertyChanged("ValueColumn", b, this.ot);
                }
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "pk", {
        get: function () {
            return this.c(AnchoredCategorySeries.o9);
        },
        set: function (a) {
            this.h(AnchoredCategorySeries.o9, a);
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.c6 = function (a) {
        var b = new Rect(0, 0, 0, 1, 1);
        var c = this.fetchXAxis();
        var d = this.fetchYAxis();
        var e = this.lg(this.bi);
        var f = c != null ? this.mz.r(typeCast(ICategoryScaler_$type, c), b, b, e) : 0;
        return this.os.c$a(this, this.valueColumn, c, d, f, a);
    };
    AnchoredCategorySeries.prototype.ok = function (a, b, c) {
        if (b < a || a < 0 || a > this.valueColumn.count || b < 0 || b > this.valueColumn.count || c == null) {
            return null;
        }
        var d = new Array((b - a) + 1);
        var e = c.cc;
        var f = null;
        if (e) {
            f = c.i$b;
        }
        for (var g = a; g <= b; g++) {
            var h = g;
            if (e) {
                h = f._inner[h];
            }
            d[g - a] = this.bz.item(g);
        }
        return d;
    };
    AnchoredCategorySeries.prototype.io = function (a, b, c, d) {
        _super.prototype.io.call(this, a, b, c, d);
        if (this.on.cx && this.on.cw.g$b(a, b, c, d)) {
            this.i1(false);
            this.h8();
        }
        switch (b) {
            case "FastItemsSource":
                if (typeCast(IFastItemsSource_$type, c) != null) {
                    c.deregisterColumn(this.valueColumn);
                    this.valueColumn = null;
                }
                if (typeCast(IFastItemsSource_$type, d) != null) {
                    this.valueColumn = this.bw(this.o2);
                }
                var e = typeCast(NumericAxisBase.$, this.fetchYAxis());
                if (e != null && !e.ck()) {
                    this.on.cl.g(this.eo);
                    this.i1(false);
                }
                break;
            case AnchoredCategorySeries.$$p[2]:
                if (this.bz != null) {
                    this.bz.deregisterColumn(this.valueColumn);
                    this.valueColumn = this.bw(this.o2);
                }
                this.oy = this.o2;
                break;
            case "ValueColumn":
                if (this.on.cx) {
                    this.on.cw.g$i();
                }
                var f = typeCast(NumericAxisBase.$, this.fetchYAxis());
                if (f != null && !f.ck()) {
                    this.on.cl.g(this.eo);
                    this.i1(false);
                }
                this.o8();
                break;
            case "TrendLineBrush":
                this.jc();
                break;
            case "ErrorBarSettings":
                this.i1(false);
                break;
            case "TrendLineType":
                this.h8();
                break;
            case AnchoredCategorySeries.$$p[1]:
                this.i1(false);
                break;
        }
    };
    AnchoredCategorySeries.prototype.an = function (a) {
        if (this.valueColumn == null || this.valueColumn.count == 0) {
            return null;
        }
        if (a == this.fetchXAxis()) {
            return new AxisRange(0, this.valueColumn.count - 1);
        }
        if (a == this.fetchYAxis()) {
            return new AxisRange(this.valueColumn.minimum, this.valueColumn.maximum);
        }
        return null;
    };
    AnchoredCategorySeries.prototype.ho = function (a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.on.cl.g(this.eo);
                break;
        }
        if (this.on.cx) {
            this.on.cw.g$e(a, b, c, d);
        }
        this.o8();
    };
    AnchoredCategorySeries.prototype.nu = function () {
        return this.ow(this.m3);
    };
    AnchoredCategorySeries.prototype.ow = function (a) {
        var b = 0;
        var c = a.bq;
        var d = a.bp;
        var e = this.getEffectiveViewport1(a);
        var f = typeCast(NumericYAxis.$, this.fetchYAxis());
        if (!c.isEmpty && !d.isEmpty && f != null) {
            var g = new ScalerParams(0, c, d, f.b8, e);
            b = f.dt(f.j6, g);
        }
        return b;
    };
    AnchoredCategorySeries.prototype.o7 = function (a, b, c) {
        var d = this.ow(c);
        if (a.count > 0) {
            var e = d;
            a.add({ $type: Point_$type, x: a._inner[a.count - 1].x, y: e });
            a.add({ $type: Point_$type, x: a._inner[0].x, y: e });
        }
    };
    AnchoredCategorySeries.prototype.ol = function (a, b, c, d) {
        return this.om(a, b, c, d, false);
    };
    AnchoredCategorySeries.prototype.om = function (a, b, c, d, e) {
        return CategorySeries.mp(a, b, c, d, e);
    };
    AnchoredCategorySeries.prototype.dt = function (a, b, c) {
        var d = _super.prototype.dt.call(this, a, b, c);
        var e = c;
        if (this.valueColumn == null || this.valueColumn.count == 0 || e.cl.d < 1) {
            d = false;
        }
        return d;
    };
    AnchoredCategorySeries.prototype.hl = function (a, b) {
        _super.prototype.hl.call(this, a, b);
        var c = b;
        c.cr();
        if (c.cx) {
            c.cw.g$d();
        }
    };
    AnchoredCategorySeries.prototype.n8 = function (a, b) {
        _super.prototype.n8.call(this, a, b);
        this.m0(b).d(a, b);
    };
    AnchoredCategorySeries.prototype.ob = function (a, b) {
        _super.prototype.ob.call(this, a, b);
        var c = typeCast(AnchoredCategorySeriesView.$, b);
        c.by = true;
        if (c.cx) {
            c.cw.g$g(a.p);
        }
        if (this.lr()) {
            CategoryMarkerManager.b(this, a.m, b.co, this.lt);
            this.n5(b, a);
            b.ch();
        }
        this.o4(a, b);
    };
    AnchoredCategorySeries.prototype.i0 = function (a, b, c, d, e) {
        _super.prototype.i0.call(this, a, b, c, d, e);
        var f = this.a0.a$h.item(d);
        var g = f;
        g.cl.g(this.eo);
        f.ay(c);
        if (this.cc(g)) {
            return;
        }
        if (this.oo == null) {
            this.oo = new CategoryFrame(3);
        }
        this.oo.u();
        this.n8(this.oo, g);
        this.ob(this.oo, g);
    };
    AnchoredCategorySeries.prototype.o4 = function (a, b) {
    };
    AnchoredCategorySeries.prototype.jc = function () {
        _super.prototype.jc.call(this);
        if (this.fb < 0) {
            return;
        }
        this.on.c1();
        if (this.trendLineBrush != null) {
            this.on.cz();
        }
        else {
            this.on.cy();
        }
    };
    AnchoredCategorySeries.prototype.fm = function (a, b) {
        if (this.on.cx && a == this.on.cw.g$j) {
            return null;
        }
        return _super.prototype.fm.call(this, a, b);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "currentCategoryMode", {
        get: function () {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.fetchXAxis()));
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "scaler", {
        get: function () {
            return typeCast(ICategoryScaler_$type, this.fetchXAxis());
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "yScaler", {
        get: function () {
            return typeCast(IScaler_$type, this.fetchYAxis());
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "bucketizer", {
        get: function () {
            return this.on.cl;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "currentMode2Index", {
        get: function () {
            return this.nx();
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.provideCollisionDetector = function () {
        if (this.op == 1) {
            return new CollisionAvoider();
        }
        return NonCollisionAvoider.a;
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "trendlinePreparer", {
        get: function () {
            return this.on.cx ? this.on.cw : null;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.hu = function (a) {
        _super.prototype.hu.call(this, a);
        if (this.on.cx) {
            this.a2.exportTrendlineData(this, a, this.on.cw.g$j);
        }
    };
    AnchoredCategorySeries.prototype.fj = function (a) {
        var _this = this;
        var b = this.fetchXAxis();
        var c = this.fetchYAxis();
        return this.os.c$b(this, a, this.nv(this.bi), this.valueColumn, b, c, this.oq == 1, function (d) { return _super.prototype.fj.call(_this, d); });
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "mayContainUnknowns", {
        get: function () {
            return this.valueColumn == null || this.valueColumn.mayContainUnknowns;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.prototype.ec = function () {
        return this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(0);
    };
    AnchoredCategorySeries.prototype.ao = function () {
        if (this.valueColumn == null) {
            return null;
        }
        var a = this.mu();
        var b = new ScalerParams(0, this.bs.mk, this.bs.mx, a.b8, this.getEffectiveViewport());
        var c = (a.dw(this.bs.mx.left, b));
        var d = (a.dw(this.bs.mx.right, b));
        var e = null;
        if (a.cc) {
            e = a;
            c = e.i$f(c);
            d = e.i$f(d);
        }
        else {
            c = Math.floor(c);
            d = Math.ceil(d);
        }
        if (isNaN_(c) || isNaN_(d)) {
            return null;
        }
        c = Math.max(0, Math.min(this.valueColumn.count - 1, c));
        d = Math.max(0, Math.min(this.valueColumn.count - 1, d));
        var f = 1.7976931348623157E+308;
        var g = -1.7976931348623157E+308;
        for (var h = truncate(c); h <= truncate(d); h++) {
            var i = h;
            if (e != null) {
                i = e.i$b._inner[h];
            }
            f = Math.min(f, this.valueColumn.item(i));
            g = Math.max(g, this.valueColumn.item(i));
        }
        return new AxisRange(f, g);
    };
    AnchoredCategorySeries.prototype.o8 = function () {
        this.d3 = this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(this.valueColumn.count - 1);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.nq;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeries.o9 = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredCategorySeries.$, new PropertyMetadata(2, null, function (a, b) { return a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue); }));
    AnchoredCategorySeries.$t = markType(AnchoredCategorySeries, 'AnchoredCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasSingleValueCategory_$type, IHasCategoryTrendline_$type, ITrendLineSeries_$type]);
    return AnchoredCategorySeries;
}(CategorySeries));
export { AnchoredCategorySeries };
Type.dep(DependencyProperty, PropertyMetadata, AnchoredCategorySeries, 'raisePropertyChanged', ['ConsolidatedItemHitTestBehavior:oq:pa', [ConsolidatedItemHitTestBehavior_$type, enumGetBox(ConsolidatedItemHitTestBehavior_$type, 0)], 'MarkerCollisionAvoidance:op:pb', [CategorySeriesMarkerCollisionAvoidance_$type, enumGetBox(CategorySeriesMarkerCollisionAvoidance_$type, 1)], 'ValueMemberPath:o2:pj', [2, null], 'TrendLineType::ph', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::pg', [1, 1.5], 'TrendLinePeriod::pf', [1, 7], 'TrendLineBrush::pc', [Brush.$, null], 'TrendLineZIndex:ox:pi', [1, 1001], 'TrendLineDashArray:pl:pd', [DoubleCollection.$], 'TrendLineDashCap:pm:pe', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
var AnchoredCategoryBucketCalculator = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategoryBucketCalculator, _super);
    function AnchoredCategoryBucketCalculator(a) {
        var _this = _super.call(this, a) || this;
        _this.i = null;
        _this.h = null;
        _this.j = 0;
        _this.i = a;
        return _this;
    }
    AnchoredCategoryBucketCalculator.prototype.getBucketWithoutUnknowns = function (a) {
        var b = this.h;
        var c = this.j;
        var d = a * this.d;
        var e = d + this.d - 1;
        var f = c - 1;
        d = d < f ? d : f;
        e = e < f ? e : f;
        var g = 1.7976931348623157E+308;
        var h = -1.7976931348623157E+308;
        var i = true;
        for (var j = d; j <= e; ++j) {
            var k = b[j];
            g = g < k ? g : k;
            h = h > k ? h : k;
            i = false;
        }
        if (!i) {
            return [0.5 * (d + e), g, h];
        }
        return [0.5 * (d + e), NaN, NaN];
    };
    AnchoredCategoryBucketCalculator.prototype.getBucket = function (a) {
        var b = this.h;
        var c = this.j;
        var d = a * this.d;
        var e = d + this.d - 1;
        var f = c - 1;
        d = d < f ? d : f;
        e = e < f ? e : f;
        var g = 0;
        var h = 0;
        var i = true;
        for (var j = d; j <= e; ++j) {
            var k = b[j];
            if (!i) {
                if (!isNaN_(k)) {
                    g = g < k ? g : k;
                    h = h > k ? h : k;
                }
            }
            else {
                if (!isNaN_(k)) {
                    g = k;
                    h = k;
                    i = false;
                }
            }
        }
        if (!i) {
            return [0.5 * (d + e), g, h];
        }
        return [0.5 * (d + e), NaN, NaN];
    };
    AnchoredCategoryBucketCalculator.prototype.cacheValues = function () {
        this.j = this.i.cu.valueColumn.count;
        this.h = this.i.cu.valueColumn.asArray();
    };
    AnchoredCategoryBucketCalculator.prototype.unCacheValues = function () {
        this.h = null;
    };
    AnchoredCategoryBucketCalculator.$t = markType(AnchoredCategoryBucketCalculator, 'AnchoredCategoryBucketCalculator', CategoryBucketCalculator.$);
    return AnchoredCategoryBucketCalculator;
}(CategoryBucketCalculator));
export { AnchoredCategoryBucketCalculator };
var AnchoredCategorySeriesView = /** @class */ (function (_super) {
    tslib_1.__extends(AnchoredCategorySeriesView, _super);
    function AnchoredCategorySeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.cu = null;
        _this.cv = null;
        _this.cu = a;
        return _this;
    }
    Object.defineProperty(AnchoredCategorySeriesView.prototype, "cw", {
        get: function () {
            if (this.cv == null) {
                this.cv = CategoryTrendLineManagerFactory.a(this.cv, this.e.ap(), this.e.jl, this.e, this.e.b2);
            }
            return this.cv;
        },
        set: function (a) {
            this.cv = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeriesView.prototype, "cx", {
        get: function () {
            return this.cv != null;
        },
        enumerable: true,
        configurable: true
    });
    AnchoredCategorySeriesView.prototype.c1 = function () {
        this.cu.pk = null;
    };
    AnchoredCategorySeriesView.prototype.cz = function () {
        this.cu.pk = this.cu.trendLineBrush;
    };
    AnchoredCategorySeriesView.prototype.cy = function () {
        this.cu.pk = this.cu.kr;
    };
    AnchoredCategorySeriesView.prototype.cm = function () {
        return new AnchoredCategoryBucketCalculator(this);
    };
    AnchoredCategorySeriesView.prototype.c0 = function () {
        this.cl.cacheValues();
    };
    AnchoredCategorySeriesView.prototype.c2 = function () {
        this.cl.unCacheValues();
    };
    AnchoredCategorySeriesView.prototype.c3 = function (a) {
        var b = this.co.item(a);
        return this.ck(b);
    };
    AnchoredCategorySeriesView.prototype.a2 = function (a, b) {
        if (a.d) {
            if (this.cu.trendLineType != 0 && !b) {
                var c = this.cw.g$j;
                c.ac = this.cu.trendLineThickness;
                c._stroke = this.cu.pk;
                c.ai = this.cu.pl;
                c.ad = this.cu.pm;
                a.u(c);
            }
        }
        _super.prototype.a2.call(this, a, b);
    };
    AnchoredCategorySeriesView.prototype.getDefaultTooltipTemplate = function () {
        return this.cu.os.c$c(this.e, this.cu.o2);
    };
    AnchoredCategorySeriesView.$t = markType(AnchoredCategorySeriesView, 'AnchoredCategorySeriesView', CategorySeriesView.$);
    return AnchoredCategorySeriesView;
}(CategorySeriesView));
export { AnchoredCategorySeriesView };
/*<BeginStatics Name="Infragistics.Controls.Charts.AnchoredCategorySeries" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.AnchoredCategorySeries" />*/
