/*
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/ES5/FastItemDateTimeColumn";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { Rect } from "igniteui-angular-core/ES5/Rect";
import { ScalerParams } from "./ScalerParams";
import { EventArgs, runOn, delegateCombine, typeCast, Date_$type, markType } from "igniteui-angular-core/ES5/type";
import { IFastItemsSource_$type } from "igniteui-angular-core/ES5/IFastItemsSource";
import { TimeAxisBase } from "./TimeAxisBase";
import { TimeXAxis } from "./TimeXAxis";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { truncate } from "igniteui-angular-core/ES5/number";
import { dateMaxValue, dateMinValue } from "igniteui-angular-core/ES5/date";
/**
 * @hidden
 */
var OrdinalTimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.lo = dateMaxValue();
        _this.ln = dateMinValue();
        _this.ls = dateMaxValue();
        _this.lr = dateMinValue();
        _this.lx = null;
        _this.ll = null;
        _this.lj = null;
        _this.l4 = 0;
        _this.lq = dateMinValue();
        _this.lp = dateMaxValue();
        _this.visibleRangeChanged = null;
        FastItemDateTimeColumn.o();
        _this.lj = new TimeAxisLabelFormatCollection();
        var a = _this.lk;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.l6));
        _this.la = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.dx = function (a, b, c) {
        return this.dv(a, new ScalerParams(0, b, c, this.b8, this.iv()));
    };
    OrdinalTimeXAxis.prototype.dw = function (a, b, c) {
        return this.dv(a, b);
    };
    OrdinalTimeXAxis.prototype.dv = function (a, b) {
        var c = this.k9;
        var d = this.la;
        var e = this.k9 - this.la;
        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.gl = function (a, b, c, d, e) {
        var f = this.kv(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.dv(j[h], e);
            }
        }
    };
    OrdinalTimeXAxis.prototype.gm = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dv(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.d0 = function (a, b, c) {
        return this.dy(a, new ScalerParams(0, b, this.i0, this.b8, this.iv()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.dy(a, new ScalerParams(0, b, this.i0, this.b8, this.iv()));
    };
    OrdinalTimeXAxis.prototype.dy = 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.la + e * (this.k9 - this.la);
    };
    OrdinalTimeXAxis.prototype.dz = function (a, b, c) {
        return this.dy(a, b);
    };
    OrdinalTimeXAxis.prototype.gn = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dy(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.gt = function (a, b, c, d) {
        _super.prototype.gt.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.lm);
                    this.lm = null;
                }
                if (this.je != null) {
                    this.lm = TimeAxisBase.ky(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.je != null) {
                    this.je.deregisterColumn(this.lm);
                    this.lm = TimeAxisBase.ky(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeColumn":
                this.ck();
                this.l4 = this.l3();
                break;
            case "MinimumValue":
            case "MaximumValue":
                this.ck();
                this.g4();
                break;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.lo;
        },
        set: function (a) {
            this.lo = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.ln;
        },
        set: function (a) {
            this.ln = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.ls;
        },
        set: function (a) {
            this.ls = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.lr;
        },
        set: function (a) {
            this.lr = a;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.l7 = function () {
        if (this.lm == null || this.lm.count == 0 || this.lm.count < this.la - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.la, this.lm.count - 1));
        var b = Math.max(0, Math.min(this.k9, this.lm.count - 1));
        var c = +(this.actualMinimumValue) != +(this.lm.item(a)) || +(this.actualMaximumValue) != +(this.lm.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.lm.item(a);
            this.actualMaximumValue = this.lm.item(b);
            this.l8();
        }
    };
    OrdinalTimeXAxis.prototype.l8 = function () {
        if (this.lm == null || this.lm.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.dy(this.bf.m3.left, b)));
        var d = truncate(Math.ceil(this.dy(this.bf.m3.right, b)));
        var e = c >= 0 && c < this.lm.count ? this.lm.item(c) : this.actualMinimumValue;
        var f = d >= 0 && d < this.lm.count ? this.lm.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.lx;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.lx = a;
                this.gz("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lm", {
        get: function () {
            return this.ll;
        },
        set: function (a) {
            if (this.ll != a) {
                var b = this.ll;
                this.ll = a;
                this.gz("DateTimeColumn", b, this.ll);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.hh = function (a, b) {
        _super.prototype.hh.call(this, a, b);
        this.l8();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.lm == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.lm.count && this.lm.item(f) < d) {
            ;
        }
        var g = this.lm.count;
        while (--g >= 0 && this.lm.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.dv(f, h);
        var j = this.dv(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lk", {
        get: function () {
            return this.lj;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.l6 = function (a, b) {
        this.g5(false);
    };
    OrdinalTimeXAxis.prototype.gv = function (a) {
        _super.prototype.gv.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.e5 = function (a) {
        if (this.ar != null) {
            return this.ar(a);
        }
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e5.call(this, a);
        }
        var b = TimeXAxis.mm(a, this.l5, this.lk, this.eq);
        return b == null ? _super.prototype.e5.call(this, a) : b;
    };
    OrdinalTimeXAxis.prototype.fi = 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.jy - 1) {
            return _super.prototype.fi.call(this, a);
        }
        var c = this.lm.item(b);
        var d = this.e5(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "l5", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.kx = function () {
        return this.lm;
    };
    OrdinalTimeXAxis.prototype.hg = function (a, b) {
        _super.prototype.hg.call(this, a, b);
        this.l8();
    };
    OrdinalTimeXAxis.prototype.k3 = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.k3.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.k2 = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.l3 = function () {
        var _this = this;
        if (this.lm == null || this.lm.count < 2) {
            return (0);
        }
        return TimeXAxis.mu(function (a) { return _this.lm.item(a); }, this.lm.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.mr(this.l4);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.lq;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.lq = a;
                this.gt(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.lp;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.lp = a;
                this.gt(this, "MaximumValue", b, this.maximumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.cm = function () {
        if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
            return _super.prototype.cm.call(this);
        }
        if (this.cf && this.cn) {
            this.a9 = this.a8();
        }
        if (this.je == null || this.lm == null) {
            return false;
        }
        var a = this.la;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.lm.count) {
                if (this.lm.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.je.count - 1 : this.je.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.je.count;
            while (d-- > 0) {
                if (this.lm.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.la || c != this.k9) {
            var e = new AxisRangeChangedEventArgs(0, this.la, a, this.k9, c);
            this.la = a;
            this.k9 = c;
            this.g0(e);
            this.l7();
            this.ka();
            return true;
        }
        return false;
    };
    OrdinalTimeXAxis.prototype.kj = function (a) {
        _super.prototype.kj.call(this, a);
        this.cl(true);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ce;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.j$c = function (a, b) {
        return this.dy.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$b = function (a, b) {
        return this.dv.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gl.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gm.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gn.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