/*
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 { DependencyProperty } from "igniteui-react-core";
import { TimeAxisDisplayType_$type } from "./TimeAxisDisplayType";
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";
import { AxisDefaults } from "./AxisDefaults";
/**
 * @hidden
 */
export let CategoryDateTimeXAxis = /*@__PURE__*/ (() => {
    class CategoryDateTimeXAxis extends TimeAxisBase {
        constructor() {
            super();
            this.nw = 0;
            this.nx = 0;
            this.ab = CategoryDateTimeXAxis.$;
            this.actualMinimumValue = (new Date());
            this.actualMaximumValue = (new Date());
        }
        get_cd() {
            return this.nq == 0;
        }
        a4() {
            return new CategoryDateTimeXAxisView(this);
        }
        ht(a) {
            super.ht(a);
            this.np = a;
        }
        get ny() {
            return this.nw;
        }
        set ny(a) {
            if (this.ny != a) {
                let b = this.nw;
                this.nw = a;
                this.h3("ActualInterval", b, this.ny);
            }
        }
        ew() {
            return this.ny;
        }
        get n2() {
            return typeGetValue(this.c(CategoryDateTimeXAxis.oe));
        }
        set n2(a) {
            this.h(CategoryDateTimeXAxis.oe, a);
        }
        get nz() {
            return this.nx;
        }
        set nz(a) {
            if (this.nz != a) {
                let b = this.nx;
                this.nx = a;
                this.h3("ActualMinorInterval", b, this.nz);
            }
        }
        c8(a, b, c) {
            let d = super.c8(a, b, c);
            if (!d) {
                return false;
            }
            return +(this.actualMinimumValue) != +(this.actualMaximumValue);
        }
        d5() {
            return this.ny;
        }
        ia(a) {
            super.ia(a);
            let b = this.bi != null ? this.bi.vl : Rect.empty;
            let c = !b.isEmpty ? this.ke : Rect.empty;
            let d = this.j9();
            let e = this.j8();
            let f = new ScalerParams(0, b, c, this.ch, d);
            if ((this.mj == null || this.mj.count < 1) && !this.mp() && !this.mq()) {
                return;
            }
            if (!b.isEmpty && !c.isEmpty && (this.nq != 1 || this.mj != null)) {
                let g = c.bottom;
                let h = g - c.top;
                if (this.aj != null) {
                    let i = typeCast(NumericYAxis.$, this.aj);
                    if (i != null) {
                        let j = this.ig(g, h, b, c, d, c.top, c.bottom);
                        g = j.p0;
                        h = j.p1;
                    }
                }
                if (isNaN_(g)) {
                    g = 0;
                }
                this.hr(this.a5.a4(), g, c, this.a5.e(), true);
                this.aw.bg = h;
                let k = this.a5.a7();
                let l = this.a5.f();
                let m = this.a5.a5();
                let n = this.a5.a6();
                let o = this.a5.g();
                if (this.nq == 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.ms == null ? s : this.ms._inner[s];
                        let u = this.ek(this.mj.item(t).getTime(), f);
                        if (u == r) {
                            continue;
                        }
                        r = u;
                        if (this.categoryMode == 2) {
                            u += this.ch ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                        }
                        if (u < e.left || u > e.right) {
                            continue;
                        }
                        this.io(m, u, c, l, false);
                        this.kz.add(u);
                        if (this.ks != null && s < this.ks.count) {
                            let v = this.ks.item(t);
                            let w = super.f0(v);
                            if (!isNaN_(u) && !isInfinity(u) && w != null) {
                                if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                                }
                                else {
                                    this.dc.add1(w);
                                    this.dd.add(new LabelPosition(u));
                                }
                            }
                        }
                    }
                }
                else {
                    let x = this.en(e.left, f);
                    let y = this.en(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.ez());
                    let ac = this.mn ? this.nv() : ab.g;
                    this.oa(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.ch ? -af : af;
                    }
                    let ag = truncate(Math.ceil(e.right));
                    let ah = truncate(Math.floor(e.left));
                    let ai = this.ek(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                    for (let aj = ad; aj <= ae; aj++) {
                        let ak = this.ek(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.ip(k, ai, ak, c);
                                }
                                this.io(m, ai, c, l, false);
                                this.kz.add(ai);
                                if (this.cy) {
                                    let am = this.n0();
                                    if (am > 0 && am < ac) {
                                        if (ac / am < 20) {
                                            let an = ai;
                                            let ao = Math.abs(this.ek(this.actualMinimumValue.getTime() + am, f) - this.ek(this.actualMinimumValue.getTime(), f));
                                            while (an + ao < ak) {
                                                if (Math.abs(an + ao - ak) < 0.0001) {
                                                    break;
                                                }
                                                an += ao;
                                                if (an > 0) {
                                                    this.io(n, an, c, o, false);
                                                }
                                            }
                                            this.ob(am);
                                        }
                                    }
                                    else {
                                        for (let ap = 1; ap < ab.i; ++ap) {
                                            let aq = this.ek(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                            this.io(n, aq, c, o, false);
                                        }
                                        if (ab.i > 0) {
                                            this.ob(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.f0(as);
                                if (at != null) {
                                    this.dc.add1(at);
                                    this.dd.add(new LabelPosition(ai));
                                }
                            }
                        }
                        ai = ak;
                    }
                }
                if ((this.az == null || this.az.visibility == 0) && this.aj != null) {
                    if (this.az != null && (this.az.location == 4 || this.az.location == 5)) {
                        this.bi.nr();
                    }
                }
                this.aw.a9 = this.dc;
                this.aw.ba = this.dd;
                this.l6();
            }
        }
        nv() {
            return this.ny;
        }
        n0() {
            return this.n2;
        }
        oa(a) {
            this.ny = a;
        }
        ob(a) {
            this.nz = a;
        }
        ns() {
            return this.n1 != 0;
        }
        nr() {
            return this.ny == 0;
        }
        nu(a) {
            return this.mj == null ? dateMinValue() : this.mj.item(a);
        }
        n9(a, b) {
            if (a > b || this.ks == null || this.ks.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.bi.v1 = new Rect(0, c, this.bi.v1.y, d - c, this.bi.v1.height);
        }
        hx(a, b, c, d) {
            super.hx(a, b, c, d);
            switch (b) {
                case CategoryDateTimeXAxis.$$p[0]:
                    this.cq = true;
                    this.aw.al = this.nq == 1 || this.nt;
                    this.h9(false);
                    break;
                case CategoryDateTimeXAxis.$$p[1]:
                    this.cq = true;
                    this.h9(false);
                    break;
                case CategoryDateTimeXAxis.$$p[2]:
                    this.aw.al = this.nq == 1 || this.nt;
                    break;
            }
        }
        nf() {
            super.nf();
            if (this.ns()) {
                this.ny = this.n1;
                let a = this.bi != null ? this.bi.vl : Rect.empty;
                let b = !a.isEmpty ? this.ke : Rect.empty;
                let c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
                this.mn = this.nr() || (this.nq == 1) || (1 * c / this.nv() > (b.width / a.width)) ? false : true;
            }
            else {
                this.mn = false;
            }
        }
        nd(a, b) {
            let c = b.getTime() - a.getTime();
            let timeOffset_ = truncate(Math.round(intDivide(c, this.lg) / 2));
            return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
        }
        get_cc() {
            return true;
        }
        get isVertical() {
            return this.cp;
        }
        j$d(a, b) {
            return this.en.apply(this, arguments);
        }
        j$c(a, b) {
            return this.ek.apply(this, arguments);
        }
        j$e(a, b, c, d, e) {
            this.hn.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.ho.apply(this, arguments);
        }
        j$g(a, b, c, d) {
            this.hp.apply(this, arguments);
        }
        get j$b() {
            return this.ch;
        }
        j$a() {
            return this.ag.apply(this, arguments);
        }
        get i$a() {
            return this.ce;
        }
    }
    CategoryDateTimeXAxis.$t = /*@__PURE__*/ markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.oe = /*@__PURE__*/ DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, /*@__PURE__*/ new PropertyMetadata(2, 0, (a, b) => {
        (typeCast(CategoryDateTimeXAxis.$, a)).h3("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).h9(false);
    }));
    CategoryDateTimeXAxis.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'h3', ['DisplayType:nq:oc', [TimeAxisDisplayType_$type, /*@__PURE__*/ enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:n1:od', [1, 0], 'UnevenlySpacedLabels:nt:of', [0, false]]);
    return CategoryDateTimeXAxis;
})();
/**
 * @hidden
 */
export let CategoryDateTimeXAxisView = /*@__PURE__*/ (() => {
    class CategoryDateTimeXAxisView extends CategoryAxisBaseView {
        constructor(a) {
            super(a);
            this.bm = null;
            this.bm = a;
        }
        al() {
            super.al();
            this.a.fi = AxisDefaults.f;
        }
        s(a) {
            let b = this.q(dateFromTicks(truncate(a)));
            return b;
        }
    }
    CategoryDateTimeXAxisView.$t = /*@__PURE__*/ markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
    return CategoryDateTimeXAxisView;
})();
