/*
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";
/**
 * @hidden
 */
export class CategoryDateTimeXAxis extends TimeAxisBase {
    constructor() {
        super();
        this.l9 = 0;
        this.ma = 0;
        this.ab = CategoryDateTimeXAxis.$;
        this.actualMinimumValue = (new Date());
        this.actualMaximumValue = (new Date());
    }
    get_b4() {
        return this.l4 == 0;
    }
    a1() {
        return new CategoryDateTimeXAxisView(this);
    }
    gs(a) {
        super.gs(a);
        this.l3 = a;
    }
    get mb() {
        return this.l9;
    }
    set mb(a) {
        if (this.mb != a) {
            let b = this.l9;
            this.l9 = a;
            this.g0("ActualInterval", b, this.mb);
        }
    }
    d7() {
        return this.mb;
    }
    get mf() {
        return typeGetValue(this.c(CategoryDateTimeXAxis.mq));
    }
    set mf(a) {
        this.h(CategoryDateTimeXAxis.mq, a);
    }
    get mc() {
        return this.ma;
    }
    set mc(a) {
        if (this.mc != a) {
            let b = this.ma;
            this.ma = a;
            this.g0("ActualMinorInterval", b, this.mc);
        }
    }
    cr(a, b, c) {
        let d = super.cr(a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    }
    dj() {
        return this.mb;
    }
    g7(a) {
        super.g7(a);
        let b = this.bf != null ? this.bf.mq : Rect.empty;
        let c = !b.isEmpty ? this.i1 : Rect.empty;
        let d = this.iw();
        let e = this.iv();
        let f = new ScalerParams(0, b, c, this.b8, d);
        if (this.kx == null && !this.k3() && !this.k4()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.l4 != 1 || this.kx != 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.ha(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.gq(this.a2.ay(), g, c, this.a2.e(), true);
            this.at.a8 = h;
            let k = this.a2.a1();
            let l = this.a2.f();
            let m = this.a2.az();
            let n = this.a2.a0();
            let o = this.a2.g();
            if (this.l4 == 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.k6 == null ? s : this.k6._inner[s];
                    let u = this.dw(this.kx.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.hf(m, u, c, l, false);
                    this.jm.add(u);
                    if (this.jf != null && s < this.jf.count) {
                        let v = this.jf.item(t);
                        let w = super.e6(v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.cv.add1(w);
                                this.cw.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                let x = this.dz(e.left, f);
                let y = this.dz(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.d9());
                let ac = this.k1 ? this.l8() : ab.g;
                this.mm(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.dw(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (let aj = ad; aj <= ae; aj++) {
                    let ak = this.dw(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.hg(k, ai, ak, c);
                            }
                            this.hf(m, ai, c, l, false);
                            this.jm.add(ai);
                            if (this.cj) {
                                let am = this.md();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        let an = ai;
                                        let ao = Math.abs(this.dw(this.actualMinimumValue.getTime() + am, f) - this.dw(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.hf(n, an, c, o, false);
                                            }
                                        }
                                        this.mn(am);
                                    }
                                }
                                else {
                                    for (let ap = 1; ap < ab.i; ++ap) {
                                        let aq = this.dw(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                        this.hf(n, aq, c, o, false);
                                    }
                                    if (ab.i > 0) {
                                        this.mn(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.e6(as);
                            if (at != null) {
                                this.cv.add1(at);
                                this.cw.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.ht();
                }
            }
            this.at.a1 = this.cv;
            this.at.a2 = this.cw;
            this.km();
        }
    }
    l8() {
        return this.mb;
    }
    md() {
        return this.mf;
    }
    mm(a) {
        this.mb = a;
    }
    mn(a) {
        this.mc = a;
    }
    l6() {
        return this.me != 0;
    }
    l5() {
        return this.mb == 0;
    }
    l7(a) {
        return this.kx == null ? dateMinValue() : this.kx.item(a);
    }
    ml(a, b) {
        if (a > b || this.jf == null || this.jf.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.m4 = new Rect(0, c, this.bf.m4.y, d - c, this.bf.m4.height);
    }
    gu(a, b, c, d) {
        super.gu(a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.cg = true;
                this.at.ak = this.l4 == 1;
                this.g6(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.cg = true;
                this.g6(false);
                break;
        }
    }
    lt() {
        super.lt();
        if (this.l6()) {
            this.mb = this.me;
            let a = this.bf != null ? this.bf.mq : Rect.empty;
            let b = !a.isEmpty ? this.i1 : Rect.empty;
            let c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.k1 = this.l5() || (this.l4 == 1) || (1 * c / this.l8() > (b.width / a.width)) ? false : true;
        }
        else {
            this.k1 = false;
        }
    }
    lr(a, b) {
        let c = b.getTime() - a.getTime();
        let timeOffset_ = truncate(Math.round(intDivide(c, this.jy) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    }
    get_b3() {
        return true;
    }
    get isVertical() {
        return this.cf;
    }
    j$c(a, b) {
        return this.dz.apply(this, arguments);
    }
    j$b(a, b) {
        return this.dw.apply(this, arguments);
    }
    j$d(a, b, c, d, e) {
        this.gm.apply(this, arguments);
    }
    j$e(a, b, c, d) {
        this.gn.apply(this, arguments);
    }
    j$f(a, b, c, d) {
        this.go.apply(this, arguments);
    }
    get j$a() {
        return this.b8;
    }
    get i$a() {
        return this.b5;
    }
}
CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
CategoryDateTimeXAxis.mq = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, (a, b) => {
    (typeCast(CategoryDateTimeXAxis.$, a)).g0("MinorInterval", b.oldValue, b.newValue);
    (typeCast(CategoryDateTimeXAxis.$, a)).g6(false);
}));
CategoryDateTimeXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'g0', ['DisplayType:l4:mo', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:me:mp', [1, 0]]);
/**
 * @hidden
 */
export 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 = markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
//# sourceMappingURL=CategoryDateTimeXAxis_combined.js.map