/*
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 { CategoryBucketCalculator } from "./CategoryBucketCalculator";
import { markType, typeCast, markDep, Point_$type } from "igniteui-react-core";
import { isNaN_, truncate, isInfinity } from "igniteui-react-core";
import { CategorySeries } from "./CategorySeries";
import { IIsCategoryBased_$type } from "./IIsCategoryBased";
import { IHasHighLowValueCategory_$type } from "./IHasHighLowValueCategory";
import { RangeCategoryFramePreparer } from "./RangeCategoryFramePreparer";
import { DependencyProperty } from "igniteui-react-core";
import { Series } from "./Series";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { ICategoryScaler_$type } from "./ICategoryScaler";
import { IScaler_$type } from "./IScaler";
import { CategorySeriesView } from "./CategorySeriesView";
import { CategoryFrame } from "./CategoryFrame";
import { CategoryMarkerManager } from "./CategoryMarkerManager";
import { AxisRange } from "./AxisRange";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { ISortingAxis_$type } from "./ISortingAxis";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { CollisionAvoider } from "./CollisionAvoider";
import { ISupportsMarkers_$type } from "./ISupportsMarkers";
import { PropertyMetadata } from "igniteui-react-core";
import { FastFlattener } from "igniteui-react-core";
/**
 * @hidden
 */
export let RangeCategoryBucketCalculator = /*@__PURE__*/ (() => {
    class RangeCategoryBucketCalculator extends CategoryBucketCalculator {
        constructor(a) {
            super(a);
            this.j = null;
            this.l = 0;
            this.k = 0;
            this.i = null;
            this.h = null;
            this.j = a;
        }
        getBucketWithoutUnknowns(a) {
            let b = false;
            let c = this.i;
            let d = this.h;
            let e = this.l;
            let f = this.k;
            let g = Math.min(e, f);
            let h = a * this.d;
            let i = Math.min(h + this.d - 1, g - 1);
            let j = 1.7976931348623157E+308;
            let k = -1.7976931348623157E+308;
            let l = true;
            let m = 0;
            let n = 0;
            let o;
            let p;
            for (let q = h; q <= i; ++q) {
                m = c[q];
                n = d[q];
                if (m < n) {
                    o = m;
                    p = n;
                }
                else {
                    p = m;
                    o = n;
                }
                if (!l) {
                    j = j < o ? j : o;
                    k = k > o ? k : o;
                    j = j < p ? j : p;
                    k = k > p ? k : p;
                }
                else {
                    j = Math.min(j, o);
                    k = Math.max(k, o);
                    k = Math.max(k, p);
                    j = Math.min(j, p);
                    l = false;
                }
            }
            if (b && n < m) {
                let r = j;
                j = k;
                k = r;
            }
            if (!l) {
                let s = new Array(3);
                s[0] = 0.5 * (h + i);
                s[1] = j;
                s[2] = k;
                return s;
            }
            let t = new Array(3);
            t[0] = NaN;
            t[1] = NaN;
            t[2] = NaN;
            return t;
        }
        getBucket(a) {
            let b = false;
            let c = this.i;
            let d = this.h;
            let e = this.l;
            let f = this.k;
            let g = Math.min(e, f);
            let h = a * this.d;
            let i = Math.min(h + this.d - 1, g - 1);
            let j = NaN;
            let k = NaN;
            let l = true;
            let m = 0;
            let n = 0;
            let o;
            let p;
            for (let q = h; q <= i; ++q) {
                m = c[q];
                n = d[q];
                if (m < n) {
                    o = m;
                    p = n;
                }
                else {
                    p = m;
                    o = n;
                }
                if (!l) {
                    if (!isNaN_(o)) {
                        j = j < o ? j : o;
                        k = k > o ? k : o;
                    }
                    if (!isNaN_(p)) {
                        j = j < p ? j : p;
                        k = k > p ? k : p;
                    }
                }
                else {
                    if (!isNaN_(o)) {
                        if (isNaN_(j)) {
                            j = o;
                        }
                        else {
                            j = Math.min(j, o);
                        }
                        if (!isNaN_(k)) {
                            k = Math.max(k, o);
                        }
                    }
                    if (!isNaN_(p)) {
                        if (isNaN_(k)) {
                            k = p;
                        }
                        else {
                            k = Math.max(k, p);
                        }
                        if (!isNaN_(j)) {
                            j = Math.min(j, p);
                        }
                    }
                    if (!isNaN_(j) && !isNaN_(k)) {
                        l = false;
                    }
                }
            }
            if (n < m && b) {
                let r = j;
                j = k;
                k = r;
            }
            if (!l) {
                let s = new Array(3);
                s[0] = 0.5 * (h + i);
                s[1] = j;
                s[2] = k;
                return s;
            }
            let t = new Array(3);
            t[0] = NaN;
            t[1] = NaN;
            t[2] = NaN;
            return t;
        }
        cacheValues() {
            this.l = this.j.c0.lowColumn.count;
            this.k = this.j.c0.highColumn.count;
            this.i = this.j.c0.lowColumn.asArray();
            this.h = this.j.c0.highColumn.asArray();
        }
        unCacheValues() {
            this.i = null;
            this.h = null;
        }
    }
    RangeCategoryBucketCalculator.$t = /*@__PURE__*/ markType(RangeCategoryBucketCalculator, 'RangeCategoryBucketCalculator', CategoryBucketCalculator.$);
    return RangeCategoryBucketCalculator;
})();
/**
 * @hidden
 */
