/*
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/ES2015/DependencyProperty";
import { Type, Base, enumGetBox, Number_$type, typeGetValue, typeCast, markType } from "igniteui-react-core/ES2015/type";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { ScalerParams } from "./ScalerParams";
import { NumericYAxis } from "./NumericYAxis";
import { LinearNumericSnapper } from "./LinearNumericSnapper";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-react-core/ES2015/number";
import { dateMinValue, dateFromTicks } from "igniteui-react-core/ES2015/date";
import { timeSpanFromMilliseconds } from "igniteui-react-core/ES2015/timespan";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
export class CategoryDateTimeXAxis extends TimeAxisBase {
    constructor() {
        super();
        this.ly = 0;
        this.lz = 0;
        this.ab = CategoryDateTimeXAxis.$;
        this.actualMinimumValue = (new Date());
        this.actualMaximumValue = (new Date());
    }
    get_b4() {
        return this.lt == 0;
    }
    get b4() {
        return this.get_b4();
    }
    a1() {
        return new CategoryDateTimeXAxisView(this);
    }
    gl(a) {
        super.gl(a);
        this.ls = a;
    }
    get l0() {
        return this.ly;
    }
    set l0(a) {
        if (this.l0 != a) {
            let b = this.ly;
            this.ly = a;
            this.gt("ActualInterval", b, this.l0);
        }
    }
    d4() {
        return this.l0;
    }
    get l4() {
        return typeGetValue(this.c(CategoryDateTimeXAxis.mf));
    }
    set l4(a) {
        this.h(CategoryDateTimeXAxis.mf, a);
    }
    get l1() {
        return this.lz;
    }
    set l1(a) {
        if (this.l1 != a) {
            let b = this.lz;
            this.lz = a;
            this.gt("ActualMinorInterval", b, this.l1);
        }
    }
    cq(a, b, c) {
        let d = super.cq(a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    }
    dg() {
        return this.l0;
    }
    g0(a) {
        super.g0(a);
        let b = this.bf != null ? this.bf.mk : Rect.empty;
        let c = !b.isEmpty ? this.it : Rect.empty;
        let d = this.io();
        let e = this.im();
        let f = new ScalerParams(0, b, c, this.b8, d);
        if (this.kq == null && !this.kw() && !this.kx()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.lt != 1 || this.kq != null)) {
            let g = c.bottom;
            let h = g - c.top;
            if (this.ag != null) {
                let i = typeCast(NumericYAxis.$, this.ag);
                if (i != null) {
                    let j = this.g3(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.gj(this.a2.ax(), g, c, this.a2.e(), true);
            this.at.a8 = h;
            let k = this.a2.a0();
            let l = this.a2.f();
            let m = this.a2.ay();
            let n = this.a2.az();
            let o = this.a2.g();
            if (this.lt == 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.kz == null ? s : this.kz._inner[s];
                    let u = this.dt(this.kq.item(t).getTime(), f);
                    if (u == r) {
                        continue;
                    }
                    r = u;
                    if (this.categoryMode == 2) {
                        u += this.b8 ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                    }
                    if (u < e.left || u > e.right) {
                        continue;
                    }
                    this.g8(m, u, c, l, false);
                    this.je.add(u);
                    if (this.i7 != null && s < this.i7.count) {
                        let v = this.i7.item(t);
                        let w = super.e0(v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.cs.add1(w);
                                this.ct.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                let x = this.dw(e.left, f);
                let y = this.dw(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.d6());
                let ac = this.ku ? this.lx() : ab.g;
                this.mb(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.b8 ? -af : af;
                }
                let ag = truncate(Math.ceil(e.right));
                let ah = truncate(Math.floor(e.left));
                let ai = this.dt(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (let aj = ad; aj <= ae; aj++) {
                    let ak = this.dt(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.g9(k, ai, ak, c);
                            }
                            this.g8(m, ai, c, l, false);
                            this.je.add(ai);
                            if (this.ci) {
                                let am = this.l2();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        let an = ai;
                                        let ao = Math.abs(this.dt(this.actualMinimumValue.getTime() + am, f) - this.dt(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.g8(n, an, c, o, false);
                                            }
                                        }
                                        this.mc(am);
                                    }
                                }
                                else {
                                    for (let ap = 1; ap < ab.i; ++ap) {
                                        let aq = this.dt(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                        this.g8(n, aq, c, o, false);
                                    }
                                    if (ab.i > 0) {
                                        this.mc(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.e0(as);
                            if (at != null) {
                                this.cs.add1(at);
                                this.ct.add(new LabelPosition(ai));
                            }
                        }
                    }
                    ai = ak;
                }
            }
            if ((this.aw == null || this.aw.visibility == 0) && this.ag != null) {
                if (this.aw != null && (this.aw.location == 4 || this.aw.location == 5)) {
                    this.bf.hp();
                }
            }
            this.at.a1 = this.cs;
            this.at.a2 = this.ct;
            this.ke();
        }
    }
    lx() {
        return this.l0;
    }
    l2() {
        return this.l4;
    }
    mb(a) {
        this.l0 = a;
    }
    mc(a) {
        this.l1 = a;
    }
    lv() {
        return this.l3 != 0;
    }
    lu() {
        return this.l0 == 0;
    }
    lw(a) {
        return this.kq == null ? dateMinValue() : this.kq.item(a);
    }
    ma(a, b) {
        if (a > b || this.i7 == null || this.i7.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.bf.my = new Rect(0, c, this.bf.my.y, d - c, this.bf.my.height);
    }
    gn(a, b, c, d) {
        super.gn(a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.cf = true;
                this.at.ak = this.lt == 1;
                this.gz(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.cf = true;
                this.gz(false);
                break;
        }
    }
    li() {
        super.li();
        if (this.lv()) {
            this.l0 = this.l3;
            let a = this.bf != null ? this.bf.mk : Rect.empty;
            let b = !a.isEmpty ? this.it : Rect.empty;
            let c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.ku = this.lu() || (this.lt == 1) || (1 * c / this.lx() > (b.width / a.width)) ? false : true;
        }
        else {
            this.ku = false;
        }
    }
    lg(a, b) {
        let c = b.getTime() - a.getTime();
        let timeOffset_ = truncate(Math.round(intDivide(c, this.jq) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    }
    get_b3() {
        return true;
    }
    get b3() {
        return this.get_b3();
    }
    get isVertical() {
        return this.ce;
    }
    j$c(a, b) {
        return this.dw.apply(this, arguments);
    }
    j$b(a, b) {
        return this.dt.apply(this, arguments);
    }
    j$d(a, b, c, d, e) {
        this.gf.apply(this, arguments);
    }
    j$e(a, b, c, d) {
        this.gg.apply(this, arguments);
    }
    j$f(a, b, c, d) {
        this.gh.apply(this, arguments);
    }
    get j$a() {
        return this.b8;
    }
    get i$a() {
        return this.b5;
    }
}
CategoryDateTimeXAxis.mf = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, (a, b) => {
    (typeCast(CategoryDateTimeXAxis.$, a)).gt("MinorInterval", b.oldValue, b.newValue);
    (typeCast(CategoryDateTimeXAxis.$, a)).gz(false);
}));
CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
Type.dep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'gt', ['DisplayType:lt:md', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:l3:me', [1, 0]]);
export class CategoryDateTimeXAxisView extends CategoryAxisBaseView {
    constructor(a) {
        super(a);
        this.bf = null;
        this.bf = a;
    }
    n(a) {
        let b = this.m(dateFromTicks(truncate(a)));
        return b;
    }
}
CategoryDateTimeXAxisView.$t = markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
/*<BeginStatics Name="Infragistics.Controls.Charts.CategoryDateTimeXAxis" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.CategoryDateTimeXAxis" />*/
