/*
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 { Series } from "./Series";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { Type, Point_$type, Boolean_$type, runOn, delegateRemove, typeCast, delegateCombine, fromEnum, fromEn, markType } from "igniteui-react-core/ES5/type";
import { SeriesView } from "./SeriesView";
import { XamDataChart } from "./XamDataChart";
import { Tuple$2 } from "igniteui-react-core/ES5/Tuple$2";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES5/number";
/**
 * @hidden
 */
var AnnotationLayer = /** @class */ (function (_super) {
    tslib_1.__extends(AnnotationLayer, _super);
    function AnnotationLayer() {
        var _this = _super.call(this) || this;
        _this.mu = null;
        _this.lv = null;
        _this.lu = null;
        _this.lw = null;
        _this.ms = { $type: Point_$type, x: NaN, y: NaN };
        _this.lx = false;
        _this.mu = { $type: Point_$type, x: NaN, y: NaN };
        return _this;
    }
    AnnotationLayer.prototype.bf = function () {
        return new AnnotationLayerView(this);
    };
    AnnotationLayer.prototype.im = function (a) {
        _super.prototype.im.call(this, a);
        this.lt = a;
    };
    AnnotationLayer.prototype.lz = function (a) {
        if (a == null) {
            return false;
        }
        if (a.cj) {
            return false;
        }
        if (a == this) {
            return false;
        }
        return a.dv(a.bi.br, a.bi.bs, a.bi);
    };
    AnnotationLayer.prototype.get_cm = function () {
        return this.ly;
    };
    AnnotationLayer.prototype.bd = function () {
        if (this.be == 0) {
            return 1;
        }
        else {
            return _super.prototype.bd.call(this);
        }
    };
    AnnotationLayer.prototype.get_cw = function () {
        return this.l1 || this.l2;
    };
    AnnotationLayer.prototype.get_isUsableInLegend = function () {
        return this.l2;
    };
    AnnotationLayer.prototype.is = function (a, b, c, d) {
        _super.prototype.is.call(this, a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                var e = c;
                var f = d;
                if (e != null) {
                    this.ml(e.series);
                    var g = e.series;
                    g.collectionChanged = delegateRemove(g.collectionChanged, runOn(this, this.mi));
                    if (typeCast(XamDataChart.$, e) !== null) {
                        var h = e;
                        this.mk(h.axes);
                        var i = h.axes;
                        i.collectionChanged = delegateRemove(i.collectionChanged, runOn(this, this.l8));
                    }
                }
                if (f != null) {
                    this.mg(f.series);
                    var j = f.series;
                    j.collectionChanged = delegateCombine(j.collectionChanged, runOn(this, this.mi));
                    if (typeCast(XamDataChart.$, f) !== null) {
                        var k = f;
                        this.mf(k.axes);
                        var l = k.axes;
                        l.collectionChanged = delegateCombine(l.collectionChanged, runOn(this, this.l8));
                    }
                }
                break;
            case AnnotationLayer.$$p[3]:
            case AnnotationLayer.$$p[2]:
                if (this.cw) {
                    if (this.fe == -1) {
                        this.fe = XamDataChart.od(this);
                    }
                }
                else {
                    this.fe = -1;
                    this.kw = null;
                    this.kx = null;
                }
                if (this.bs != null) {
                    this.bs.ii();
                }
                this.i6(true);
                break;
            case "TransitionProgress":
                this.lw.c(this.ew, this.lv, this.lu);
                if (this.cc(this.bi)) {
                    return;
                }
                if (this.ew == 1) {
                    this.mh(this.lu, this.bi);
                }
                else {
                    this.mh(this.lw, this.bi);
                }
                if (this.bs != null) {
                    this.bs.jj(this);
                }
                break;
            case AnnotationLayer.$$p[1]:
                if (this.bs != null) {
                    this.bs.ig();
                }
                break;
            case AnnotationLayer.$$p[0]:
                this.mu = this.mt;
                this.ih(this.mt);
                break;
            case "ShouldRenderAsOverlay":
                if (this.bs != null) {
                    this.bi.ah(this.bs);
                    this.bi.ad(this.bs);
                }
                break;
        }
    };
    AnnotationLayer.prototype.ml = function (a) {
        var e_1, _a;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (!(b == this)) {
                    b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.mj));
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.mk = function (a) {
        var e_2, _a;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.l9));
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_2) throw e_2.error; }
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.mg = function (a) {
        var e_3, _a;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (!(b == this)) {
                    b.renderRequested = delegateCombine(b.renderRequested, runOn(this, this.mj));
                }
            }
        }
        catch (e_3_1) { e_3 = { error: e_3_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_3) throw e_3.error; }
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.mf = function (a) {
        var e_4, _a;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                b.renderRequested = delegateCombine(b.renderRequested, runOn(this, this.l9));
            }
        }
        catch (e_4_1) { e_4 = { error: e_4_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_4) throw e_4.error; }
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.l9 = function (a, b) {
        this.mb(a, b.animate);
    };
    AnnotationLayer.prototype.mj = function (a, b) {
        this.mc(a, b.animate);
    };
    AnnotationLayer.prototype.mb = function (a, b) {
    };
    AnnotationLayer.prototype.mc = function (a, b) {
    };
    AnnotationLayer.prototype.mi = function (a, b) {
        this.md(b);
    };
    AnnotationLayer.prototype.l8 = function (a, b) {
        this.ma(b);
    };
    AnnotationLayer.prototype.mq = function () {
        if (this.kw != null) {
            return this.kw;
        }
        return this.ky;
    };
    AnnotationLayer.prototype.mr = function () {
        if (this.kx != null) {
            return this.kx;
        }
        return this.k1;
    };
    AnnotationLayer.prototype.ma = function (a) {
        var e_5, _a, e_6, _b;
        if (a.oldItems != null) {
            try {
                for (var _c = tslib_1.__values(fromEn(a.oldItems)), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var b = _d.value;
                    b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.l9));
                }
            }
            catch (e_5_1) { e_5 = { error: e_5_1 }; }
            finally {
                try {
                    if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
                }
                finally { if (e_5) throw e_5.error; }
            }
        }
        if (a.newItems != null) {
            try {
                for (var _e = tslib_1.__values(fromEn(a.newItems)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var c = _f.value;
                    c.renderRequested = delegateCombine(c.renderRequested, runOn(this, this.l9));
                }
            }
            catch (e_6_1) { e_6 = { error: e_6_1 }; }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
                }
                finally { if (e_6) throw e_6.error; }
            }
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.md = function (a) {
        var e_7, _a, e_8, _b;
        if (a.oldItems != null) {
            try {
                for (var _c = tslib_1.__values(fromEn(a.oldItems)), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var b = _d.value;
                    b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.mj));
                }
            }
            catch (e_7_1) { e_7 = { error: e_7_1 }; }
            finally {
                try {
                    if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
                }
                finally { if (e_7) throw e_7.error; }
            }
        }
        if (a.newItems != null) {
            try {
                for (var _e = tslib_1.__values(fromEn(a.newItems)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var c = _f.value;
                    c.renderRequested = delegateCombine(c.renderRequested, runOn(this, this.mj));
                }
            }
            catch (e_8_1) { e_8 = { error: e_8_1 }; }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
                }
                finally { if (e_8) throw e_8.error; }
            }
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.jm = function (a, b) {
        this.i6(false);
    };
    AnnotationLayer.prototype.jl = function (a, b) {
        this.i6(true);
    };
    AnnotationLayer.prototype.i7 = function (a) {
        _super.prototype.i7.call(this, a);
        if (this.cc(this.bi)) {
            return;
        }
        if (this.c9(a) && !this.dd) {
            var b = this.lv;
            if (this.ca()) {
                if (this.bt.g) {
                    this.bt.t();
                }
                this.lv = this.lw;
                this.lw = b;
            }
            else {
                this.lv = this.lu;
                this.lu = b;
            }
            this.me(this.lu, this.bi);
            this.je();
        }
        else {
            if (!this.dd) {
                this.me(this.lu, this.bi);
            }
            this.mh(this.lu, this.bi);
        }
    };
    AnnotationLayer.prototype.get_cj = function () {
        return true;
    };
    AnnotationLayer.prototype.me = function (a, b) {
    };
    AnnotationLayer.prototype.mh = function (a, b) {
        this.lt.by();
    };
    AnnotationLayer.prototype.l7 = function (a) {
        var b = { $type: Point_$type, x: this.ms.x, y: this.ms.y };
        if (a.isVertical) {
            if (isNaN_(this.ms.y)) {
                return new Tuple$2(Boolean_$type, Point_$type, false, b);
            }
            if (isNaN_(this.ms.x)) {
                b.x = 0;
                return new Tuple$2(Boolean_$type, Point_$type, true, b);
            }
        }
        else {
            if (isNaN_(this.ms.x)) {
                return new Tuple$2(Boolean_$type, Point_$type, false, b);
            }
            if (isNaN_(this.ms.y)) {
                b.y = 0;
                return new Tuple$2(Boolean_$type, Point_$type, true, b);
            }
        }
        return new Tuple$2(Boolean_$type, Point_$type, true, b);
    };
    AnnotationLayer.prototype.ih = function (a) {
        _super.prototype.ih.call(this, a);
        if (isNaN_(this.mu.x) && isNaN_(this.mu.y)) {
            if (isNaN_(a.x) && isNaN_(a.y)) {
                this.lt.bx();
                return;
            }
            else {
                this.lt.bz();
                this.ms = a;
            }
        }
        else {
            this.lt.bz();
            this.ms = this.mu;
        }
        this.i6(true);
    };
    AnnotationLayer.prototype.dv = function (a, b, c) {
        var d = _super.prototype.dv.call(this, a, b, c);
        if (!this.bi.q()) {
            return d = false;
        }
        return d;
    };
    AnnotationLayer.prototype.get_dr = function () {
        return this.l0;
    };
    Object.defineProperty(AnnotationLayer.prototype, "l0", {
        get: function () {
            return this.lx;
        },
        set: function (a) {
            var b = this.lx;
            this.lx = a;
            this.raisePropertyChanged("ShouldRenderAsOverlay", b, this.lx);
        },
        enumerable: true,
        configurable: true
    });
    AnnotationLayer.$t = markType(AnnotationLayer, 'AnnotationLayer', Series.$);
    return AnnotationLayer;
}(Series));
export { AnnotationLayer };
Type.dep(DependencyProperty, PropertyMetadata, AnnotationLayer, 'raisePropertyChanged', ['CursorPosition:mt:mm', [Point_$type, { $type: Point_$type, x: NaN, y: NaN }], 'IsDefaultCrosshairDisabled:ly:mn', [0, true], 'UseIndex:l1:mo', [0, false], 'UseLegend:l2:mp', [0, false]]);
/**
 * @hidden
 */
