/*
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-react-core";
import { Point_$type, enumGetBox, typeCast, runOn, delegateCombine, markType, markDep } from "igniteui-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { Series } from "./Series";
import { TrendLineType_$type } from "igniteui-react-core";
import { Brush } from "igniteui-react-core";
import { PenLineCap_$type } from "igniteui-react-core";
import { DoubleCollection } from "igniteui-react-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-react-core";
import { DataLegendSeriesContext } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { ISortingAxis_$type } from "./ISortingAxis";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { NumericAxisBase } from "./NumericAxisBase";
import { CategoryBucketCalculator } from "./CategoryBucketCalculator";
import { AxisRange } from "./AxisRange";
import { NumericYAxis } from "./NumericYAxis";
import { ScalerParams } from "./ScalerParams";
import { SeriesLayerPropertyOverlay } from "./SeriesLayerPropertyOverlay";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { CollisionAvoider } from "./CollisionAvoider";
import { NonCollisionAvoider } from "./NonCollisionAvoider";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { CategoryTrendLineManagerFactory } from "./CategoryTrendLineManagerFactory";
/**
 * @hidden
 */
export let AnchoredCategorySeries = /*@__PURE__*/ (() => {
    class AnchoredCategorySeries extends CategorySeries {
        get xm() {
            if (this.xl == null) {
                this.xl = DVContainer.instance.createInstance(IAnchoredCategorySeriesInteractionManager_$type, () => this.da.n);
            }
            return this.xl;
        }
        getHostReferenceValue() {
            return this.h3();
        }
        k0() {
            return AnchoredCategorySeries.$$p[5];
        }
        cd() {
            let a = new AnchoredCategorySeriesView(this);
            return a;
        }
        o2(a) {
            super.o2(a);
            this.xh = a;
        }
        constructor() {
            super();
            this.xl = null;
            this.xq = false;
            this.xn = null;
            this.xi = null;
            this.xx = null;
            this.xw = null;
            this.xp = true;
            this.xr = 0;
            this.xs = 0;
            this.vt = new CategoryFramePreparer(1, this, this.vx, this, this, this.vx.cu);
        }
        jv(a, b) {
            let c = this.lw(b);
            if (c == AnchoredCategorySeries.$$p[5]) {
                return this.jw(a, b, this.x7);
            }
            if (c == AnchoredCategorySeries.$$p[1]) {
                return this.jw(a, b, this.xz);
            }
            return super.jv(a, b);
        }
        get valueColumn() {
            return this.xn;
        }
        set valueColumn(a) {
            if (this.xn != a) {
                let b = this.xn;
                this.xn = a;
                if (!this.xq) {
                    this.raisePropertyChanged("ValueColumn", b, this.xn);
                }
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = new DataLegendSeriesValueInfo();
            c.a = 0;
            c.l = this.ia({ $type: Point_$type, x: a, y: b }, false, false);
            c.q = this.x7 != null ? this.x7 : "Value";
            c.p = "Value";
            c.r = this.x3 != null ? this.x3 : "V:";
            c.s = this.x5 != null ? this.x5 : "";
            let d = new DataLegendSeriesContext();
            d.f = ((() => {
                let $ret = new List$1(DataLegendSeriesValueInfo.$, 0);
                $ret.add(c);
                return $ret;
            })());
            d.b = this.aw();
            return d;
        }
        get yu() {
            return this.c(AnchoredCategorySeries.yg);
        }
        set yu(a) {
            this.h(AnchoredCategorySeries.yg, a);
        }
        fp(a) {
            let b = new Rect(0, 0, 0, 1, 1);
            let c = this.fetchXAxis();
            let d = this.fetchYAxis();
            let e = this.ts(this.cg);
            let f = c != null ? this.vt.r(typeCast(ICategoryScaler_$type, c), b, b, e) : 0;
            return this.xm.c$a(this, this.valueColumn, c, d, f, a);
        }
        xe(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.cn;
            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.c7.item(g);
            }
            return d;
        }
        pa(a, b, c, d) {
            super.pa(a, b, c, d);
            if (this.xh.c6 && this.xh.c5.g$b(a, b, c, d)) {
                let e = false;
                if (b == "FastItemsSource") {
                    e = this.fr && c != null;
                }
                this.pr(e);
                this.om();
            }
            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.c4(this.x7);
                    }
                    let f = typeCast(NumericAxisBase.$, this.fetchYAxis());
                    if (f != null && !f.c1()) {
                        this.xh.cu.g(this.hk);
                        this.pr(this.fr && c != null);
                    }
                    break;
                case AnchoredCategorySeries.$$p[5]:
                    if (this.c7 != null) {
                        this.c7.deregisterColumn(this.valueColumn);
                        this.valueColumn = this.c4(this.x7);
                    }
                    this.xx = this.x7;
                    break;
                case AnchoredCategorySeries.$$p[1]:
                    this.xw = this.xz;
                    this.pr(true);
                    break;
                case "ValueColumn":
                    if (this.xh.c6) {
                        this.xh.c5.g$i();
                    }
                    let g = typeCast(NumericAxisBase.$, this.fetchYAxis());
                    if (g != null && !g.c1()) {
                        this.xh.cu.g(this.hk);
                        this.pr(this.fr && this.dp);
                    }
                    this.yf();
                    this.ql();
                    break;
                case "TrendLineBrush":
                    this.pg(b);
                    break;
                case "ErrorBarSettings":
                    this.pr(false);
                    break;
                case "TrendLineType":
                    this.om();
                    break;
                case AnchoredCategorySeries.$$p[2]:
                    this.pr(false);
                    break;
            }
        }
        aq(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;
        }
        np(a, b, c, d) {
            switch (a) {
                case 4:
                case 1:
                case 0:
                    this.xh.cu.g(this.hk);
                    break;
            }
            if (this.xh.c6) {
                this.xh.c5.g$e(a, b, c, d);
            }
            this.yf();
            this.ql();
            if (a == 0 || a == 2 || a == 3 || a == 4) {
                this.xp = true;
            }
            else if (a == 1) {
                for (let e = b; e < b + c; e++) {
                    this.xr += this.valueColumn.item(e);
                }
                this.xs = this.xr / this.valueColumn.count;
            }
        }
        wo() {
            return this.xt(this.vx);
        }
        xt(a) {
            let b = 0;
            let c = a.by;
            let d = a.bx;
            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.ch, e);
                if (f.cp) {
                    g.b = this.h3();
                }
                b = f.ej(f.l7, g);
            }
            return b;
        }
        yd(a, b, c) {
            let d = this.xt(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 });
            }
        }
        xf(a, b, c, d) {
            return this.xg(a, b, c, d, false);
        }
        xg(a, b, c, d, e) {
            return CategorySeries.vi(a, b, c, d, e);
        }
        fo() {
            return this.highlightedItemsSource != null || this.xz != null;
        }
        g1() {
            let a = super.g1();
            {
                let b = ((() => {
                    let $ret = new SeriesLayerPropertyOverlay();
                    $ret.ad = "ValueMemberPath";
                    $ret.p = true;
                    $ret.y = "HighlightedValueMemberPath";
                    $ret.q = true;
                    return $ret;
                })());
                b.valueResolving = delegateCombine(b.valueResolving, runOn(this, this.x9));
                a.add(b);
            }
            return a;
        }
        x9(a, b) {
            if (this.xz != null) {
                b.value = this.xz;
                return;
            }
            b.value = this.x7;
        }
        gm(a, b, c) {
            let d = super.gm(a, b, c);
            let e = c;
            if (this.valueColumn == null || this.valueColumn.count == 0 || e.cu.d < 1) {
                d = false;
            }
            return d;
        }
        nk(a, b) {
            super.nk(a, b);
            let c = b;
            c.c0();
            if (c.c6) {
                c.c5.g$d();
            }
        }
        w4(a, b) {
            super.w4(a, b);
            this.vu(b).d(a, b);
        }
        w7(a, b) {
            super.w7(a, b);
            let c = typeCast(AnchoredCategorySeriesView.$, b);
            c.b6 = true;
            if (c.c6) {
                c.c5.g$g(a.p);
            }
            if (this.ue()) {
                CategoryMarkerManager.e(this, a.m, b.cx, this.ug);
                this.w1(b, a);
                b.cp();
            }
            this.ya(a, b);
        }
        pq(a, b, c, d, e) {
            super.pq(a, b, c, d, e);
            let f = this.a3.a$h.item(d);
            let g = f;
            g.cu.g(this.hk);
            f.a3(c);
            if (this.dm(g)) {
                return;
            }
            if (this.xi == null) {
                this.xi = new CategoryFrame(3);
            }
            this.xi.u();
            this.w4(this.xi, g);
            this.w7(this.xi, g);
        }
        ya(a, b) {
        }
        qf() {
            super.qf();
            if (this.index < 0) {
                return;
            }
            this.xh.da();
            if (this.trendLineBrush != null) {
                this.xh.c8();
            }
            else {
                this.xh.c7();
            }
        }
        jz(a, b) {
            if (this.xh.c6 && a == this.xh.c5.g$j) {
                return null;
            }
            return super.jz(a, b);
        }
        get currentCategoryMode() {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.vn()));
        }
        get scaler() {
            return typeCast(ICategoryScaler_$type, this.vn());
        }
        get yScaler() {
            return typeCast(IScaler_$type, this.v3());
        }
        get bucketizer() {
            return this.xh.cu;
        }
        get currentMode2Index() {
            return this.ws();
        }
        provideCollisionDetector() {
            if (this.xj == 1) {
                return new CollisionAvoider();
            }
            return NonCollisionAvoider.b;
        }
        get trendlinePreparer() {
            return this.xh.c6 ? this.xh.c5 : null;
        }
        n2(a) {
            super.n2(a);
            if (this.xh.c6) {
                this.a5.exportTrendlineData(this, a, this.xh.c5.g$j);
            }
        }
        js(a) {
            let b = this.fetchXAxis();
            let c = this.fetchYAxis();
            return this.xm.c$b(this, a, this.wp(this.cg), this.valueColumn, b, c, this.xk == 1, (d) => super.js(d));
        }
        get mayContainUnknowns() {
            return this.valueColumn == null || this.valueColumn.mayContainUnknowns;
        }
        h3() {
            return Series.h4(this.valueColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
        }
        get_xv() {
            return 0;
        }
        get xv() {
            return this.get_xv();
        }
        ar(a) {
            if (a.isEmpty && this.cv != null) {
                a = this.cv.tr;
            }
            if (this.valueColumn == null) {
                return null;
            }
            let b = this.tq(this.cg);
            let c = this.vn();
            let d = new ScalerParams(0, a, this.cv.t6, c.ch, this.getEffectiveViewport());
            let e = (c.em(b.left, d));
            let f = (c.em(b.right, d));
            if (c.ch) {
                let g = e;
                e = f;
                f = g;
            }
            e -= this.xv;
            f += this.xv;
            let h = null;
            if (c.cn) {
                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.ap(n, this.v3(), a);
            return n;
        }
        yf() {
            this.hs = this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(this.valueColumn.count - 1);
        }
        ye() {
            if (this.xp) {
                this.xr = 0;
                for (let a = 0; a < this.valueColumn.count; a++) {
                    this.xr += this.valueColumn.item(a);
                }
                this.xs = this.xr / this.valueColumn.count;
                this.xp = false;
            }
        }
        id(a, b) {
            if (b == null || !b.cj) {
                return NaN;
            }
            let c = this.v3();
            if (b != c) {
                return NaN;
            }
            let d = this.am(a);
            if (c.cp) {
                return d[1];
            }
            else {
                return d[0];
            }
        }
        am(a) {
            let b = NaN;
            switch (a) {
                case 5:
                case 2:
                    b = this.valueColumn.maximum;
                    break;
                case 4:
                case 1:
                    b = this.valueColumn.minimum;
                    break;
                case 6:
                case 3:
                    if (this.xp) {
                        this.ye();
                    }
                    b = this.xs;
                    break;
            }
            let c = this.v3();
            if (c.cp) {
                return [NaN, b];
            }
            else {
                return [b, NaN];
            }
        }
        tm(a) {
            let b = NaN;
            switch (a) {
                case 5:
                case 2:
                    b = this.valueColumn.maximum;
                    break;
                case 4:
                case 1:
                    b = this.valueColumn.minimum;
                    break;
                case 6:
                case 3:
                    if (this.xp) {
                        this.ye();
                    }
                    b = this.xs;
                    break;
            }
            if (isNaN_(b)) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let c = this.v3();
            let d = this.getEffectiveViewport1(this.cg);
            let e = new ScalerParams(0, this.cg.by, this.cg.bx, c.ch, d);
            if (c.cp) {
                e.b = this.h3();
            }
            e.c = d;
            if (c.cp) {
                return { $type: Point_$type, x: NaN, y: c.ej(b, e) };
            }
            else {
                return { $type: Point_$type, x: c.ej(b, e), y: NaN };
            }
        }
        tn(a) {
            let b = this.v3();
            let c = this.getEffectiveViewport1(this.cg);
            let d = new ScalerParams(0, this.cg.by, this.cg.bx, b.ch, c);
            if (b.cp) {
                d.b = this.h3();
            }
            d.c = c;
            if (b.cp) {
                return { $type: Point_$type, x: NaN, y: b.ej(a[1], d) };
            }
            else {
                return { $type: Point_$type, x: b.ej(a[0], d), y: NaN };
            }
        }
        get useHighMarkerFidelity() {
            return this.wk;
        }
    }
    AnchoredCategorySeries.$t = /*@__PURE__*/ markType(AnchoredCategorySeries, 'AnchoredCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasSingleValueCategory_$type, IHasCategoryTrendline_$type, ITrendLineSeries_$type]);
    AnchoredCategorySeries.yg = /*@__PURE__*/ DependencyProperty.i("ActualTrendLineBrush", Brush.$, AnchoredCategorySeries.$, /*@__PURE__*/ new PropertyMetadata(2, null, (a, b) => a.raisePropertyChanged("ActualTrendLineBrush", b.oldValue, b.newValue)));
    AnchoredCategorySeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, AnchoredCategorySeries, 'raisePropertyChanged', ['ConsolidatedItemHitTestBehavior:xk:yh', [ConsolidatedItemHitTestBehavior_$type, /*@__PURE__*/ enumGetBox(ConsolidatedItemHitTestBehavior_$type, 0)], 'HighlightedValueMemberPath:xz:yi', [2, null], 'MarkerCollisionAvoidance:xj:yj', [CategorySeriesMarkerCollisionAvoidance_$type, /*@__PURE__*/ enumGetBox(CategorySeriesMarkerCollisionAvoidance_$type, 1)], 'ValueMemberAsLegendLabel:x3:yr', [2, null], 'ValueMemberAsLegendUnit:x5:ys', [2, null], 'ValueMemberPath:x7:yt', [2, null], 'TrendLineType::yp', [TrendLineType_$type, /*@__PURE__*/ enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::yo', [1, 1.5], 'TrendLinePeriod::yn', [1, 7], 'TrendLineBrush::yk', [Brush.$, null], 'TrendLineZIndex:xu:yq', [1, 1001], 'TrendLineDashArray:yv:yl', [DoubleCollection.$], 'TrendLineDashCap:yw:ym', [PenLineCap_$type, /*@__PURE__*/ 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.c3.valueColumn.count;
            this.h = this.i.c3.valueColumn.asArray();
        }
        unCacheValues() {
            this.h = null;
        }
    }
    AnchoredCategoryBucketCalculator.$t = /*@__PURE__*/ markType(AnchoredCategoryBucketCalculator, 'AnchoredCategoryBucketCalculator', CategoryBucketCalculator.$);
    return AnchoredCategoryBucketCalculator;
})();
/**
 * @hidden
 */
