/*
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";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisLabellingMode_$type } from "./TimeAxisLabellingMode";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { EventArgs, runOn, delegateCombine, typeCast, enumGetBox, Date_$type, markType } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { TimeAxisBase } from "./TimeAxisBase";
import { TimeXAxis } from "./TimeXAxis";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { truncate } from "igniteui-react-core";
import { dateMaxValue, dateMinValue } from "igniteui-react-core";
/**
 * @hidden
 */
var OrdinalTimeXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.l0 = dateMaxValue();
        _this.lz = dateMinValue();
        _this.l4 = dateMaxValue();
        _this.l3 = dateMinValue();
        _this.l9 = null;
        _this.lv = 0;
        _this.lx = null;
        _this.lt = null;
        _this.mh = 0;
        _this.l2 = dateMinValue();
        _this.l1 = dateMaxValue();
        _this.visibleRangeChanged = null;
        FastItemDateTimeColumn.o();
        _this.lt = new TimeAxisLabelFormatCollection();
        var a = _this.lu;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.mj));
        _this.lj = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.d0 = function (a, b, c) {
        return this.dy(a, new ScalerParams(0, b, c, this.ca, this.i4()));
    };
    OrdinalTimeXAxis.prototype.dz = function (a, b, c) {
        return this.dy(a, b);
    };
    OrdinalTimeXAxis.prototype.dy = function (a, b) {
        var c = this.li;
        var d = this.lj;
        var e = this.li - this.lj;
        var f = e >= 1 ? (a - d) / (c - d) : e == 0 ? 0.5 : NaN;
        if (this.cb) {
            f = 1 - f;
        }
        var g = b.d;
        var h = b.e;
        return g.left + g.width * (f - h.left) / h.width;
    };
    OrdinalTimeXAxis.prototype.gr = function (a, b, c, d, e) {
        var f = this.k4(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.dy(j[h], e);
            }
        }
    };
    OrdinalTimeXAxis.prototype.gs = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dy(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.d3 = function (a, b, c) {
        return this.d1(a, new ScalerParams(0, b, this.i9, this.ca, this.i4()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.d1(a, new ScalerParams(0, b, this.i9, this.ca, this.i4()));
    };
    OrdinalTimeXAxis.prototype.d1 = function (a, b) {
        var c = b.e;
        var d = b.d;
        var e = c.left + (a - d.left) * c.width / d.width;
        if (this.cb) {
            e = 1 - e;
        }
        return this.lj + e * (this.li - this.lj);
    };
    OrdinalTimeXAxis.prototype.d2 = function (a, b, c) {
        return this.d1(a, b);
    };
    OrdinalTimeXAxis.prototype.gt = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.d1(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.gz = function (a, b, c, d) {
        _super.prototype.gz.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.ly);
                    this.ly = null;
                }
                if (this.jn != null) {
                    this.ly = TimeAxisBase.k7(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.jn != null) {
                    this.jn.deregisterColumn(this.ly);
                    this.ly = TimeAxisBase.k7(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeColumn":
                this.cn();
                this.mh = this.mg();
                break;
            case "MinimumValue":
            case "MaximumValue":
                this.cn();
                this.ha();
                break;
            case "LabellingMode":
                this.ha();
                break;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.l0;
        },
        set: function (a) {
            this.l0 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.lz;
        },
        set: function (a) {
            this.lz = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.l4;
        },
        set: function (a) {
            this.l4 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.l3;
        },
        set: function (a) {
            this.l3 = a;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.mk = function () {
        if (this.ly == null || this.ly.count == 0 || this.ly.count < this.lj - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.lj, this.ly.count - 1));
        var b = Math.max(0, Math.min(this.li, this.ly.count - 1));
        var c = +(this.actualMinimumValue) != +(this.ly.item(a)) || +(this.actualMaximumValue) != +(this.ly.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.ly.item(a);
            this.actualMaximumValue = this.ly.item(b);
            this.ml();
        }
    };
    OrdinalTimeXAxis.prototype.ml = function () {
        if (this.ly == null || this.ly.count == 0 || this.bh == 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 = this.i3();
        var c = new ScalerParams(1, this.bh.oi, this.bh.oh, this.ca);
        var d = truncate(Math.ceil(this.d1(b.left, c)));
        var e = truncate(Math.ceil(this.d1(b.right, c)));
        var f = d >= 0 && d < this.ly.count ? this.ly.item(d) : this.actualMinimumValue;
        var g = e >= 0 && e < this.ly.count ? this.ly.item(e) : this.actualMaximumValue;
        var h = +(this.visibleMinimum) != +f || +(this.visibleMaximum) != +g;
        this.visibleMinimum = f;
        this.visibleMaximum = g;
        if (h && this.visibleRangeChanged != null) {
            this.visibleRangeChanged(this, EventArgs.empty);
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "dateTimeMemberPath", {
        get: function () {
            return this.l9;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.l9 = a;
                this.g5("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lw", {
        get: function () {
            return this.lv;
        },
        set: function (a) {
            var b = this.lw;
            if (a != b) {
                this.lv = a;
                this.g5("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.lw));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "ly", {
        get: function () {
            return this.lx;
        },
        set: function (a) {
            if (this.lx != a) {
                var b = this.lx;
                this.lx = a;
                this.g5("DateTimeColumn", b, this.lx);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.ho = function (a, b) {
        _super.prototype.ho.call(this, a, b);
        this.ml();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.ly == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.ly.count && this.ly.item(f) < d) {
        }
        var g = this.ly.count;
        while (--g >= 0 && this.ly.item(g) > e) {
        }
        var h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.ca, this.bh.n6);
        var i = this.dy(f, h);
        var j = this.dy(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lu", {
        get: function () {
            return this.lt;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.mj = function (a, b) {
        this.hb(false);
    };
    OrdinalTimeXAxis.prototype.g1 = function (a) {
        _super.prototype.g1.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.e8 = function (a) {
        if (this.at != null) {
            return this.at(a);
        }
        if (this.ah != null) {
            return this.ah.i(a);
        }
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e8.call(this, a);
        }
        var b = dateMinValue();
        var c = false;
        if (this.lk != null) {
            if (typeCast(Date_$type, this.lk) !== null) {
                b = this.lk;
                c = true;
            }
        }
        var d = TimeXAxis.mz(a, c, b, this.lw, this.mi, this.lu, this.et);
        return d == null ? _super.prototype.e8.call(this, a) : d;
    };
    OrdinalTimeXAxis.prototype.fl = 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.j8 - 1) {
            return _super.prototype.fl.call(this, a);
        }
        var c = this.ly.item(b);
        var d = this.e8(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "mi", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.k6 = function () {
        return this.ly;
    };
    OrdinalTimeXAxis.prototype.hn = function (a, b) {
        _super.prototype.hn.call(this, a, b);
        this.ml();
    };
    OrdinalTimeXAxis.prototype.lc = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.lc.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.lb = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.mg = function () {
        var _this = this;
        if (this.ly == null || this.ly.count < 2) {
            return (0);
        }
        return TimeXAxis.m9(function (a) { return _this.ly.item(a); }, this.ly.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.m5(this.mh);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.l2;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.l2 = a;
                this.gz(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.l1;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.l1 = a;
                this.gz(this, "MaximumValue", b, this.maximumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.cp = function () {
        if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
            return _super.prototype.cp.call(this);
        }
        if (this.ci && this.cq) {
            this.bb = this.ba();
        }
        if (this.jn == null || this.ly == null) {
            return false;
        }
        var a = this.lj;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.ly.count) {
                if (this.ly.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.jn.count - 1 : this.jn.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.jn.count;
            while (d-- > 0) {
                if (this.ly.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.lj || c != this.li) {
            var e = new AxisRangeChangedEventArgs(0, this.lj, a, this.li, c);
            this.lj = a;
            this.li = c;
            this.g6(e);
            this.mk();
            this.kj();
            return true;
        }
        return false;
    };
    OrdinalTimeXAxis.prototype.ks = function (a) {
        _super.prototype.ks.call(this, a);
        this.co(true);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.j$c = function (a, b) {
        return this.d1.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$b = function (a, b) {
        return this.dy.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gr.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gs.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gt.apply(this, arguments);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "j$a", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.$t = markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
    return OrdinalTimeXAxis;
}(CategoryXAxis));
export { OrdinalTimeXAxis };
//# sourceMappingURL=OrdinalTimeXAxis.js.map