var AnnotationLayerView = /** @class */ (function (_super) {
    tslib_1.__extends(AnnotationLayerView, _super);
    function AnnotationLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.bu = null;
        _this.bv = false;
        _this.bw = -1;
        _this.bu = a;
        return _this;
    }
    AnnotationLayerView.prototype.b0 = function () {
        if (this.bv) {
            this.bv = false;
            this.bw = -1;
            this.bu.ms = { $type: Point_$type, x: NaN, y: NaN };
            this.bu.i6(true);
        }
    };
    AnnotationLayerView.prototype.bx = function () {
        this.bv = true;
        if (this.e.e1 != null) {
            this.e.e1.setTimeout(runOn(this, this.b0), 300);
        }
        else {
            this.bw = window.setTimeout(runOn(this, this.b0), 300);
        }
    };
    AnnotationLayerView.prototype.bz = function () {
        if (this.bv == true) {
            this.bv = false;
            if (this.bw != -1) {
                window.clearTimeout(this.bw);
                this.bw = -1;
            }
        }
    };
    AnnotationLayerView.prototype.by = function () {
        this.an();
    };
    AnnotationLayerView.$t = markType(AnnotationLayerView, 'AnnotationLayerView', SeriesView.$);
    return AnnotationLayerView;
}(SeriesView));
export { AnnotationLayerView };