export let AnchoredCategorySeriesView = /*@__PURE__*/ (() => {
    class AnchoredCategorySeriesView extends CategorySeriesView {
        constructor(a) {
            super(a);
            this.c3 = null;
            this.c4 = null;
            this.c3 = a;
        }
        get c5() {
            if (this.c4 == null) {
                this.c4 = CategoryTrendLineManagerFactory.a(this.c4, this.e.as(), this.e.qt, this.e, this.e.da);
            }
            return this.c4;
        }
        set c5(a) {
            this.c4 = a;
        }
        get c6() {
            return this.c4 != null;
        }
        da() {
            this.c3.yu = null;
        }
        c8() {
            this.c3.yu = this.c3.trendLineBrush;
        }
        c7() {
            this.c3.yu = this.c3.su;
        }
        cv() {
            return new AnchoredCategoryBucketCalculator(this);
        }
        c9() {
            this.cu.cacheValues();
        }
        db() {
            this.cu.unCacheValues();
        }
        dc(a) {
            let b = this.cx.item(a);
            return this.cs(b);
        }
        a7(a, b) {
            if (a.d) {
                if (this.c3.trendLineType != 0 && !b) {
                    let c = this.c5.g$j;
                    c.ad = this.c3.trendLineThickness;
                    c._stroke = this.c3.yu;
                    c.ai = this.c3.yv;
                    c.aj = this.c3.yw;
                    a.v(c);
                }
            }
            super.a7(a, b);
        }
        getDefaultTooltipTemplate() {
            return this.c3.xm.c$c(this.e, this.c3.x7);
        }
    }
    AnchoredCategorySeriesView.$t = /*@__PURE__*/ markType(AnchoredCategorySeriesView, 'AnchoredCategorySeriesView', CategorySeriesView.$);
    return AnchoredCategorySeriesView;
})();
