/*
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 { 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
 */
export let AnchoredCategorySeries = /*@__PURE__*/ (() => {
    class AnchoredCategorySeries extends CategorySeries {
        constructor() {
            super();
            this.tp = null;
            this.tt = false;
            this.tr = null;
            this.tm = null;
            this.tx = null;
            this.ry = new CategoryFramePreparer(1, this, this.r2, this, this, this.r2.cr);
        }
        get tq() {
            if (this.tp == null) {
                this.tp = DVContainer.instance.createInstance(IAnchoredCategorySeriesInteractionManager_$type, () => this.cn.n);
            }
            return this.tp;
        }
        getHostReferenceValue() {
            return this.ge();
        }
        i2() {
            return AnchoredCategorySeries.$$p[4];
        }
        bx() {
            let a = new AnchoredCategorySeriesView(this);
            return a;
        }
        l2(a) {
            super.l2(a);
            this.tl = a;
        }
        hy(a, b) {
            let c = this.js(b);
            if (c == AnchoredCategorySeries.$$p[4]) {
                return this.hz(a, b, this.t5);
            }
            return super.hy(a, b);
        }
        get valueColumn() {
            return this.tr;
        }
        set valueColumn(a) {
            if (this.tr != a) {
                let b = this.tr;
                this.tr = a;
                if (!this.tt) {
                    this.raisePropertyChanged("ValueColumn", b, this.tr);
                }
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = new DataLegendSeriesValueInfo();
            c.a = 0;
            c.l = this.gl({ $type: Point_$type, x: a, y: b }, false, false);
            c.q = this.t5 != null ? this.t5 : "Value";
            c.p = "Value";
            c.r = this.t1 != null ? this.t1 : "V:";
            c.s = this.t3 != null ? this.t3 : "";
            let d = new DataLegendSeriesContext();
            d.f = ((() => {
                let $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
                $ret.add(c);
                return $ret;
            })());
            d.b = this.av();
            return d;
        }
        get up() {
            return this.c(AnchoredCategorySeries.uc);
        }
        set up(a) {
            this.h(AnchoredCategorySeries.uc, a);
        }
        eo(a) {
            let b = new Rect(0, 0, 0, 1, 1);
            let c = this.fetchXAxis();
            let d = this.fetchYAxis();
            let e = this.px(this.b0);
            let f = c != null ? this.ry.r(typeCast(ICategoryScaler_$type, c), b, b, e) : 0;
            return this.tq.c$a(this, this.valueColumn, c, d, f, a);
        }
        ti(a, b, c) {
            if (b < a || a < 0 || a > this.valueColumn.count || b < 0 || b > this.valueColumn.count || c == null) {
                return null;
            }
            let d = new Array((b - a) + 1);
            let e = c.cm;
            let f = null;
            if (e) {
                f = c.i$b;
            }
            for (let g = a; g <= b; g++) {
                let h = g;
                if (e) {
                    h = f._inner[h];
                }
                d[g - a] = this.ck.item(g);
            }
            return d;
        }
        l7(a, b, c, d) {
            super.l7(a, b, c, d);
            if (this.tl.c3 && this.tl.c2.g$b(a, b, c, d)) {
                this.ml(false);
                this.ls();
            }
            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.t5);
                    }
                    let e = typeCast(NumericAxisBase.$, this.fetchYAxis());
                    if (e != null && !e.c0()) {
                        this.tl.cr.g(this.fv);
                        this.ml(false);
                    }
                    break;
                case AnchoredCategorySeries.$$p[4]:
                    if (this.ck != null) {
                        this.ck.deregisterColumn(this.valueColumn);
                        this.valueColumn = this.ch(this.t5);
                    }
                    this.tx = this.t5;
                    break;
                case "ValueColumn":
                    if (this.tl.c3) {
                        this.tl.c2.g$i();
                    }
                    let f = typeCast(NumericAxisBase.$, this.fetchYAxis());
                    if (f != null && !f.c0()) {
                        this.tl.cr.g(this.fv);
                        this.ml(false);
                    }
                    this.ub();
                    this.m5();
                    break;
                case "TrendLineBrush":
                    this.mz();
                    break;
                case "ErrorBarSettings":
                    this.ml(false);
                    break;
                case "TrendLineType":
                    this.ls();
                    break;
                case AnchoredCategorySeries.$$p[1]:
                    this.ml(false);
                    break;
            }
        }
        ap(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;
        }
        k3(a, b, c, d) {
            switch (a) {
                case 4:
                case 1:
                case 0:
                    this.tl.cr.g(this.fv);
                    break;
            }
            if (this.tl.c3) {
                this.tl.c2.g$e(a, b, c, d);
            }
            this.ub();
            this.m5();
        }
        ss() {
            return this.tu(this.r2);
        }
        tu(a) {
            let b = 0;
            let c = a.bv;
            let d = a.bu;
            let e = this.getEffectiveViewport1(a);
            let f = typeCast(NumericYAxis.$, this.fetchYAxis());
            if (!c.isEmpty && !d.isEmpty && f != null) {
                let g = new ScalerParams(0, c, d, f.cg, e);
                if (f.co) {
                    g.b = this.ge();
                }
                b = f.ei(f.l5, g);
            }
            return b;
        }
        ua(a, b, c) {
            let d = this.tu(c);
            if (a.count > 0) {
                let 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 });
            }
        }
        tj(a, b, c, d) {
            return this.tk(a, b, c, d, false);
        }
        tk(a, b, c, d, e) {
            return CategorySeries.rn(a, b, c, d, e);
        }
        fb(a, b, c) {
            let d = super.fb(a, b, c);
            let e = c;
            if (this.valueColumn == null || this.valueColumn.count == 0 || e.cr.d < 1) {
                d = false;
            }
            return d;
        }
        k0(a, b) {
            super.k0(a, b);
            let c = b;
            c.cx();
            if (c.c3) {
                c.c2.g$d();
            }
        }
        s8(a, b) {
            super.s8(a, b);
            this.rz(b).d(a, b);
        }
        tb(a, b) {
            super.tb(a, b);
            let c = typeCast(AnchoredCategorySeriesView.$, b);
            c.b3 = true;
            if (c.c3) {
                c.c2.g$g(a.p);
            }
            if (this.qj()) {
                CategoryMarkerManager.e(this, a.m, b.cu, this.ql);
                this.s5(b, a);
                b.cm();
            }
            this.t7(a, b);
        }
        mk(a, b, c, d, e) {
            super.mk(a, b, c, d, e);
            let f = this.a6.a$h.item(d);
            let g = f;
            g.cr.g(this.fv);
            f.a1(c);
            if (this.cx(g)) {
                return;
            }
            if (this.tm == null) {
                this.tm = new CategoryFrame(3);
            }
            this.tm.u();
            this.s8(this.tm, g);
            this.tb(this.tm, g);
        }
        t7(a, b) {
        }
        mz() {
            super.mz();
            if (this.index < 0) {
                return;
            }
            this.tl.c7();
            if (this.trendLineBrush != null) {
                this.tl.c5();
            }
            else {
                this.tl.c4();
            }
        }
        h1(a, b) {
            if (this.tl.c3 && a == this.tl.c2.g$j) {
                return null;
            }
            return super.h1(a, b);
        }
        get currentCategoryMode() {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.rs()));
        }
        get scaler() {
            return typeCast(ICategoryScaler_$type, this.rs());
        }
        get yScaler() {
            return typeCast(IScaler_$type, this.sd());
        }
        get bucketizer() {
            return this.tl.cr;
        }
        get currentMode2Index() {
            return this.sw();
        }
        provideCollisionDetector() {
            if (this.tn == 1) {
                return new CollisionAvoider();
            }
            return NonCollisionAvoider.b;
        }
        get trendlinePreparer() {
            return this.tl.c3 ? this.tl.c2 : null;
        }
        la(a) {
            super.la(a);
            if (this.tl.c3) {
                this.a8.exportTrendlineData(this, a, this.tl.c2.g$j);
            }
        }
        hv(a) {
            let b = this.fetchXAxis();
            let c = this.fetchYAxis();
            return this.tq.c$b(this, a, this.st(this.b0), this.valueColumn, b, c, this.to == 1, (d) => super.hv(d));
        }
        get mayContainUnknowns() {
            return this.valueColumn == null || this.valueColumn.mayContainUnknowns;
        }
        ge() {
            return Series.gf(this.valueColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
        }
        get_tw() {
            return 0;
        }
        get tw() {
            return this.get_tw();
        }
        aq(a) {
            if (a.isEmpty && this.cd != null) {
                a = this.cd.s9;
            }
            if (this.valueColumn == null) {
                return null;
            }
            let b = this.pv(this.b0);
            let c = this.rs();
            let d = new ScalerParams(0, a, this.cd.to, c.cg, this.getEffectiveViewport());
            let e = (c.el(b.left, d));
            let f = (c.el(b.right, d));
            if (c.cg) {
                let g = e;
                e = f;
                f = g;
            }
            e -= this.tw;
            f += this.tw;
            let 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));
            let i = 1.7976931348623157E+308;
            let j = -1.7976931348623157E+308;
            if (truncate(e) <= truncate(f)) {
                for (let k = truncate(e); k <= truncate(f); k++) {
                    let l = k;
                    if (h != null) {
                        l = h.i$b._inner[k];
                    }
                    let 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);
                }
            }
            let n = new AxisRange(i, j);
            n = this.ao(n, this.sd(), a);
            return n;
        }
        ub() {
            this.f3 = this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(this.valueColumn.count - 1);
        }
        get useHighMarkerFidelity() {
            return this.so;
        }
    }
    AnchoredCategorySeries.$t = markType(AnchoredCategorySeries, 'AnchoredCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasSingleValueCategory_$type, IHasCategoryTrendline_$type, ITrendLineSeries_$type]);
    AnchoredCategorySeries.uc = DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredCategorySeries.$, new PropertyMetadata(2, null, (a, b) => a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue)));
    AnchoredCategorySeries.$$p = markDep(DependencyProperty, PropertyMetadata, AnchoredCategorySeries, 'raisePropertyChanged', ['ConsolidatedItemHitTestBehavior:to:ud', [ConsolidatedItemHitTestBehavior_$type, enumGetBox(ConsolidatedItemHitTestBehavior_$type, 0)], 'MarkerCollisionAvoidance:tn:ue', [CategorySeriesMarkerCollisionAvoidance_$type, enumGetBox(CategorySeriesMarkerCollisionAvoidance_$type, 1)], 'ValueMemberAsLegendLabel:t1:um', [2, null], 'ValueMemberAsLegendUnit:t3:un', [2, null], 'ValueMemberPath:t5:uo', [2, null], 'TrendLineType::uk', [TrendLineType_$type, enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::uj', [1, 1.5], 'TrendLinePeriod::ui', [1, 7], 'TrendLineBrush::uf', [Brush.$, null], 'TrendLineZIndex:tv:ul', [1, 1001], 'TrendLineDashArray:uq:ug', [DoubleCollection.$], 'TrendLineDashCap:ur:uh', [PenLineCap_$type, enumGetBox(PenLineCap_$type, 0)]]);
    return AnchoredCategorySeries;
})();
/**
 * @hidden
 */
export let AnchoredCategoryBucketCalculator = /*@__PURE__*/ (() => {
    class AnchoredCategoryBucketCalculator extends CategoryBucketCalculator {
        constructor(a) {
            super(a);
            this.i = null;
            this.h = null;
            this.j = 0;
            this.i = a;
        }
        getBucketWithoutUnknowns(a) {
            let b = this.h;
            let c = this.j;
            let d = a * this.d;
            let e = d + this.d - 1;
            let f = c - 1;
            d = d < f ? d : f;
            e = e < f ? e : f;
            let g = 1.7976931348623157E+308;
            let h = -1.7976931348623157E+308;
            let i = true;
            for (let j = d; j <= e; ++j) {
                let 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];
        }
        getBucket(a) {
            let b = this.h;
            let c = this.j;
            let d = a * this.d;
            let e = d + this.d - 1;
            let f = c - 1;
            d = d < f ? d : f;
            e = e < f ? e : f;
            let g = 0;
            let h = 0;
            let i = true;
            for (let j = d; j <= e; ++j) {
                let 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];
        }
        cacheValues() {
            this.j = this.i.c0.valueColumn.count;
            this.h = this.i.c0.valueColumn.asArray();
        }
        unCacheValues() {
            this.h = null;
        }
    }
    AnchoredCategoryBucketCalculator.$t = markType(AnchoredCategoryBucketCalculator, 'AnchoredCategoryBucketCalculator', CategoryBucketCalculator.$);
    return AnchoredCategoryBucketCalculator;
})();
/**
 * @hidden
 */
export let AnchoredCategorySeriesView = /*@__PURE__*/ (() => {
    class AnchoredCategorySeriesView extends CategorySeriesView {
        constructor(a) {
            super(a);
            this.c0 = null;
            this.c1 = null;
            this.c0 = a;
        }
        get c2() {
            if (this.c1 == null) {
                this.c1 = CategoryTrendLineManagerFactory.a(this.c1, this.e.ar(), this.e.nd, this.e, this.e.cn);
            }
            return this.c1;
        }
        set c2(a) {
            this.c1 = a;
        }
        get c3() {
            return this.c1 != null;
        }
        c7() {
            this.c0.up = null;
        }
        c5() {
            this.c0.up = this.c0.trendLineBrush;
        }
        c4() {
            this.c0.up = this.c0.o3;
        }
        cs() {
            return new AnchoredCategoryBucketCalculator(this);
        }
        c6() {
            this.cr.cacheValues();
        }
        c8() {
            this.cr.unCacheValues();
        }
        c9(a) {
            let b = this.cu.item(a);
            return this.cp(b);
        }
        a5(a, b) {
            if (a.d) {
                if (this.c0.trendLineType != 0 && !b) {
                    let c = this.c2.g$j;
                    c.ac = this.c0.trendLineThickness;
                    c._stroke = this.c0.up;
                    c.ai = this.c0.uq;
                    c.ad = this.c0.ur;
                    a.v(c);
                }
            }
            super.a5(a, b);
        }
        getDefaultTooltipTemplate() {
            return this.c0.tq.c$c(this.e, this.c0.t5);
        }
    }
    AnchoredCategorySeriesView.$t = markType(AnchoredCategorySeriesView, 'AnchoredCategorySeriesView', CategorySeriesView.$);
    return AnchoredCategorySeriesView;
})();
