/*
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 * as tslib_1 from "tslib";
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
 */
var OrdinalTimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _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();
        var a = _this.ll;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.l7));
        _this.lb = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.dy = function (a, b, c) {
        return this.dw(a, new ScalerParams(0, b, c, this.b8, this.iw()));
    };
    OrdinalTimeXAxis.prototype.dx = function (a, b, c) {
        return this.dw(a, b);
    };
    OrdinalTimeXAxis.prototype.dw = function (a, b) {
        var c = this.la;
        var d = this.lb;
        var e = this.la - this.lb;
        var f = e >= 1 ? (a - d) / (c - d) : e == 0 ? 0.5 : NaN;
        if (this.b9) {
            f = 1 - f;
        }
        var g = b.d;
        var h = b.e;
        return g.left + g.width * (f - h.left) / h.width;
    };
    OrdinalTimeXAxis.prototype.gm = function (a, b, c, d, e) {
        var f = this.kw(a);
        var g = f != null;
        for (var h = 0; h < b.count; h++) {
            for (var i = c; i < d; i++) {
                var j = g ? f[i] : a.item(i);
                j[h] = this.dw(j[h], e);
            }
        }
    };
    OrdinalTimeXAxis.prototype.gn = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dw(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.d1 = function (a, b, c) {
        return this.dz(a, new ScalerParams(0, b, this.i1, this.b8, this.iw()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.dz(a, new ScalerParams(0, b, this.i1, this.b8, this.iw()));
    };
    OrdinalTimeXAxis.prototype.dz = function (a, b) {
        var c = b.e;
        var d = b.d;
        var e = c.left + (a - d.left) * c.width / d.width;
        if (this.b9) {
            e = 1 - e;
        }
        return this.lb + e * (this.la - this.lb);
    };
    OrdinalTimeXAxis.prototype.d0 = function (a, b, c) {
        return this.dz(a, b);
    };
    OrdinalTimeXAxis.prototype.go = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dz(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.gu = function (a, b, c, d) {
        _super.prototype.gu.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var 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;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.lp;
        },
        set: function (a) {
            this.lp = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.lo;
        },
        set: function (a) {
            this.lo = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.lt;
        },
        set: function (a) {
            this.lt = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.ls;
        },
        set: function (a) {
            this.ls = a;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.l8 = function () {
        if (this.ln == null || this.ln.count == 0 || this.ln.count < this.lb - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.lb, this.ln.count - 1));
        var b = Math.max(0, Math.min(this.la, this.ln.count - 1));
        var c = +(this.actualMinimumValue) != +(this.ln.item(a)) || +(this.actualMaximumValue) != +(this.ln.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.ln.item(a);
            this.actualMaximumValue = this.ln.item(b);
            this.l9();
        }
    };
    OrdinalTimeXAxis.prototype.l9 = function () {
        if (this.ln == null || this.ln.count == 0 || this.bf == null) {
            var 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;
        }
        var b = new ScalerParams(1, this.bf.m4, this.bf.m3, this.b8);
        var c = truncate(Math.ceil(this.dz(this.bf.m3.left, b)));
        var d = truncate(Math.ceil(this.dz(this.bf.m3.right, b)));
        var e = c >= 0 && c < this.ln.count ? this.ln.item(c) : this.actualMinimumValue;
        var f = d >= 0 && d < this.ln.count ? this.ln.item(d) : this.actualMaximumValue;
        var g = +(this.visibleMinimum) != +e || +(this.visibleMaximum) != +f;
        this.visibleMinimum = e;
        this.visibleMaximum = f;
        if (g && this.visibleRangeChanged != null) {
            this.visibleRangeChanged(this, EventArgs.empty);
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "dateTimeMemberPath", {
        get: function () {
            return this.ly;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.ly = a;
                this.g0("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "ln", {
        get: function () {
            return this.lm;
        },
        set: function (a) {
            if (this.lm != a) {
                var b = this.lm;
                this.lm = a;
                this.g0("DateTimeColumn", b, this.lm);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.hi = function (a, b) {
        _super.prototype.hi.call(this, a, b);
        this.l9();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.ln == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.ln.count && this.ln.item(f) < d) {
            ;
        }
        var g = this.ln.count;
        while (--g >= 0 && this.ln.item(g) > e) {
            ;
        }
        var h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.b8, this.bf.mu);
        var i = this.dw(f, h);
        var j = this.dw(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "ll", {
        get: function () {
            return this.lk;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.l7 = function (a, b) {
        this.g6(false);
    };
    OrdinalTimeXAxis.prototype.gw = function (a) {
        _super.prototype.gw.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.e6 = function (a) {
        if (this.ar != null) {
            return this.ar(a);
        }
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e6.call(this, a);
        }
        var b = TimeXAxis.mn(a, this.l6, this.ll, this.er);
        return b == null ? _super.prototype.e6.call(this, a) : b;
    };
    OrdinalTimeXAxis.prototype.fj = function (a) {
        var 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.prototype.fj.call(this, a);
        }
        var c = this.ln.item(b);
        var d = this.e6(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "l6", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.ky = function () {
        return this.ln;
    };
    OrdinalTimeXAxis.prototype.hh = function (a, b) {
        _super.prototype.hh.call(this, a, b);
        this.l9();
    };
    OrdinalTimeXAxis.prototype.k4 = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.k4.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.k3 = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.l4 = function () {
        var _this = this;
        if (this.ln == null || this.ln.count < 2) {
            return (0);
        }
        return TimeXAxis.mv(function (a) { return _this.ln.item(a); }, this.ln.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.ms(this.l5);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.lr;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.lr = a;
                this.gu(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.lq;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.lq = a;
                this.gu(this, "MaximumValue", b, this.maximumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.cn = function () {
        if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
            return _super.prototype.cn.call(this);
        }
        if (this.cg && this.co) {
            this.a9 = this.a8();
        }
        if (this.jf == null || this.ln == null) {
            return false;
        }
        var a = this.lb;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.ln.count) {
                if (this.ln.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.jf.count - 1 : this.jf.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.jf.count;
            while (d-- > 0) {
                if (this.ln.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.lb || c != this.la) {
            var 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;
    };
    OrdinalTimeXAxis.prototype.kk = function (a) {
        _super.prototype.kk.call(this, a);
        this.cm(true);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.cf;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.j$c = function (a, b) {
        return this.dz.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$b = function (a, b) {
        return this.dw.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gm.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gn.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.go.apply(this, arguments);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "j$a", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.$t = markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
    return OrdinalTimeXAxis;
}(CategoryXAxis));
export { OrdinalTimeXAxis };
//# sourceMappingURL=OrdinalTimeXAxis.js.map