/*
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-react-core/ES5/FastItemDateTimeColumn";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { ScalerParams } from "./ScalerParams";
import { EventArgs, runOn, delegateCombine, typeCast, Date_$type, markType } from "igniteui-react-core/ES5/type";
import { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { TimeAxisBase } from "./TimeAxisBase";
import { TimeXAxis } from "./TimeXAxis";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { truncate } from "igniteui-react-core/ES5/number";
import { dateMaxValue, dateMinValue } from "igniteui-react-core/ES5/date";
/**
 * @hidden
 */
var OrdinalTimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.li = dateMaxValue();
        _this.lh = dateMinValue();
        _this.lm = dateMaxValue();
        _this.ll = dateMinValue();
        _this.lr = null;
        _this.lf = null;
        _this.ld = null;
        _this.ly = 0;
        _this.lk = dateMinValue();
        _this.lj = dateMaxValue();
        _this.visibleRangeChanged = null;
        FastItemDateTimeColumn.m();
        _this.ld = new TimeAxisLabelFormatCollection();
        var a = _this.le;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.l0));
        _this.k4 = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.dv = function (a, b, c) {
        return this.dt(a, new ScalerParams(0, b, c, this.b8, this.ip()));
    };
    OrdinalTimeXAxis.prototype.du = function (a, b, c) {
        return this.dt(a, b);
    };
    OrdinalTimeXAxis.prototype.dt = function (a, b) {
        var c = this.k3;
        var d = this.k4;
        var e = this.k3 - this.k4;
        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.gg = function (a, b, c, d, e) {
        var f = this.kp(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.dt(j[h], e);
            }
        }
    };
    OrdinalTimeXAxis.prototype.gh = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dt(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.dy = function (a, b, c) {
        return this.dw(a, new ScalerParams(0, b, this.iu, this.b8, this.ip()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.dw(a, new ScalerParams(0, b, this.iu, this.b8, this.ip()));
    };
    OrdinalTimeXAxis.prototype.dw = 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.k4 + e * (this.k3 - this.k4);
    };
    OrdinalTimeXAxis.prototype.dx = function (a, b, c) {
        return this.dw(a, b);
    };
    OrdinalTimeXAxis.prototype.gi = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dw(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.go = function (a, b, c, d) {
        _super.prototype.go.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.lg);
                    this.lg = null;
                }
                if (this.i8 != null) {
                    this.lg = TimeAxisBase.ks(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.i8 != null) {
                    this.i8.deregisterColumn(this.lg);
                    this.lg = TimeAxisBase.ks(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeColumn":
                this.ck();
                this.ly = this.lx();
                break;
            case "MinimumValue":
            case "MaximumValue":
                this.ck();
                this.gz();
                break;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.li;
        },
        set: function (a) {
            this.li = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.lh;
        },
        set: function (a) {
            this.lh = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.lm;
        },
        set: function (a) {
            this.lm = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.ll;
        },
        set: function (a) {
            this.ll = a;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.l1 = function () {
        if (this.lg == null || this.lg.count == 0 || this.lg.count < this.k4 - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.k4, this.lg.count - 1));
        var b = Math.max(0, Math.min(this.k3, this.lg.count - 1));
        var c = +(this.actualMinimumValue) != +(this.lg.item(a)) || +(this.actualMaximumValue) != +(this.lg.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.lg.item(a);
            this.actualMaximumValue = this.lg.item(b);
            this.l2();
        }
    };
    OrdinalTimeXAxis.prototype.l2 = function () {
        if (this.lg == null || this.lg.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.dw(this.bf.m3.left, b)));
        var d = truncate(Math.ceil(this.dw(this.bf.m3.right, b)));
        var e = c >= 0 && c < this.lg.count ? this.lg.item(c) : this.actualMinimumValue;
        var f = d >= 0 && d < this.lg.count ? this.lg.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.lr;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.lr = a;
                this.gu("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lg", {
        get: function () {
            return this.lf;
        },
        set: function (a) {
            if (this.lf != a) {
                var b = this.lf;
                this.lf = a;
                this.gu("DateTimeColumn", b, this.lf);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.hc = function (a, b) {
        _super.prototype.hc.call(this, a, b);
        this.l2();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.lg == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.lg.count && this.lg.item(f) < d) {
            ;
        }
        var g = this.lg.count;
        while (--g >= 0 && this.lg.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.dt(f, h);
        var j = this.dt(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "le", {
        get: function () {
            return this.ld;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.l0 = function (a, b) {
        this.g0(false);
    };
    OrdinalTimeXAxis.prototype.gq = function (a) {
        _super.prototype.gq.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.e1 = function (a) {
        if (this.ar != null) {
            return this.ar(a);
        }
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e1.call(this, a);
        }
        var b = TimeXAxis.mg(a, this.lz, this.le, this.eo);
        return b == null ? _super.prototype.e1.call(this, a) : b;
    };
    OrdinalTimeXAxis.prototype.fe = 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.js - 1) {
            return _super.prototype.fe.call(this, a);
        }
        var c = this.lg.item(b);
        var d = this.e1(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lz", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.kr = function () {
        return this.lg;
    };
    OrdinalTimeXAxis.prototype.hb = function (a, b) {
        _super.prototype.hb.call(this, a, b);
        this.l2();
    };
    OrdinalTimeXAxis.prototype.kx = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.kx.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.kw = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.lx = function () {
        var _this = this;
        if (this.lg == null || this.lg.count < 2) {
            return (0);
        }
        return TimeXAxis.mo(function (a) { return _this.lg.item(a); }, this.lg.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.ml(this.ly);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.lk;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.lk = a;
                this.go(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.lj;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.lj = a;
                this.go(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.i8 == null || this.lg == null) {
            return false;
        }
        var a = this.k4;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.lg.count) {
                if (this.lg.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.i8.count - 1 : this.i8.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.i8.count;
            while (d-- > 0) {
                if (this.lg.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.k4 || c != this.k3) {
            var e = new AxisRangeChangedEventArgs(0, this.k4, a, this.k3, c);
            this.k4 = a;
            this.k3 = c;
            this.gv(e);
            this.l1();
            this.j4();
            return true;
        }
        return false;
    };
    OrdinalTimeXAxis.prototype.kd = function (a) {
        _super.prototype.kd.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.dw.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$b = function (a, b) {
        return this.dt.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gg.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gh.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gi.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 };
