/*
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 { IFastItemsSource_$type } from "igniteui-react-core/ES5/IFastItemsSource";
import { TimeAxisBase } from "./TimeAxisBase";
import { runOn, delegateCombine, typeCast, Date_$type, markType } from "igniteui-react-core/ES5/type";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { TimeXAxis } from "./TimeXAxis";
import { truncate } from "igniteui-react-core/ES5/number";
import { dateMaxValue, dateMinValue } from "igniteui-react-core/ES5/date";
var OrdinalTimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.lh = dateMaxValue();
        _this.lg = dateMinValue();
        _this.lj = dateMaxValue();
        _this.li = dateMinValue();
        _this.lo = null;
        _this.le = null;
        _this.lc = null;
        _this.actualRangeChanged = null;
        FastItemDateTimeColumn.m();
        _this.lc = new TimeAxisLabelFormatCollection();
        var a = _this.ld;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.lu));
        return _this;
    }
    OrdinalTimeXAxis.prototype.gn = function (a, b, c, d) {
        _super.prototype.gn.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.lf);
                    this.lf = null;
                }
                if (this.i7 != null) {
                    this.lf = TimeAxisBase.ks(this.lq, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.i7 != null) {
                    this.i7.deregisterColumn(this.lf);
                    this.lf = TimeAxisBase.ks(this.lq, this);
                }
                break;
            case "DateTimeColumn":
                this.lv();
                break;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.lh;
        },
        set: function (a) {
            this.lh = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.lg;
        },
        set: function (a) {
            this.lg = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.lj;
        },
        set: function (a) {
            this.lj = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.li;
        },
        set: function (a) {
            this.li = a;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.kc = function (a) {
        _super.prototype.kc.call(this, a);
        this.lv();
    };
    OrdinalTimeXAxis.prototype.lv = function () {
        if (this.lf == null || this.lf.count == 0) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = +(this.actualMinimumValue) != +(this.lf.item(0)) && +(this.actualMaximumValue) != +(this.lf.item(this.lf.count - 1));
        if (a) {
            var b = this.actualMinimumValue;
            var c = this.actualMaximumValue;
            this.actualMinimumValue = this.lf.item(0);
            this.actualMaximumValue = this.lf.item(this.lf.count - 1);
            this.lw();
            if (this.actualRangeChanged != null) {
                this.actualRangeChanged(this, new AxisRangeChangedEventArgs(0, b.getTime(), this.actualMinimumValue.getTime(), c.getTime(), this.actualMaximumValue.getTime()));
            }
        }
    };
    OrdinalTimeXAxis.prototype.lw = function () {
        if (this.lf == null || this.lf.count == 0 || this.bf == null) {
            this.visibleMinimum = this.actualMinimumValue;
            this.visibleMaximum = this.actualMaximumValue;
            return;
        }
        var a = new ScalerParams(1, this.bf.my, this.it, this.b8);
        var b = truncate(Math.ceil(this.dw(this.it.left, a)));
        var c = truncate(Math.ceil(this.dw(this.it.right, a)));
        this.visibleMinimum = b >= 0 && b < this.lf.count ? this.lf.item(b) : this.actualMinimumValue;
        this.visibleMaximum = c >= 0 && c < this.lf.count ? this.lf.item(c) : this.actualMaximumValue;
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lq", {
        get: function () {
            return this.lo;
        },
        set: function (a) {
            var b = this.lq;
            if (a != b) {
                this.lo = a;
                this.gt("DateTimeMemberPath", b, this.lq);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lf", {
        get: function () {
            return this.le;
        },
        set: function (a) {
            if (this.le != a) {
                var b = this.le;
                this.le = a;
                this.gt("DateTimeColumn", b, this.le);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.hb = function (a, b) {
        _super.prototype.hb.call(this, a, b);
        this.lw();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.lf == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.lf.count && this.lf.item(f) < d) {
            ;
        }
        var g = this.lf.count;
        while (--g >= 0 && this.lf.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.mo);
        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, "ld", {
        get: function () {
            return this.lc;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.lu = function (a, b) {
        this.gz(false);
    };
    OrdinalTimeXAxis.prototype.gp = function (a) {
        _super.prototype.gp.call(this, a);
        this.lq = a;
    };
    OrdinalTimeXAxis.prototype.e0 = function (a) {
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e0.call(this, a);
        }
        var b = TimeXAxis.mc(a, this.lt, this.ld);
        return b == null ? _super.prototype.e0.call(this, a) : b;
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lt", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.kq = function () {
        return this.lf;
    };
    OrdinalTimeXAxis.prototype.ha = function (a, b) {
        _super.prototype.ha.call(this, a, b);
        this.lw();
    };
    OrdinalTimeXAxis.prototype.kw = function (a, b) {
        return _super.prototype.kw.call(this, a + 0.5, b);
    };
    OrdinalTimeXAxis.prototype.kv = function (a, b, c, d) {
        return b;
    };
    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.gf.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gg.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gh.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 };
