/*
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 { FastItemDateTimeColumn } from "igniteui-angular-core";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { EventArgs, runOn, delegateCombine, typeCast, Date_$type, markType } from "igniteui-angular-core";
import { IFastItemsSource_$type } from "igniteui-angular-core";
import { TimeAxisBase } from "./TimeAxisBase";
import { TimeXAxis } from "./TimeXAxis";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { truncate } from "igniteui-angular-core";
import { dateMaxValue, dateMinValue } from "igniteui-angular-core";
/**
 * @hidden
 */
export class OrdinalTimeXAxis extends CategoryXAxis {
    constructor() {
        super();
        this.lp = dateMaxValue();
        this.lo = dateMinValue();
        this.lt = dateMaxValue();
        this.ls = dateMinValue();
        this.ly = null;
        this.lm = null;
        this.lk = null;
        this.l5 = 0;
        this.lr = dateMinValue();
        this.lq = dateMaxValue();
        this.visibleRangeChanged = null;
        FastItemDateTimeColumn.o();
        this.lk = new TimeAxisLabelFormatCollection();
        let a = this.ll;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.l7));
        this.lb = 0;
    }
    dy(a, b, c) {
        return this.dw(a, new ScalerParams(0, b, c, this.b8, this.iw()));
    }
    dx(a, b, c) {
        return this.dw(a, b);
    }
    dw(a, b) {
        let c = this.la;
        let d = this.lb;
        let e = this.la - this.lb;
        let f = e >= 1 ? (a - d) / (c - d) : e == 0 ? 0.5 : NaN;
        if (this.b9) {
            f = 1 - f;
        }
        let g = b.d;
        let h = b.e;
        return g.left + g.width * (f - h.left) / h.width;
    }
    gm(a, b, c, d, e) {
        let f = this.kw(a);
        let g = f != null;
        for (let h = 0; h < b.count; h++) {
            for (let i = c; i < d; i++) {
                let j = g ? f[i] : a.item(i);
                j[h] = this.dw(j[h], e);
            }
        }
    }
    gn(a, b, c, d) {
        for (let e = b; e < c; e++) {
            a.item(e, this.dw(a.item(e), d));
        }
    }
    d1(a, b, c) {
        return this.dz(a, new ScalerParams(0, b, this.i1, this.b8, this.iw()));
    }
    getUnscaledValue3(a, b, c, d) {
        return this.dz(a, new ScalerParams(0, b, this.i1, this.b8, this.iw()));
    }
    dz(a, b) {
        let c = b.e;
        let d = b.d;
        let e = c.left + (a - d.left) * c.width / d.width;
        if (this.b9) {
            e = 1 - e;
        }
        return this.lb + e * (this.la - this.lb);
    }
    d0(a, b, c) {
        return this.dz(a, b);
    }
    go(a, b, c, d) {
        for (let e = b; e < c; e++) {
            a.item(e, this.dz(a.item(e), d));
        }
    }
    gu(a, b, c, d) {
        super.gu(a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                let e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.ln);
                    this.ln = null;
                }
                if (this.jf != null) {
                    this.ln = TimeAxisBase.kz(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.jf != null) {
                    this.jf.deregisterColumn(this.ln);
                    this.ln = TimeAxisBase.kz(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeColumn":
                this.cl();
                this.l5 = this.l4();
                break;
            case "MinimumValue":
            case "MaximumValue":
                this.cl();
                this.g5();
                break;
        }
    }
    get actualMinimumValue() {
        return this.lp;
    }
    set actualMinimumValue(a) {
        this.lp = a;
    }
    get actualMaximumValue() {
        return this.lo;
    }
    set actualMaximumValue(a) {
        this.lo = a;
    }
    get visibleMinimum() {
        return this.lt;
    }
    set visibleMinimum(a) {
        this.lt = a;
    }
    get visibleMaximum() {
        return this.ls;
    }
    set visibleMaximum(a) {
        this.ls = a;
    }
    l8() {
        if (this.ln == null || this.ln.count == 0 || this.ln.count < this.lb - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        let a = Math.max(0, Math.min(this.lb, this.ln.count - 1));
        let b = Math.max(0, Math.min(this.la, this.ln.count - 1));
        let c = +(this.actualMinimumValue) != +(this.ln.item(a)) || +(this.actualMaximumValue) != +(this.ln.item(b));
        if (c) {
            let d = this.actualMinimumValue;
            let e = this.actualMaximumValue;
            this.actualMinimumValue = this.ln.item(a);
            this.actualMaximumValue = this.ln.item(b);
            this.l9();
        }
    }
    l9() {
        if (this.ln == null || this.ln.count == 0 || this.bf == null) {
            let a = +(this.visibleMinimum) != +(this.actualMinimumValue) || +(this.visibleMaximum) != +(this.actualMaximumValue);
            this.visibleMinimum = this.actualMinimumValue;
            this.visibleMaximum = this.actualMaximumValue;
            if (a && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
            return;
        }
        let b = new ScalerParams(1, this.bf.m4, this.bf.m3, this.b8);
        let c = truncate(Math.ceil(this.dz(this.bf.m3.left, b)));
        let d = truncate(Math.ceil(this.dz(this.bf.m3.right, b)));
        let e = c >= 0 && c < this.ln.count ? this.ln.item(c) : this.actualMinimumValue;
        let f = d >= 0 && d < this.ln.count ? this.ln.item(d) : this.actualMaximumValue;
        let g = +(this.visibleMinimum) != +e || +(this.visibleMaximum) != +f;
        this.visibleMinimum = e;
        this.visibleMaximum = f;
        if (g && this.visibleRangeChanged != null) {
            this.visibleRangeChanged(this, EventArgs.empty);
        }
    }
    get dateTimeMemberPath() {
        return this.ly;
    }
    set dateTimeMemberPath(a) {
        let b = this.dateTimeMemberPath;
        if (a != b) {
            this.ly = a;
            this.g0("DateTimeMemberPath", b, this.dateTimeMemberPath);
        }
    }
    get ln() {
        return this.lm;
    }
    set ln(a) {
        if (this.lm != a) {
            let b = this.lm;
            this.lm = a;
            this.g0("DateTimeColumn", b, this.lm);
        }
    }
    hi(a, b) {
        super.hi(a, b);
        this.l9();
    }
    getWindowRectForSelection(a, b) {
        if (this.ln == null) {
            return Rect.empty;
        }
        let c = a > b;
        let d = c ? b : a;
        let e = c ? a : b;
        let f = -1;
        while (++f < this.ln.count && this.ln.item(f) < d) {
            ;
        }
        let g = this.ln.count;
        while (--g >= 0 && this.ln.item(g) > e) {
            ;
        }
        let h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.b8, this.bf.mu);
        let i = this.dw(f, h);
        let j = this.dw(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    }
    get ll() {
        return this.lk;
    }
    l7(a, b) {
        this.g6(false);
    }
    gw(a) {
        super.gw(a);
        this.dateTimeMemberPath = a;
    }
    e6(a) {
        if (this.ar != null) {
            return this.ar(a);
        }
        if (!(typeCast(Date_$type, a) !== null)) {
            return super.e6(a);
        }
        let b = TimeXAxis.mn(a, this.l6, this.ll, this.er);
        return b == null ? super.e6(a) : b;
    }
    fj(a) {
        let b = 0;
        if (this.categoryMode == 0) {
            b = truncate(Math.round(a));
        }
        else {
            b = truncate(Math.floor(a));
        }
        if (b < 0 || b > this.jz - 1) {
            return super.fj(a);
        }
        let c = this.ln.item(b);
        let d = this.e6(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    }
    get l6() {
        return +(this.visibleMaximum) - +(this.visibleMinimum);
    }
    ky() {
        return this.ln;
    }
    hh(a, b) {
        super.hh(a, b);
        this.l9();
    }
    k4(a, b) {
        let c = this.categoryMode == 0 ? 0 : 0.5;
        return super.k4(a + c, b);
    }
    k3(a, b, c, d) {
        return b;
    }
    l4() {
        if (this.ln == null || this.ln.count < 2) {
            return (0);
        }
        return TimeXAxis.mv((a) => this.ln.item(a), this.ln.count);
    }
    itemLabelFormat() {
        return TimeXAxis.ms(this.l5);
    }
    get minimumValue() {
        return this.lr;
    }
    set minimumValue(a) {
        let b = this.minimumValue;
        if (+a != +b) {
            this.lr = a;
            this.gu(this, "MinimumValue", b, this.minimumValue);
        }
    }
    get maximumValue() {
        return this.lq;
    }
    set maximumValue(a) {
        let b = this.maximumValue;
        if (+a != +b) {
            this.lq = a;
            this.gu(this, "MaximumValue", b, this.maximumValue);
        }
    }
    cn() {
        if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
            return super.cn();
        }
        if (this.cg && this.co) {
            this.a9 = this.a8();
        }
        if (this.jf == null || this.ln == null) {
            return false;
        }
        let a = this.lb;
        if (+(this.minimumValue) != +(dateMinValue())) {
            let b = -1;
            while (b++ <= this.ln.count) {
                if (this.ln.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        let c = this.categoryMode == 0 ? this.jf.count - 1 : this.jf.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            let d = this.jf.count;
            while (d-- > 0) {
                if (this.ln.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.lb || c != this.la) {
            let e = new AxisRangeChangedEventArgs(0, this.lb, a, this.la, c);
            this.lb = a;
            this.la = c;
            this.g1(e);
            this.l8();
            this.kb();
            return true;
        }
        return false;
    }
    kk(a) {
        super.kk(a);
        this.cm(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;
    }
}
OrdinalTimeXAxis.$t = markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
//# sourceMappingURL=OrdinalTimeXAxis.js.map