/*
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 { 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-angular-core";
import { Point_$type, enumGetBox, typeCast, markType, markDep } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { Series } from "./Series";
import { TrendLineType_$type } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { PenLineCap_$type } from "igniteui-angular-core";
import { DoubleCollection } from "igniteui-angular-core";
import { CategoryFrame } from "./CategoryFrame";
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 { DataLegendSeriesValueInfo } from "igniteui-angular-core";
import { DataLegendSeriesContext } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { ISortingAxis_$type } from "./ISortingAxis";
import { IFastItemsSource_$type } from "igniteui-angular-core";
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 { CategoryAxisBase } from "./CategoryAxisBase";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { CategoryTrendLineManagerFactory } from "./CategoryTrendLineManagerFactory";
/**
 * @hidden
 */
var AnchoredCategorySeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(AnchoredCategorySeries, _super);
    function AnchoredCategorySeries() {
        var _this = _super.call(this) || this;
        _this.tk = null;
        _this.to = false;
        _this.tm = null;
        _this.th = null;
        _this.ts = null;
        _this.rt = new CategoryFramePreparer(1, _this, _this.rx, _this, _this, _this.rx.cr);
        return _this;
    }
    Object.defineProperty(AnchoredCategorySeries.prototype, "tl", {
        get: function () {
            var _this = this;
            if (this.tk == null) {
                this.tk = DVContainer.instance.createInstance(IAnchoredCategorySeriesInteractionManager_$type, function () { return _this.cn.n; });
            }
            return this.tk;
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.getHostReferenceValue = function () {
        return this.gc();
    };
    AnchoredCategorySeries.prototype.i0 = function () {
        return AnchoredCategorySeries.$$p[4];
    };
    AnchoredCategorySeries.prototype.bx = function () {
        var a = new AnchoredCategorySeriesView(this);
        return a;
    };
    AnchoredCategorySeries.prototype.ly = function (a) {
        _super.prototype.ly.call(this, a);
        this.tg = a;
    };
    AnchoredCategorySeries.prototype.hw = function (a, b) {
        var c = this.jq(b);
        if (c == AnchoredCategorySeries.$$p[4]) {
            return this.hx(a, b, this.t0);
        }
        return _super.prototype.hw.call(this, a, b);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "valueColumn", {
        get: function () {
            return this.tm;
        },
        set: function (a) {
            if (this.tm != a) {
                var b = this.tm;
                this.tm = a;
                if (!this.to) {
                    this.raisePropertyChanged("ValueColumn", b, this.tm);
                }
            }
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.getDataLegendSeriesContextAt = function (a, b) {
        var c = new DataLegendSeriesValueInfo();
        c.a = 0;
        c.l = this.gj({ $type: Point_$type, x: a, y: b }, false, false);
        c.p = "Value";
        c.q = this.tw != null ? this.tw : "V:";
        c.r = this.ty != null ? this.ty : "";
        var d = new DataLegendSeriesContext();
        d.f = ((function () {
            var $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
            $ret.add(c);
            return $ret;
        })());
        d.b = this.av();
        return d;
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "uk", {
        get: function () {
            return this.c(AnchoredCategorySeries.t7);
        },
        set: function (a) {
            this.h(AnchoredCategorySeries.t7, a);
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.en = function (a) {
        var b = new Rect(0, 0, 0, 1, 1);
        var c = this.fetchXAxis();
        var d = this.fetchYAxis();
        var e = this.ps(this.b0);
        var f = c != null ? this.rt.r(typeCast(ICategoryScaler_$type, c), b, b, e) : 0;
        return this.tl.c$a(this, this.valueColumn, c, d, f, a);
    };
    AnchoredCategorySeries.prototype.td = 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.cm;
        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.ck.item(g);
        }
        return d;
    };
    AnchoredCategorySeries.prototype.l3 = function (a, b, c, d) {
        _super.prototype.l3.call(this, a, b, c, d);
        if (this.tg.c3 && this.tg.c2.g$b(a, b, c, d)) {
            this.mh(false);
            this.lo();
        }
        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.ch(this.t0);
                }
                var e = typeCast(NumericAxisBase.$, this.fetchYAxis());
                if (e != null && !e.c0()) {
                    this.tg.cr.g(this.ft);
                    this.mh(false);
                }
                break;
            case AnchoredCategorySeries.$$p[4]:
                if (this.ck != null) {
                    this.ck.deregisterColumn(this.valueColumn);
                    this.valueColumn = this.ch(this.t0);
                }
                this.ts = this.t0;
                break;
            case "ValueColumn":
                if (this.tg.c3) {
                    this.tg.c2.g$i();
                }
                var f = typeCast(NumericAxisBase.$, this.fetchYAxis());
                if (f != null && !f.c0()) {
                    this.tg.cr.g(this.ft);
                    this.mh(false);
                }
                this.t6();
                this.m1();
                break;
            case "TrendLineBrush":
                this.mv();
                break;
            case "ErrorBarSettings":
                this.mh(false);
                break;
            case "TrendLineType":
                this.lo();
                break;
            case AnchoredCategorySeries.$$p[1]:
                this.mh(false);
                break;
        }
    };
    AnchoredCategorySeries.prototype.ap = 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.k0 = function (a, b, c, d) {
        switch (a) {
            case 4:
            case 1:
            case 0:
                this.tg.cr.g(this.ft);
                break;
        }
        if (this.tg.c3) {
            this.tg.c2.g$e(a, b, c, d);
        }
        this.t6();
        this.m1();
    };
    AnchoredCategorySeries.prototype.sn = function () {
        return this.tp(this.rx);
    };
    AnchoredCategorySeries.prototype.tp = function (a) {
        var b = 0;
        var c = a.bv;
        var d = a.bu;
        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.cg, e);
            if (f.co) {
                g.b = this.gc();
            }
            b = f.ei(f.l5, g);
        }
        return b;
    };
    AnchoredCategorySeries.prototype.t5 = function (a, b, c) {
        var d = this.tp(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.te = function (a, b, c, d) {
        return this.tf(a, b, c, d, false);
    };
    AnchoredCategorySeries.prototype.tf = function (a, b, c, d, e) {
        return CategorySeries.ri(a, b, c, d, e);
    };
    AnchoredCategorySeries.prototype.e9 = function (a, b, c) {
        var d = _super.prototype.e9.call(this, a, b, c);
        var e = c;
        if (this.valueColumn == null || this.valueColumn.count == 0 || e.cr.d < 1) {
            d = false;
        }
        return d;
    };
    AnchoredCategorySeries.prototype.kx = function (a, b) {
        _super.prototype.kx.call(this, a, b);
        var c = b;
        c.cx();
        if (c.c3) {
            c.c2.g$d();
        }
    };
    AnchoredCategorySeries.prototype.s3 = function (a, b) {
        _super.prototype.s3.call(this, a, b);
        this.ru(b).d(a, b);
    };
    AnchoredCategorySeries.prototype.s6 = function (a, b) {
        _super.prototype.s6.call(this, a, b);
        var c = typeCast(AnchoredCategorySeriesView.$, b);
        c.b3 = true;
        if (c.c3) {
            c.c2.g$g(a.p);
        }
        if (this.qe()) {
            CategoryMarkerManager.e(this, a.m, b.cu, this.qg);
            this.s0(b, a);
            b.cm();
        }
        this.t2(a, b);
    };
    AnchoredCategorySeries.prototype.mg = function (a, b, c, d, e) {
        _super.prototype.mg.call(this, a, b, c, d, e);
        var f = this.a6.a$h.item(d);
        var g = f;
        g.cr.g(this.ft);
        f.a1(c);
        if (this.cx(g)) {
            return;
        }
        if (this.th == null) {
            this.th = new CategoryFrame(3);
        }
        this.th.u();
        this.s3(this.th, g);
        this.s6(this.th, g);
    };
    AnchoredCategorySeries.prototype.t2 = function (a, b) {
    };
    AnchoredCategorySeries.prototype.mv = function () {
        _super.prototype.mv.call(this);
        if (this.index < 0) {
            return;
        }
        this.tg.c7();
        if (this.trendLineBrush != null) {
            this.tg.c5();
        }
        else {
            this.tg.c4();
        }
    };
    AnchoredCategorySeries.prototype.hz = function (a, b) {
        if (this.tg.c3 && a == this.tg.c2.g$j) {
            return null;
        }
        return _super.prototype.hz.call(this, a, b);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "currentCategoryMode", {
        get: function () {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.rn()));
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "scaler", {
        get: function () {
            return typeCast(ICategoryScaler_$type, this.rn());
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "yScaler", {
        get: function () {
            return typeCast(IScaler_$type, this.r8());
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "bucketizer", {
        get: function () {
            return this.tg.cr;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeries.prototype, "currentMode2Index", {
        get: function () {
            return this.sr();
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.provideCollisionDetector = function () {
        if (this.ti == 1) {
            return new CollisionAvoider();
        }
        return NonCollisionAvoider.b;
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "trendlinePreparer", {
        get: function () {
            return this.tg.c3 ? this.tg.c2 : null;
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.k7 = function (a) {
        _super.prototype.k7.call(this, a);
        if (this.tg.c3) {
            this.a8.exportTrendlineData(this, a, this.tg.c2.g$j);
        }
    };
    AnchoredCategorySeries.prototype.ht = function (a) {
        var _this = this;
        var b = this.fetchXAxis();
        var c = this.fetchYAxis();
        return this.tl.c$b(this, a, this.so(this.b0), this.valueColumn, b, c, this.tj == 1, function (d) { return _super.prototype.ht.call(_this, d); });
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "mayContainUnknowns", {
        get: function () {
            return this.valueColumn == null || this.valueColumn.mayContainUnknowns;
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.gc = function () {
        return Series.gd(this.valueColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
    };
    AnchoredCategorySeries.prototype.get_tr = function () {
        return 0;
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "tr", {
        get: function () {
            return this.get_tr();
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.prototype.aq = function (a) {
        if (a.isEmpty && this.cd != null) {
            a = this.cd.sf;
        }
        if (this.valueColumn == null) {
            return null;
        }
        var b = this.pq(this.b0);
        var c = this.rn();
        var d = new ScalerParams(0, a, this.cd.su, c.cg, this.getEffectiveViewport());
        var e = (c.el(b.left, d));
        var f = (c.el(b.right, d));
        if (c.cg) {
            var g = e;
            e = f;
            f = g;
        }
        e -= this.tr;
        f += this.tr;
        var h = null;
        if (c.cm) {
            h = c;
            e = h.i$f(e);
            f = h.i$f(f);
        }
        else {
            e = Math.floor(e);
            f = Math.ceil(f);
        }
        if (isNaN_(e) || isNaN_(f)) {
            return null;
        }
        e = Math.max(0, Math.min(this.valueColumn.count - 1, e));
        f = Math.max(0, Math.min(this.valueColumn.count - 1, f));
        var i = 1.7976931348623157E+308;
        var j = -1.7976931348623157E+308;
        if (truncate(e) <= truncate(f)) {
            for (var k = truncate(e); k <= truncate(f); k++) {
                var l = k;
                if (h != null) {
                    l = h.i$b._inner[k];
                }
                var m = this.valueColumn.item(l);
                if (this.valueColumn.mayContainUnknowns) {
                    if (isInfinity(m) || isNaN_(m)) {
                        continue;
                    }
                }
                i = Math.min(i, m);
                j = Math.max(j, m);
            }
        }
        var n = new AxisRange(i, j);
        n = this.ao(n, this.r8(), a);
        return n;
    };
    AnchoredCategorySeries.prototype.t6 = function () {
        this.f1 = this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(this.valueColumn.count - 1);
    };
    Object.defineProperty(AnchoredCategorySeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.sj;
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeries.$t = markType(AnchoredCategorySeries, 'AnchoredCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasSingleValueCategory_$type, IHasCategoryTrendline_$type, ITrendLineSeries_$type]);
    AnchoredCategorySeries.t7 = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredCategorySeries.$, new PropertyMetadata(2, null, function (a, b) { return a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue); }));
    AnchoredCategorySeries.$$p = markDep(DependencyProperty, PropertyMetadata, AnchoredCategorySeries, 'raisePropertyChanged', ['ConsolidatedItemHitTestBehavior:tj:t8', [ConsolidatedItemHitTestBehavior_$type, enumGetBox(ConsolidatedItemHitTestBehavior_$type, 0)], 'MarkerCollisionAvoidance:ti:t9', [CategorySeriesMarkerCollisionAvoidance_$type, enumGetBox(CategorySeriesMarkerCollisionAvoidance_$type, 1)], 'ValueMemberAsLegendLabel:tw:uh', [2, null], 'ValueMemberAsLegendUnit:ty:ui', [2, null], 'ValueMemberPath:t0:uj', [2, null], 'TrendLineType::uf', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::ue', [1, 1.5], 'TrendLinePeriod::ud', [1, 7], 'TrendLineBrush::ua', [Brush.$, null], 'TrendLineZIndex:tq:ug', [1, 1001], 'TrendLineDashArray:ul:ub', [DoubleCollection.$], 'TrendLineDashCap:um:uc', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
    return AnchoredCategorySeries;
}(CategorySeries));
export { AnchoredCategorySeries };
/**
 * @hidden
 */
var AnchoredCategoryBucketCalculator = /** @class */ /*@__PURE__*/ (function (_super) {
    __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.c0.valueColumn.count;
        this.h = this.i.c0.valueColumn.asArray();
    };
    AnchoredCategoryBucketCalculator.prototype.unCacheValues = function () {
        this.h = null;
    };
    AnchoredCategoryBucketCalculator.$t = markType(AnchoredCategoryBucketCalculator, 'AnchoredCategoryBucketCalculator', CategoryBucketCalculator.$);
    return AnchoredCategoryBucketCalculator;
}(CategoryBucketCalculator));
export { AnchoredCategoryBucketCalculator };
/**
 * @hidden
 */
var AnchoredCategorySeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(AnchoredCategorySeriesView, _super);
    function AnchoredCategorySeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.c0 = null;
        _this.c1 = null;
        _this.c0 = a;
        return _this;
    }
    Object.defineProperty(AnchoredCategorySeriesView.prototype, "c2", {
        get: function () {
            if (this.c1 == null) {
                this.c1 = CategoryTrendLineManagerFactory.a(this.c1, this.e.ar(), this.e.m9, this.e, this.e.cn);
            }
            return this.c1;
        },
        set: function (a) {
            this.c1 = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(AnchoredCategorySeriesView.prototype, "c3", {
        get: function () {
            return this.c1 != null;
        },
        enumerable: false,
        configurable: true
    });
    AnchoredCategorySeriesView.prototype.c7 = function () {
        this.c0.uk = null;
    };
    AnchoredCategorySeriesView.prototype.c5 = function () {
        this.c0.uk = this.c0.trendLineBrush;
    };
    AnchoredCategorySeriesView.prototype.c4 = function () {
        this.c0.uk = this.c0.oy;
    };
    AnchoredCategorySeriesView.prototype.cs = function () {
        return new AnchoredCategoryBucketCalculator(this);
    };
    AnchoredCategorySeriesView.prototype.c6 = function () {
        this.cr.cacheValues();
    };
    AnchoredCategorySeriesView.prototype.c8 = function () {
        this.cr.unCacheValues();
    };
    AnchoredCategorySeriesView.prototype.c9 = function (a) {
        var b = this.cu.item(a);
        return this.cp(b);
    };
    AnchoredCategorySeriesView.prototype.a5 = function (a, b) {
        if (a.d) {
            if (this.c0.trendLineType != 0 && !b) {
                var c = this.c2.g$j;
                c.ac = this.c0.trendLineThickness;
                c._stroke = this.c0.uk;
                c.ai = this.c0.ul;
                c.ad = this.c0.um;
                a.u(c);
            }
        }
        _super.prototype.a5.call(this, a, b);
    };
    AnchoredCategorySeriesView.prototype.getDefaultTooltipTemplate = function () {
        return this.c0.tl.c$c(this.e, this.c0.t0);
    };
    AnchoredCategorySeriesView.$t = markType(AnchoredCategorySeriesView, 'AnchoredCategorySeriesView', CategorySeriesView.$);
    return AnchoredCategorySeriesView;
}(CategorySeriesView));
export { AnchoredCategorySeriesView };
