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