export let RangeCategorySeries = /*@__PURE__*/ (() => {
    class RangeCategorySeries extends CategorySeries {
        constructor() {
            super();
            this._RangeFramePreparer = null;
            this.rn = null;
            this.rm = null;
            this.rj = null;
            this.RangeFramePreparer = new RangeCategoryFramePreparer(1, this, this.rl, this, this, this.rl.cr);
        }
        bp() {
            return new RangeCategorySeriesView(this);
        }
        getHostReferenceValue() {
            return this.fa();
        }
        kk(a) {
            super.kk(a);
            this.rl = a;
        }
        get RangeFramePreparer() {
            return this._RangeFramePreparer;
        }
        set RangeFramePreparer(a) {
            this._RangeFramePreparer = a;
        }
        gt(a, b) {
            let c = this.ic(b);
            if (c == RangeCategorySeries.$$p[0]) {
                return this.gu(a, b, this.rr);
            }
            if (c == RangeCategorySeries.$$p[0]) {
                return this.gu(a, b, this.rr);
            }
            return super.gt(a, b);
        }
        get lowColumn() {
            return this.rn;
        }
        set lowColumn(a) {
            if (this.rn != a) {
                let b = this.rn;
                this.rn = a;
                this.raisePropertyChanged("LowColumn", b, this.rn);
            }
        }
        get highColumn() {
            return this.rm;
        }
        set highColumn(a) {
            if (this.rm != a) {
                let b = this.rm;
                this.rm = a;
                this.raisePropertyChanged("HighColumn", b, this.rm);
            }
        }
        p4() {
            return 11;
        }
        rc(a, b) {
            super.rc(a, b);
            b.b3 = true;
            CategoryMarkerManager.e(this, a.m, b.cu, this.om);
            this.q6(b, a);
        }
        rw(a, b, c, d, e, f) {
            this.rl.c1(a, b, c, d, e, f);
        }
        ap(a) {
            if (a.isEmpty && this.b6 != null) {
                a = this.b6.os;
            }
            let b = this.pu();
            if (this.lowColumn == null || this.highColumn == null) {
                return null;
            }
            let c = this.ny(this.bs);
            let d = new ScalerParams(0, a, this.b6.o7, b.ca, this.getEffectiveViewport());
            let e = (b.d2(c.left, d));
            let f = (b.d2(c.right, d));
            if (b.ca) {
                let g = e;
                e = f;
                f = g;
            }
            let h = null;
            if (b.cf) {
                h = b;
                e = h.i$f(e);
                f = h.i$f(f);
            }
            else {
                e = Math.floor(e);
                f = Math.ceil(f);
            }
            e = Math.max(0, Math.min(this.lowColumn.count - 1, e));
            f = Math.max(0, Math.min(this.lowColumn.count - 1, f));
            let i = 1.7976931348623157E+308;
            let j = -1.7976931348623157E+308;
            for (let k = truncate(e); k <= truncate(f); k++) {
                let l = k;
                if (h != null) {
                    l = h.i$b._inner[k];
                }
                let m = this.lowColumn.item(l);
                if (this.lowColumn.mayContainUnknowns) {
                    if (isInfinity(m) || isNaN_(m)) {
                        continue;
                    }
                }
                let n = this.highColumn.item(l);
                if (this.highColumn.mayContainUnknowns) {
                    if (isInfinity(n) || isNaN_(n)) {
                        continue;
                    }
                }
                i = Math.min(i, m);
                j = Math.max(j, n);
            }
            let o = new AxisRange(i, j);
            let p = this.qe();
            o = this.an(o, p, a);
            return o;
        }
        dq(a) {
            let b = new Rect(0, 0, 0, 1, 1);
            let c = this.bs != null ? this.bs.bv : Rect.empty;
            c = c.copy();
            let d = this.bs != null ? this.bs.bu : Rect.empty;
            let e = !c.isEmpty && !d.isEmpty && this.cd != null ? this.cd.indexOf(a) : -1;
            let f = this.fetchXAxis();
            let g = this.fetchYAxis();
            let h = this.n0(this.bs);
            let i;
            if (f != null) {
                let j = new ScalerParams(0, b, b, f.ca, h);
                i = f.dz(e, j);
            }
            else {
                i = NaN;
            }
            let k = f != null ? this.RangeFramePreparer.r(typeCast(ICategoryScaler_$type, f), b, b, h) : 0;
            i += k;
            if (e >= 0 && Rect.l_op_Inequality(c, null) && Rect.l_op_Inequality(d, null)) {
                if (!isNaN_(i)) {
                    if (i < c.left + 0.1 * c.width) {
                        i = i + 0.4 * c.width;
                    }
                    if (i > c.right - 0.1 * c.width) {
                        i = i - 0.4 * c.width;
                    }
                    c.x = i - 0.5 * c.width;
                }
                if (g != null && this.highColumn != null && e < this.highColumn.count) {
                    let l = new ScalerParams(0, b, b, g.ca, h);
                    l.b = this.fa();
                    let m = g.dz(this.highColumn.item(e), l);
                    let n = g.dz(this.lowColumn.item(e), l);
                    if (!isNaN_(m) && !isNaN_(n)) {
                        let o = Math.abs(n - m);
                        if (c.height < o) {
                            c.height = o;
                            c.y = Math.min(n, m);
                        }
                        else {
                            if (n < c.top + 0.1 * c.height) {
                                n = n + 0.4 * c.height;
                            }
                            if (n > c.bottom - 0.1 * c.height) {
                                n = n - 0.4 * c.height;
                            }
                            c.y = n - 0.5 * c.height;
                        }
                    }
                }
                if (this.b1 != null) {
                    this.b1.ap(this.b6, c, true);
                }
            }
            return e >= 0;
        }
        kp(a, b, c, d) {
            super.kp(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.lowColumn);
                        c.deregisterColumn(this.highColumn);
                        this.lowColumn = null;
                        this.highColumn = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.lowColumn = this.ca(this.ru);
                        this.highColumn = this.ca(this.rr);
                    }
                    if (!this.qo()) {
                        this.p3.cr.g(this.fq);
                        this.k3(false);
                    }
                    break;
                case RangeCategorySeries.$$p[1]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.lowColumn);
                        this.lowColumn = this.ca(this.ru);
                    }
                    break;
                case "LowColumn":
                    if (!this.qo()) {
                        this.p3.cr.g(this.fq);
                        this.k3(false);
                    }
                    break;
                case RangeCategorySeries.$$p[0]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.highColumn);
                        this.highColumn = this.ca(this.rr);
                    }
                    break;
                case "HighColumn":
                    if (!this.qo()) {
                        this.p3.cr.g(this.fq);
                        this.k3(false);
                    }
                    break;
            }
        }
        ao(a) {
            if (this.lowColumn == null || this.lowColumn.count == 0 || this.highColumn == null || this.highColumn.count == 0) {
                return null;
            }
            if (a == this.fetchXAxis()) {
                let b = Math.min(this.lowColumn.count, this.highColumn.count);
                return new AxisRange(0, b - 1);
            }
            if (a == this.fetchYAxis()) {
                let c = Math.min(this.lowColumn.minimum, this.highColumn.minimum);
                let d = Math.max(this.lowColumn.maximum, this.highColumn.maximum);
                return new AxisRange(Math.min(c, d), Math.max(c, d));
            }
            return null;
        }
        jo(a, b, c, d) {
            if (this.fetchXAxis() != null && typeCast(ISortingAxis_$type, this.fetchXAxis()) !== null) {
                this.fetchXAxis().i$i();
            }
            let e = this.fetchXAxis();
            switch (a) {
                case 3:
                    if (d == this.ru || d == this.rr) {
                        if (e != null) {
                            e.cn();
                        }
                        if (!this.qo()) {
                            this.k3(true);
                        }
                    }
                    break;
                case 1:
                    if (e != null) {
                        e.cn();
                    }
                    this.p3.cr.g(this.fq);
                    if (!this.qo()) {
                        this.k3(true);
                    }
                    break;
                case 0:
                    if (e != null) {
                        e.cn();
                    }
                    this.p3.cr.g(this.fq);
                    if (!this.qo()) {
                        this.k3(true);
                    }
                    break;
                case 2:
                    if (e != null) {
                        e.cn();
                    }
                    if (this.ru != null && this.rr != null && this.p3.cr.d > 0 && !this.qo()) {
                        this.k3(true);
                    }
                    break;
                case 4:
                    if (e != null) {
                        e.cn();
                    }
                    this.p3.cr.g(this.fq);
                    if (!this.qo()) {
                        this.k3(true);
                    }
                    break;
            }
        }
        ec(a, b, c) {
            let d = super.ec(a, b, c);
            if (this.lowColumn == null || this.lowColumn.count == 0 || this.highColumn == null || this.highColumn.count == 0) {
                d = false;
            }
            return d;
        }
        q9(a, b) {
            super.q9(a, b);
            this.RangeFramePreparer.d(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.p3.cr;
        }
        get currentMode2Index() {
            return this.qx();
        }
        provideCollisionDetector() {
            return new CollisionAvoider();
        }
        get mayContainUnknowns() {
            return this.lowColumn == null || this.lowColumn.mayContainUnknowns || this.highColumn == null || this.highColumn.mayContainUnknowns;
        }
        k5(a, b) {
            let c = this.d2;
            super.k5(a, b);
            if (!c) {
                this.bs.a2(b);
                return;
            }
            this.bs.a2(b);
            if (this.cp(this.br)) {
                return;
            }
            let d = new RangeCategoryFramePreparer(1, this, typeCast(ISupportsMarkers_$type, this.br), this.b6.b8.o, this, this.br.cr);
            if (!this.dw) {
                this.px = new CategoryFrame(3);
                this.px.u();
                d.d(this.px, this.br);
            }
            this.dw = false;
            this.rc(this.px, this.br);
            this.d2 = false;
        }
        k2(a, b, c, d, e) {
            super.k2(a, b, c, d, e);
            let f = this.a3.a$h.item(d);
            let g = f;
            g.cr.g(this.fq);
            f.a1(c);
            if (this.cp(g)) {
                return;
            }
            let h = new RangeCategoryFramePreparer(1, this, typeCast(ISupportsMarkers_$type, f), f, this, f.cr);
            if (this.rj == null) {
                this.rj = new CategoryFrame(3);
            }
            this.rj.u();
            h.d(this.rj, g);
            this.rc(this.rj, g);
        }
        fa() {
            return Series.fb(this.lowColumn, typeCast(ISortingAxis_$type, this.fetchXAxis()));
        }
        get useHighMarkerFidelity() {
            return this.qp;
        }
    }
    RangeCategorySeries.$t = /*@__PURE__*/ markType(RangeCategorySeries, 'RangeCategorySeries', CategorySeries.$, [IIsCategoryBased_$type, IHasHighLowValueCategory_$type]);
    RangeCategorySeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, RangeCategorySeries, 'raisePropertyChanged', ['HighMemberPath:rr:rx', [2, null], 'LowMemberPath:ru:ry', [2, null]]);
    return RangeCategorySeries;
})();
/**
 * @hidden
 */
