/*
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-angular-core";
import { Base, enumGetBox, Number_$type, typeGetValue, typeCast, markType, markDep } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { NumericYAxis } from "./NumericYAxis";
import { LinearNumericSnapper } from "./LinearNumericSnapper";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-angular-core";
import { dateMinValue, dateFromTicks } from "igniteui-angular-core";
import { timeSpanFromMilliseconds } from "igniteui-angular-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
import { AxisDefaults } from "./AxisDefaults";
/**
 * @hidden
 */
export let CategoryDateTimeXAxis = /*@__PURE__*/ (() => {
    class CategoryDateTimeXAxis extends TimeAxisBase {
        constructor() {
            super();
            this.ns = 0;
            this.nt = 0;
            this.ab = CategoryDateTimeXAxis.$;
            this.actualMinimumValue = (new Date());
            this.actualMaximumValue = (new Date());
        }
        get_cc() {
            return this.nn == 0;
        }
        a3() {
            return new CategoryDateTimeXAxisView(this);
        }
        hr(a) {
            super.hr(a);
            this.nm = a;
        }
        get nu() {
            return this.ns;
        }
        set nu(a) {
            if (this.nu != a) {
                let b = this.ns;
                this.ns = a;
                this.h1("ActualInterval", b, this.nu);
            }
        }
        eu() {
            return this.nu;
        }
        get ny() {
            return typeGetValue(this.c(CategoryDateTimeXAxis.n9));
        }
        set ny(a) {
            this.h(CategoryDateTimeXAxis.n9, a);
        }
        get nv() {
            return this.nt;
        }
        set nv(a) {
            if (this.nv != a) {
                let b = this.nt;
                this.nt = a;
                this.h1("ActualMinorInterval", b, this.nv);
            }
        }
        c7(a, b, c) {
            let d = super.c7(a, b, c);
            if (!d) {
                return false;
            }
            return +(this.actualMinimumValue) != +(this.actualMaximumValue);
        }
        d3() {
            return this.nu;
        }
        h8(a) {
            super.h8(a);
            let b = this.bh != null ? this.bh.ta : Rect.empty;
            let c = !b.isEmpty ? this.kc : Rect.empty;
            let d = this.j7();
            let e = this.j6();
            let f = new ScalerParams(0, b, c, this.cg, d);
            if ((this.mg == null || this.mg.count < 1) && !this.mm() && !this.mn()) {
                return;
            }
            if (!b.isEmpty && !c.isEmpty && (this.nn != 1 || this.mg != 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.id(g, h, b, c, d, c.top, c.bottom);
                        g = j.p0;
                        h = j.p1;
                    }
                }
                if (isNaN_(g)) {
                    g = 0;
                }
                this.hp(this.a4.a1(), g, c, this.a4.e(), true);
                this.av.bg = h;
                let k = this.a4.a4();
                let l = this.a4.f();
                let m = this.a4.a2();
                let n = this.a4.a3();
                let o = this.a4.g();
                if (this.nn == 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.mp == null ? s : this.mp._inner[s];
                        let u = this.ei(this.mg.item(t).getTime(), f);
                        if (u == r) {
                            continue;
                        }
                        r = u;
                        if (this.categoryMode == 2) {
                            u += this.cg ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                        }
                        if (u < e.left || u > e.right) {
                            continue;
                        }
                        this.il(m, u, c, l, false);
                        this.kx.add(u);
                        if (this.kq != null && s < this.kq.count) {
                            let v = this.kq.item(t);
                            let w = super.fy(v);
                            if (!isNaN_(u) && !isInfinity(u) && w != null) {
                                if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                                }
                                else {
                                    this.db.add1(w);
                                    this.dc.add(new LabelPosition(u));
                                }
                            }
                        }
                    }
                }
                else {
                    let x = this.el(e.left, f);
                    let y = this.el(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.ex());
                    let ac = this.mk ? this.nr() : ab.g;
                    this.n5(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.cg ? -af : af;
                    }
                    let ag = truncate(Math.ceil(e.right));
                    let ah = truncate(Math.floor(e.left));
                    let ai = this.ei(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                    for (let aj = ad; aj <= ae; aj++) {
                        let ak = this.ei(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.im(k, ai, ak, c);
                                }
                                this.il(m, ai, c, l, false);
                                this.kx.add(ai);
                                if (this.cx) {
                                    let am = this.nw();
                                    if (am > 0 && am < ac) {
                                        if (ac / am < 20) {
                                            let an = ai;
                                            let ao = Math.abs(this.ei(this.actualMinimumValue.getTime() + am, f) - this.ei(this.actualMinimumValue.getTime(), f));
                                            while (an + ao < ak) {
                                                if (Math.abs(an + ao - ak) < 0.0001) {
                                                    break;
                                                }
                                                an += ao;
                                                if (an > 0) {
                                                    this.il(n, an, c, o, false);
                                                }
                                            }
                                            this.n6(am);
                                        }
                                    }
                                    else {
                                        for (let ap = 1; ap < ab.i; ++ap) {
                                            let aq = this.ei(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                            this.il(n, aq, c, o, false);
                                        }
                                        if (ab.i > 0) {
                                            this.n6(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.fy(as);
                                if (at != null) {
                                    this.db.add1(at);
                                    this.dc.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.l7();
                    }
                }
                this.av.a9 = this.db;
                this.av.ba = this.dc;
                this.l3();
            }
        }
        nr() {
            return this.nu;
        }
        nw() {
            return this.ny;
        }
        n5(a) {
            this.nu = a;
        }
        n6(a) {
            this.nv = a;
        }
        np() {
            return this.nx != 0;
        }
        no() {
            return this.nu == 0;
        }
        nq(a) {
            return this.mg == null ? dateMinValue() : this.mg.item(a);
        }
        n4(a, b) {
            if (a > b || this.kq == null || this.kq.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.tq = new Rect(0, c, this.bh.tq.y, d - c, this.bh.tq.height);
        }
        hv(a, b, c, d) {
            super.hv(a, b, c, d);
            switch (b) {
                case CategoryDateTimeXAxis.$$p[0]:
                    this.cp = true;
                    this.av.al = this.nn == 1;
                    this.h7(false);
                    break;
                case CategoryDateTimeXAxis.$$p[1]:
                    this.cp = true;
                    this.h7(false);
                    break;
            }
        }
        nc() {
            super.nc();
            if (this.np()) {
                this.nu = this.nx;
                let a = this.bh != null ? this.bh.ta : Rect.empty;
                let b = !a.isEmpty ? this.kc : Rect.empty;
                let c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
                this.mk = this.no() || (this.nn == 1) || (1 * c / this.nr() > (b.width / a.width)) ? false : true;
            }
            else {
                this.mk = false;
            }
        }
        na(a, b) {
            let c = b.getTime() - a.getTime();
            let timeOffset_ = truncate(Math.round(intDivide(c, this.le) / 2));
            return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
        }
        get_cb() {
            return true;
        }
        get isVertical() {
            return this.co;
        }
        j$c(a, b) {
            return this.el.apply(this, arguments);
        }
        j$b(a, b) {
            return this.ei.apply(this, arguments);
        }
        j$d(a, b, c, d, e) {
            this.hl.apply(this, arguments);
        }
        j$e(a, b, c, d) {
            this.hm.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.hn.apply(this, arguments);
        }
        get j$a() {
            return this.cg;
        }
        get i$a() {
            return this.cd;
        }
    }
    CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.n9 = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, (a, b) => {
        (typeCast(CategoryDateTimeXAxis.$, a)).h1("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).h7(false);
    }));
    CategoryDateTimeXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'h1', ['DisplayType:nn:n7', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:nx:n8', [1, 0]]);
    return CategoryDateTimeXAxis;
})();
/**
 * @hidden
 */
export let CategoryDateTimeXAxisView = /*@__PURE__*/ (() => {
    class CategoryDateTimeXAxisView extends CategoryAxisBaseView {
        constructor(a) {
            super(a);
            this.bj = null;
            this.bj = a;
        }
        aj() {
            super.aj();
            this.a.fg = AxisDefaults.f;
        }
        r(a) {
            let b = this.p(dateFromTicks(truncate(a)));
            return b;
        }
    }
    CategoryDateTimeXAxisView.$t = markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
    return CategoryDateTimeXAxisView;
})();
