/*
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 xk() {
            if (this.xj == null) {
                this.xj = DVContainer.instance.createInstance(IAnchoredCategorySeriesInteractionManager_$type, () => this.c9.n);
            }
            return this.xj;
        }
        getHostReferenceValue() {
            return this.h2();
        }
        kz() {
            return AnchoredCategorySeries.$$p[5];
        }
        cg() {
            let a = new AnchoredCategorySeriesView(this);
            return a;
        }
        o0(a) {
            super.o0(a);
            this.xf = a;
        }
        constructor() {
            super();
            this.xj = null;
            this.xo = false;
            this.xl = null;
            this.xg = null;
            this.xv = null;
            this.xu = null;
            this.xn = true;
            this.xp = 0;
            this.xq = 0;
            this.vr = new CategoryFramePreparer(1, this, this.vv, this, this, this.vv.cu);
        }
        ju(a, b) {
            let c = this.lv(b);
            if (c == AnchoredCategorySeries.$$p[5]) {
                return this.jv(a, b, this.x5);
            }
            if (c == AnchoredCategorySeries.$$p[1]) {
                return this.jv(a, b, this.xx);
            }
            return super.ju(a, b);
        }
        get valueColumn() {
            return this.xl;
        }
        set valueColumn(a) {
            if (this.xl != a) {
                let b = this.xl;
                this.xl = a;
                if (!this.xo) {
                    this.raisePropertyChanged("ValueColumn", b, this.xl);
                }
            }
        }
        getDataLegendSeriesContextAt(a, b) {
            let c = new DataLegendSeriesValueInfo();
            c.a = 0;
            c.l = this.h9({ $type: Point_$type, x: a, y: b }, false, false);
            c.q = this.x5 != null ? this.x5 : "Value";
            c.p = "Value";
            c.r = this.x1 != null ? this.x1 : "V:";
            c.s = this.x3 != null ? this.x3 : "";
            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 ys() {
            return this.c(AnchoredCategorySeries.ye);
        }
        set ys(a) {
            this.h(AnchoredCategorySeries.ye, a);
        }
        fo(a) {
            let b = new Rect(0, 0, 0, 1, 1);
            let c = this.fetchXAxis();
            let d = this.fetchYAxis();
            let e = this.tq(this.cj);
            let f = c != null ? this.vr.r(typeCast(ICategoryScaler_$type, c), b, b, e) : 0;
            return this.xk.c$a(this, this.valueColumn, c, d, f, a);
        }
        xc(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.c6.item(g);
            }
            return d;
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            if (this.xf.c6 && this.xf.c5.g$b(a, b, c, d)) {
                let e = false;
                if (b == "FastItemsSource") {
                    e = this.fq && c != null;
                }
                this.pp(e);
                this.ol();
            }
            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.c3(this.x5);
                    }
                    let f = typeCast(NumericAxisBase.$, this.fetchYAxis());
                    if (f != null && !f.c1()) {
                        this.xf.cu.g(this.hj);
                        this.pp(this.fq && c != null);
                    }
                    break;
                case AnchoredCategorySeries.$$p[5]:
                    if (this.c6 != null) {
                        this.c6.deregisterColumn(this.valueColumn);
                        this.valueColumn = this.c3(this.x5);
                    }
                    this.xv = this.x5;
                    break;
                case AnchoredCategorySeries.$$p[1]:
                    this.xu = this.xx;
                    this.pp(true);
                    break;
                case "ValueColumn":
                    if (this.xf.c6) {
                        this.xf.c5.g$i();
                    }
                    let g = typeCast(NumericAxisBase.$, this.fetchYAxis());
                    if (g != null && !g.c1()) {
                        this.xf.cu.g(this.hj);
                        this.pp(this.fq && this.dn);
                    }
                    this.yd();
                    this.qj();
                    break;
                case "TrendLineBrush":
                    this.pe(b);
                    break;
                case "ErrorBarSettings":
                    this.pp(false);
                    break;
                case "TrendLineType":
                    this.ol();
                    break;
                case AnchoredCategorySeries.$$p[2]:
                    this.pp(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;
        }
        no(a, b, c, d) {
            switch (a) {
                case 4:
                case 1:
                case 0:
                    this.xf.cu.g(this.hj);
                    break;
            }
            if (this.xf.c6) {
                this.xf.c5.g$e(a, b, c, d);
            }
            this.yd();
            this.qj();
            if (a == 0 || a == 2 || a == 3 || a == 4) {
                this.xn = true;
            }
            else if (a == 1) {
                for (let e = b; e < b + c; e++) {
                    this.xp += this.valueColumn.item(e);
                }
                this.xq = this.xp / this.valueColumn.count;
            }
        }
        wm() {
            return this.xr(this.vv);
        }
        xr(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.h2();
                }
                b = f.ej(f.l7, g);
            }
            return b;
        }
        yb(a, b, c) {
            let d = this.xr(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 });
            }
        }
        xd(a, b, c, d) {
            return this.xe(a, b, c, d, false);
        }
        xe(a, b, c, d, e) {
            return CategorySeries.vg(a, b, c, d, e);
        }
        fn() {
            return this.highlightedItemsSource != null || this.xx != null;
        }
        g0() {
            let a = super.g0();
            {
                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.x7));
                a.add(b);
            }
            return a;
        }
        x7(a, b) {
            if (this.xx != null) {
                b.value = this.xx;
                return;
            }
            b.value = this.x5;
        }
        gl(a, b, c) {
            let d = super.gl(a, b, c);
            let e = c;
            if (this.valueColumn == null || this.valueColumn.count == 0 || e.cu.d < 1) {
                d = false;
            }
            return d;
        }
        nj(a, b) {
            super.nj(a, b);
            let c = b;
            c.c0();
            if (c.c6) {
                c.c5.g$d();
            }
        }
        w2(a, b) {
            super.w2(a, b);
            this.vs(b).d(a, b);
        }
        w5(a, b) {
            super.w5(a, b);
            let c = typeCast(AnchoredCategorySeriesView.$, b);
            c.b6 = true;
            if (c.c6) {
                c.c5.g$g(a.p);
            }
            if (this.uc()) {
                CategoryMarkerManager.e(this, a.m, b.cx, this.ue);
                this.wz(b, a);
                b.cp();
            }
            this.x8(a, b);
        }
        po(a, b, c, d, e) {
            super.po(a, b, c, d, e);
            let f = this.a7.a$h.item(d);
            let g = f;
            g.cu.g(this.hj);
            f.a3(c);
            if (this.dl(g)) {
                return;
            }
            if (this.xg == null) {
                this.xg = new CategoryFrame(3);
            }
            this.xg.u();
            this.w2(this.xg, g);
            this.w5(this.xg, g);
        }
        x8(a, b) {
        }
        qd() {
            super.qd();
            if (this.index < 0) {
                return;
            }
            this.xf.da();
            if (this.trendLineBrush != null) {
                this.xf.c8();
            }
            else {
                this.xf.c7();
            }
        }
        jy(a, b) {
            if (this.xf.c6 && a == this.xf.c5.g$j) {
                return null;
            }
            return super.jy(a, b);
        }
        get currentCategoryMode() {
            return this.preferredCategoryMode(typeCast(CategoryAxisBase.$, this.vl()));
        }
        get scaler() {
            return typeCast(ICategoryScaler_$type, this.vl());
        }
        get yScaler() {
            return typeCast(IScaler_$type, this.v6());
        }
        get bucketizer() {
            return this.xf.cu;
        }
        get currentMode2Index() {
            return this.wq();
        }
        provideCollisionDetector() {
            if (this.xh == 1) {
                return new CollisionAvoider();
            }
            return NonCollisionAvoider.b;
        }
        get trendlinePreparer() {
            return this.xf.c6 ? this.xf.c5 : null;
        }
        n1(a) {
            super.n1(a);
            if (this.xf.c6) {
                this.a9.exportTrendlineData(this, a, this.xf.c5.g$j);
            }
        }
        jr(a) {
            let b = this.fetchXAxis();
            let c = this.fetchYAxis();
            return this.xk.c$b(this, a, this.wn(this.cj), this.valueColumn, b, c, this.xi == 1, (d) => super.jr(d));
        }
        get mayContainUnknowns() {
            return this.valueColumn == null || this.valueColumn.mayContainUnknowns;
        }
        h2() {
            return Series.h3(this.valueColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
        }
        get_xt() {
            return 0;
        }
        get xt() {
            return this.get_xt();
        }
        ar(a) {
            if (a.isEmpty && this.cy != null) {
                a = this.cy.tn;
            }
            if (this.valueColumn == null) {
                return null;
            }
            let b = this.to(this.cj);
            let c = this.vl();
            let d = new ScalerParams(0, a, this.cy.t2, 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.xt;
            f += this.xt;
            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.v6(), a);
            return n;
        }
        yd() {
            this.hr = this.valueColumn == null || this.valueColumn.count == 0 ? NaN : this.valueColumn.item(this.valueColumn.count - 1);
        }
        yc() {
            if (this.xn) {
                this.xp = 0;
                for (let a = 0; a < this.valueColumn.count; a++) {
                    this.xp += this.valueColumn.item(a);
                }
                this.xq = this.xp / this.valueColumn.count;
                this.xn = false;
            }
        }
        ic(a, b) {
            if (b == null || !b.cj) {
                return NaN;
            }
            let c = this.v6();
            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.xn) {
                        this.yc();
                    }
                    b = this.xq;
                    break;
            }
            let c = this.v6();
            if (c.cp) {
                return [NaN, b];
            }
            else {
                return [b, NaN];
            }
        }
        tk(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.xn) {
                        this.yc();
                    }
                    b = this.xq;
                    break;
            }
            if (isNaN_(b)) {
                return { $type: Point_$type, x: NaN, y: NaN };
            }
            let c = this.v6();
            let d = this.getEffectiveViewport1(this.cj);
            let e = new ScalerParams(0, this.cj.by, this.cj.bx, c.ch, d);
            if (c.cp) {
                e.b = this.h2();
            }
            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 };
            }
        }
        tl(a) {
            let b = this.v6();
            let c = this.getEffectiveViewport1(this.cj);
            let d = new ScalerParams(0, this.cj.by, this.cj.bx, b.ch, c);
            if (b.cp) {
                d.b = this.h2();
            }
            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.wi;
        }
    }
    AnchoredCategorySeries.$t = /*@__PURE__*/ markType(AnchoredCategorySeries, 'AnchoredCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasSingleValueCategory_$type, IHasCategoryTrendline_$type, ITrendLineSeries_$type]);
    AnchoredCategorySeries.ye = /*@__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:xi:yf', [ConsolidatedItemHitTestBehavior_$type, /*@__PURE__*/ enumGetBox(ConsolidatedItemHitTestBehavior_$type, 0)], 'HighlightedValueMemberPath:xx:yg', [2, null], 'MarkerCollisionAvoidance:xh:yh', [CategorySeriesMarkerCollisionAvoidance_$type, /*@__PURE__*/ enumGetBox(CategorySeriesMarkerCollisionAvoidance_$type, 1)], 'ValueMemberAsLegendLabel:x1:yp', [2, null], 'ValueMemberAsLegendUnit:x3:yq', [2, null], 'ValueMemberPath:x5:yr', [2, null], 'TrendLineType::yn', [TrendLineType_$type, /*@__PURE__*/ enumGetBox(TrendLineType_$type, 0)], 'TrendLineThickness::ym', [1, 1.5], 'TrendLinePeriod::yl', [1, 7], 'TrendLineBrush::yi', [Brush.$, null], 'TrendLineZIndex:xs:yo', [1, 1001], 'TrendLineDashArray:yt:yj', [DoubleCollection.$], 'TrendLineDashCap:yu:yk', [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.qr, this.e, this.e.c9);
            }
            return this.c4;
        }
        set c5(a) {
            this.c4 = a;
        }
        get c6() {
            return this.c4 != null;
        }
        da() {
            this.c3.ys = null;
        }
        c8() {
            this.c3.ys = this.c3.trendLineBrush;
        }
        c7() {
            this.c3.ys = this.c3.ss;
        }
        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.ys;
                    c.ai = this.c3.yt;
                    c.aj = this.c3.yu;
                    a.v(c);
                }
            }
            super.a7(a, b);
        }
        getDefaultTooltipTemplate() {
            return this.c3.xk.c$c(this.e, this.c3.x5);
        }
    }
    AnchoredCategorySeriesView.$t = /*@__PURE__*/ markType(AnchoredCategorySeriesView, 'AnchoredCategorySeriesView', CategorySeriesView.$);
    return AnchoredCategorySeriesView;
})();