export let RangeCategorySeriesView = /*@__PURE__*/ (() => {
    class RangeCategorySeriesView extends CategorySeriesView {
        constructor(a) {
            super(a);
            this.c0 = null;
            this.c0 = a;
        }
        c1(a, b, c, d, e, f) {
            a.ak.clear();
            b.ak.clear();
            c.ak.clear();
            let g = FastFlattener.b(d, e, true, f, this.e.fq);
            let h = FastFlattener.b(d, e, false, f, this.e.fq);
            let i = g.count;
            let j = h.count;
            let k;
            let l;
            let m;
            let n;
            for (let o = 0; o < i; o++) {
                k = g.item(o);
                l = e._inner[k];
                m = l[0];
                n = l[1];
                a.ak.add({ $type: Point_$type, x: m, y: n });
                b.ak.add({ $type: Point_$type, x: m, y: n });
            }
            let p;
            let q;
            for (let r = 0; r < j; r++) {
                k = h.item(r);
                l = e._inner[k];
                if (f) {
                    p = l[0];
                    q = l[2];
                }
                else {
                    p = l[2];
                    q = l[3];
                }
                c.ak.add({ $type: Point_$type, x: p, y: q });
                b.ak.add({ $type: Point_$type, x: p, y: q });
            }
            a.ab = a.ak.count > 0;
            b.ab = b.ak.count > 0;
            c.ab = c.ak.count > 0;
        }
        cs() {
            return new RangeCategoryBucketCalculator(this);
        }
    }
    RangeCategorySeriesView.$t = /*@__PURE__*/ markType(RangeCategorySeriesView, 'RangeCategorySeriesView', CategorySeriesView.$);
    return RangeCategorySeriesView;
})();
//# sourceMappingURL=RangeCategoryBucketCalculator_combined.js.map
