/*
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 { TimeAxisBase } from "./TimeAxisBase";
import { TimeAxisDisplayType_$type } from "./TimeAxisDisplayType";
import { DependencyProperty } from "igniteui-react-core";
import { Base, enumGetBox, Number_$type, typeGetValue, typeCast, markType, markDep } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericYAxis } from "./NumericYAxis";
import { LinearNumericSnapper } from "./LinearNumericSnapper";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-react-core";
import { dateMinValue, dateFromTicks } from "igniteui-react-core";
import { timeSpanFromMilliseconds } from "igniteui-react-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
export let CategoryDateTimeXAxis = /*@__PURE__*/ (() => {
    class CategoryDateTimeXAxis extends TimeAxisBase {
        constructor() {
            super();
            this.mi = 0;
            this.mj = 0;
            this.ab = CategoryDateTimeXAxis.$;
            this.actualMinimumValue = (new Date());
            this.actualMaximumValue = (new Date());
        }
        get_b6() {
            return this.md == 0;
        }
        a3() {
            return new CategoryDateTimeXAxisView(this);
        }
        gy(a) {
            super.gy(a);
            this.mc = a;
        }
        get mk() {
            return this.mi;
        }
        set mk(a) {
            if (this.mk != a) {
                let b = this.mi;
                this.mi = a;
                this.g6("ActualInterval", b, this.mk);
            }
        }
        ea() {
            return this.mk;
        }
        get mo() {
            return typeGetValue(this.c(CategoryDateTimeXAxis.mz));
        }
        set mo(a) {
            this.h(CategoryDateTimeXAxis.mz, a);
        }
        get ml() {
            return this.mj;
        }
        set ml(a) {
            if (this.ml != a) {
                let b = this.mj;
                this.mj = a;
                this.g6("ActualMinorInterval", b, this.ml);
            }
        }
        ct(a, b, c) {
            let d = super.ct(a, b, c);
            if (!d) {
                return false;
            }
            return +(this.actualMinimumValue) != +(this.actualMaximumValue);
        }
        dm() {
            return this.mk;
        }
        hd(a) {
            super.hd(a);
            let b = this.bh != null ? this.bh.os : Rect.empty;
            let c = !b.isEmpty ? this.ja : Rect.empty;
            let d = this.i5();
            let e = this.i4();
            let f = new ScalerParams(0, b, c, this.ca, d);
            if (this.k6 == null && !this.lc() && !this.ld()) {
                return;
            }
            if (!b.isEmpty && !c.isEmpty && (this.md != 1 || this.k6 != null)) {
                let g = c.bottom;
                let h = g - c.top;
                if (this.ai != null) {
                    let i = typeCast(NumericYAxis.$, this.ai);
                    if (i != null) {
                        let j = this.hh(g, h, b, c, d, c.top, c.bottom);
                        g = j.p0;
                        h = j.p1;
                    }
                }
                if (isNaN_(g)) {
                    g = 0;
                }
                this.gw(this.a4.ay(), g, c, this.a4.e(), true);
                this.av.a9 = h;
                let k = this.a4.a1();
                let l = this.a4.f();
                let m = this.a4.az();
                let n = this.a4.a0();
                let o = this.a4.g();
                if (this.md == 1) {
                    let p = this.i$e(b, c, d, e);
                    let q = this.i$g(b, c, d, e);
                    if (p < 0 || q < 0) {
                        return;
                    }
                    let r = NaN;
                    for (let s = p; s <= q; s++) {
                        let t = this.lf == null ? s : this.lf._inner[s];
                        let u = this.dz(this.k6.item(t).getTime(), f);
                        if (u == r) {
                            continue;
                        }
                        r = u;
                        if (this.categoryMode == 2) {
                            u += this.ca ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                        }
                        if (u < e.left || u > e.right) {
                            continue;
                        }
                        this.hm(m, u, c, l, false);
                        this.jv.add(u);
                        if (this.jo != null && s < this.jo.count) {
                            let v = this.jo.item(t);
                            let w = super.e9(v);
                            if (!isNaN_(u) && !isInfinity(u) && w != null) {
                                if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                                }
                                else {
                                    this.cx.add1(w);
                                    this.cy.add(new LabelPosition(u));
                                }
                            }
                        }
                    }
                }
                else {
                    let x = this.d2(e.left, f);
                    let y = this.d2(e.right, f);
                    let z = Math.min(x, y);
                    let aa = Math.max(x, y);
                    let ab = new LinearNumericSnapper(0, z, aa, e.width, this.ec());
                    let ac = this.la ? this.mh() : ab.g;
                    this.mv(truncate(ac));
                    let ad = truncate(Math.floor((z - this.actualMinimumValue.getTime()) / ac));
                    let ae = truncate(Math.ceil((aa - this.actualMinimumValue.getTime()) / ac));
                    let af = 0;
                    if (this.categoryMode == 2) {
                        af = this.getGroupCenter(0, b, c, d);
                        af = this.ca ? -af : af;
                    }
                    let ag = truncate(Math.ceil(e.right));
                    let ah = truncate(Math.floor(e.left));
                    let ai = this.dz(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                    for (let aj = ad; aj <= ae; aj++) {
                        let ak = this.dz(this.actualMinimumValue.getTime() + (aj + 1) * ac, f) + af;
                        if (!isNaN_(ai) && !isInfinity(ai)) {
                            let al = truncate(Math.round(ai));
                            if (al <= ag) {
                                if (aj % 2 == 0) {
                                    this.hn(k, ai, ak, c);
                                }
                                this.hm(m, ai, c, l, false);
                                this.jv.add(ai);
                                if (this.cl) {
                                    let am = this.mm();
                                    if (am > 0 && am < ac) {
                                        if (ac / am < 20) {
                                            let an = ai;
                                            let ao = Math.abs(this.dz(this.actualMinimumValue.getTime() + am, f) - this.dz(this.actualMinimumValue.getTime(), f));
                                            while (an + ao < ak) {
                                                if (Math.abs(an + ao - ak) < 0.0001) {
                                                    break;
                                                }
                                                an += ao;
                                                if (an > 0) {
                                                    this.hm(n, an, c, o, false);
                                                }
                                            }
                                            this.mw(am);
                                        }
                                    }
                                    else {
                                        for (let ap = 1; ap < ab.i; ++ap) {
                                            let aq = this.dz(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                            this.hm(n, aq, c, o, false);
                                        }
                                        if (ab.i > 0) {
                                            this.mw(truncate((ac / ab.i)));
                                        }
                                    }
                                }
                            }
                            if (al >= ah && al <= ag) {
                                let ar = this.actualMinimumValue.getTime() + aj * ac;
                                let ticks_ = truncate(Math.floor(ar));
                                let as = (new Date(ticks_));
                                let at = this.e9(as);
                                if (at != null) {
                                    this.cx.add1(at);
                                    this.cy.add(new LabelPosition(ai));
                                }
                            }
                        }
                        ai = ak;
                    }
                }
                if ((this.ay == null || this.ay.visibility == 0) && this.ai != null) {
                    if (this.ay != null && (this.ay.location == 4 || this.ay.location == 5)) {
                        this.bh.ja();
                    }
                }
                this.av.a2 = this.cx;
                this.av.a3 = this.cy;
                this.kv();
            }
        }
        mh() {
            return this.mk;
        }
        mm() {
            return this.mo;
        }
        mv(a) {
            this.mk = a;
        }
        mw(a) {
            this.ml = a;
        }
        mf() {
            return this.mn != 0;
        }
        me() {
            return this.mk == 0;
        }
        mg(a) {
            return this.k6 == null ? dateMinValue() : this.k6.item(a);
        }
        mu(a, b) {
            if (a > b || this.jo == null || this.jo.count == 0) {
                return;
            }
            let c = (a.getTime() - this.actualMinimumValue.getTime()) / (this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            let d = (b.getTime() - this.actualMinimumValue.getTime()) / (this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.bh.o8 = new Rect(0, c, this.bh.o8.y, d - c, this.bh.o8.height);
        }
        g0(a, b, c, d) {
            super.g0(a, b, c, d);
            switch (b) {
                case CategoryDateTimeXAxis.$$p[0]:
                    this.ci = true;
                    this.av.ak = this.md == 1;
                    this.hc(false);
                    break;
                case CategoryDateTimeXAxis.$$p[1]:
                    this.ci = true;
                    this.hc(false);
                    break;
            }
        }
        l2() {
            super.l2();
            if (this.mf()) {
                this.mk = this.mn;
                let a = this.bh != null ? this.bh.os : Rect.empty;
                let b = !a.isEmpty ? this.ja : Rect.empty;
                let c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
                this.la = this.me() || (this.md == 1) || (1 * c / this.mh() > (b.width / a.width)) ? false : true;
            }
            else {
                this.la = false;
            }
        }
        l0(a, b) {
            let c = b.getTime() - a.getTime();
            let timeOffset_ = truncate(Math.round(intDivide(c, this.j8) / 2));
            return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
        }
        get_b5() {
            return true;
        }
        get isVertical() {
            return this.ch;
        }
        j$c(a, b) {
            return this.d2.apply(this, arguments);
        }
        j$b(a, b) {
            return this.dz.apply(this, arguments);
        }
        j$d(a, b, c, d, e) {
            this.gs.apply(this, arguments);
        }
        j$e(a, b, c, d) {
            this.gt.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.gu.apply(this, arguments);
        }
        get j$a() {
            return this.ca;
        }
        get i$a() {
            return this.b7;
        }
    }
    CategoryDateTimeXAxis.$t = /*@__PURE__*/ markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.mz = /*@__PURE__*/ DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, /*@__PURE__*/ new PropertyMetadata(2, 0, (a, b) => {
        (typeCast(CategoryDateTimeXAxis.$, a)).g6("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).hc(false);
    }));
    CategoryDateTimeXAxis.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'g6', ['DisplayType:md:mx', [TimeAxisDisplayType_$type, /*@__PURE__*/ enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:mn:my', [1, 0]]);
    return CategoryDateTimeXAxis;
})();
/**
 * @hidden
 */
export let CategoryDateTimeXAxisView = /*@__PURE__*/ (() => {
    class CategoryDateTimeXAxisView extends CategoryAxisBaseView {
        constructor(a) {
            super(a);
            this.bg = null;
            this.bg = a;
        }
        o(a) {
            let b = this.n(dateFromTicks(truncate(a)));
            return b;
        }
    }
    CategoryDateTimeXAxisView.$t = /*@__PURE__*/ markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
    return CategoryDateTimeXAxisView;
})();
//# sourceMappingURL=CategoryDateTimeXAxis_combined.js.map
