/*
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 { AnnotationLayer } from "./AnnotationLayer";
import { Series } from "./Series";
import { DependencyProperty } from "igniteui-react-core/ES5/DependencyProperty";
import { CategoryItemHighlightType_$type } from "./CategoryItemHighlightType";
import { DataTemplate } from "igniteui-react-core/ES5/DataTemplate";
import { CategoryItemHighlightLayerFrame } from "./CategoryItemHighlightLayerFrame";
import { Type, Base, enumGetBox, fromEnum, typeCast, Point_$type, markType, runOn } from "igniteui-react-core/ES5/type";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { IHasCategoryModePreference_$type } from "./IHasCategoryModePreference";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { ItemHighlightFrameRect } from "./ItemHighlightFrameRect";
import { MarkerSeries } from "./MarkerSeries";
import { DataContext } from "igniteui-react-core/ES5/DataContext";
import { Pool$1 } from "igniteui-react-core/ES5/Pool$1";
import { ContentControl } from "igniteui-react-core/ES5/ContentControl";
import { Rectangle } from "igniteui-react-core/ES5/Rectangle";
import { PropertyMetadata } from "igniteui-react-core/ES5/PropertyMetadata";
import { isNaN_, isInfinity, truncate } from "igniteui-react-core/ES5/number";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Marker } from "./Marker";
import { BrushUtil } from "igniteui-react-core/ES5/BrushUtil";
import { Color } from "igniteui-react-core/ES5/Color";
import { DataTemplatePassInfo } from "igniteui-react-core/ES5/DataTemplatePassInfo";
import { DataTemplateRenderInfo } from "igniteui-react-core/ES5/DataTemplateRenderInfo";
import { DataTemplateMeasureInfo } from "igniteui-react-core/ES5/DataTemplateMeasureInfo";
var CategoryItemHighlightLayer = /** @class */ (function (_super) {
    tslib_1.__extends(CategoryItemHighlightLayer, _super);
    function CategoryItemHighlightLayer() {
        var _this = _super.call(this) || this;
        _this.mv = false;
        _this.mu = true;
        _this.my = 10;
        var a = new CategoryItemHighlightLayerFrame();
        var b = new CategoryItemHighlightLayerFrame();
        var c = new CategoryItemHighlightLayerFrame();
        _this.lq = a;
        _this.lp = b;
        _this.lr = c;
        _this.ab = CategoryItemHighlightLayer.$;
        return _this;
    }
    CategoryItemHighlightLayer.prototype.bf = function () {
        return new CategoryItemHighlightLayerView(this);
    };
    CategoryItemHighlightLayer.prototype.ii = function (a) {
        _super.prototype.ii.call(this, a);
        this.mq = a;
    };
    CategoryItemHighlightLayer.prototype.l7 = function (a, b) {
        if (this.mt == null || this.mt == a) {
            if (!this.aq.c) {
                this.i1(b);
            }
        }
    };
    CategoryItemHighlightLayer.prototype.lu = function (a) {
        if (!_super.prototype.lu.call(this, a)) {
            return false;
        }
        var b = this.l2(a);
        if (!b.a) {
            return false;
        }
        return true;
    };
    CategoryItemHighlightLayer.prototype.l9 = function (a, b) {
        _super.prototype.l9.call(this, a, b);
        var c = a;
        var d = this.mx;
        c.g.clear();
        if (isNaN_(this.mn.x) && isNaN_(this.mn.y)) {
            return;
        }
        if (this.lu(this.mt)) {
            this.m8(this.mt, c, d);
        }
        else {
            try {
                for (var _a = tslib_1.__values(fromEnum(this.bs.series)), _b = _a.next(); !_b.done; _b = _a.next()) {
                    var e = _b.value;
                    if (this.lu(e)) {
                        this.m8(e, c, d);
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                }
                finally { if (e_1) throw e_1.error; }
            }
        }
        var e_1, _c;
    };
    CategoryItemHighlightLayer.prototype.io = function (a, b, c, d) {
        _super.prototype.io.call(this, a, b, c, d);
        switch (b) {
            case CategoryItemHighlightLayer.$$p[4]:
                this.i1(true);
                break;
            case CategoryItemHighlightLayer.$$p[5]:
                this.mv = d;
                this.i1(true);
                break;
            case CategoryItemHighlightLayer.$$p[1]:
                this.i1(true);
                break;
            case CategoryItemHighlightLayer.$$p[0]:
                this.my = this.mz;
                this.i1(true);
                break;
            case CategoryItemHighlightLayer.$$p[3]:
                this.mu = d;
                this.i1(true);
                break;
        }
    };
    CategoryItemHighlightLayer.prototype.m8 = function (a, b, c) {
        if (this.bi == null || this.bi.bq.isEmpty || this.bi.bp.isEmpty) {
            return;
        }
        if (!a.ck && !a.cq) {
            return;
        }
        var d = a;
        if (d.categoryAxis == null) {
            return;
        }
        var e = this.mn.x;
        e = this.bi.bp.left + this.bi.bp.width * (e - this.bi.bq.left) / this.bi.bq.width;
        var f = this.mn.y;
        f = this.bi.bp.top + this.bi.bp.height * (f - this.bi.bq.top) / this.bi.bq.height;
        var g = this.mw;
        var h = true;
        var i = typeCast(IHasCategoryModePreference_$type, a);
        var j = 0;
        if (i != null) {
            j = i.preferredCategoryMode(d.categoryAxis);
            if (j == 2) {
                h = false;
            }
        }
        var k = true;
        if (!h || this.mr == 2) {
            k = false;
        }
        if (this.mr == 1) {
            k = true;
        }
        var l = this.l2(a);
        if (!l.a) {
            return;
        }
        if (k) {
            var m = a.k9(l.b, this.mx, g);
            if (j != 0 && !d.categoryAxis.cc) {
                var n = m.x;
                if (a.cq) {
                    n -= a.getOffsetValue();
                    n += a.getCategoryWidth() * 0.5;
                    m = { $type: Point_$type, x: n, y: m.y };
                }
                else if (a.ck) {
                    n -= a.getOffsetValue();
                    n += a.getCategoryWidth() * 0.5;
                    m = { $type: Point_$type, x: n, y: m.y };
                }
            }
            if (!isNaN_(m.x) && !isNaN_(m.y)) {
                m = this.lc(m);
            }
            this.m6(m, b, a);
        }
        else {
            var o = a.k9(l.b, this.mx, g);
            var p = void 0;
            var q = this.getEffectiveViewport1(this.bi);
            if (a.isVertical) {
                var r = o.y;
                var s = d.categoryAxis;
                var t = this.my;
                if (j != 0) {
                    t = s.jj(this.bi.bq, this.bi.bp, q);
                }
                if (isNaN_(t) || isInfinity(t)) {
                    return;
                }
                p = new Rect(0, this.lm.left, r - t / 2, this.lm.width, t);
            }
            else {
                var u = o.x;
                var v = d.categoryAxis;
                var w = this.my;
                if (j != 0) {
                    w = v.jj(this.bi.bq, this.bi.bp, q);
                }
                if (isNaN_(w) || isInfinity(w)) {
                    return;
                }
                p = new Rect(0, u - w / 2, this.lm.top, w, this.lm.height);
            }
            p.intersect(this.bi.bp);
            this.m7(p, b, a);
        }
    };
    CategoryItemHighlightLayer.prototype.m6 = function (a, b, c) {
        var d = new ItemHighlightFrameRect();
        d.b = a.x;
        d.e = a.y;
        d.i = this.ml();
        d.j = this.mm();
        if (d.i == null) {
            if (c.hasMarkers) {
                d.i = this.mq.cd(c.ku());
            }
            else {
                d.i = this.mq.cd(c.kr);
            }
        }
        if (d.j == null) {
            if (c.hasMarkers) {
                d.j = this.mq.cd(c.kv());
            }
            else {
                d.j = this.mq.cd(c.ks);
            }
        }
        d.d = this.es;
        d.f = Base.getHashCodeStatic(c);
        d.g = this.ms(c, a);
        var e = (typeCast(MarkerSeries.$, c) !== null) ? c.l6 : null;
        if (e == null || e == MarkerSeries.l9) {
            var f = MarkerSeries.lq(c, 2);
            switch (f) {
                case 3:
                    e = this.bs.ki;
                    break;
                case 4:
                    e = this.bs.kr;
                    break;
                case 5:
                    e = this.bs.ko;
                    break;
                case 6:
                    e = this.bs.kp;
                    break;
                case 7:
                    e = this.bs.kj;
                    break;
                case 8:
                    e = this.bs.km;
                    break;
                case 9:
                    e = this.bs.kk;
                    break;
                case 10:
                    e = this.bs.kq;
                    break;
                case 11:
                    e = this.bs.kn;
                    break;
                case 12:
                    e = this.bs.kl;
                    break;
            }
        }
        d.h = this.nb != null ? this.nb : e;
        if (!isNaN_(d.b) && !isNaN_(d.e)) {
            b.g.addItem(d.f, d);
        }
    };
    CategoryItemHighlightLayer.prototype.ms = function (a, b) {
        var c = a.fj(b);
        var d = a.d6(b);
        if (this.mx && d != Math.floor(d)) {
            c = null;
        }
        return ((function () {
            var $ret = new DataContext();
            $ret.series = a;
            $ret.item = c;
            return $ret;
        })());
    };
    CategoryItemHighlightLayer.prototype.m7 = function (a, b, c) {
        var d = new ItemHighlightFrameRect();
        d.b = a.left;
        d.e = a.top;
        d.c = a.right;
        d.a = a.bottom;
        d.i = this.ml();
        d.j = this.mm();
        if (d.i == null) {
            if (c != null) {
                d.i = this.mq.ce(c.kr);
            }
        }
        if (d.j == null) {
            if (c != null) {
                d.j = this.mq.ce(c.ks);
            }
        }
        d.d = this.es;
        d.f = Base.getHashCodeStatic(c);
        if (!a.isEmpty) {
            b.g.addItem(d.f, d);
        }
    };
    CategoryItemHighlightLayer.prototype.mc = function (a, b) {
        _super.prototype.mc.call(this, a, b);
        var c = this.mq.b1;
        var d = this.mq.b0;
        var e = 0;
        var f = 0;
        var g = a;
        try {
            for (var _a = tslib_1.__values(fromEnum(g.g.values)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var h = _b.value;
                if (h.h != null) {
                    var i = d.item(f);
                    this.m9(h, i);
                    f++;
                }
                else {
                    var j = c.item(e);
                    this.na(h, j);
                    e++;
                }
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_2) throw e_2.error; }
        }
        c.count = e;
        d.count = f;
        var e_2, _c;
    };
    CategoryItemHighlightLayer.prototype.m9 = function (a, b) {
        if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.d) || a.g == null) {
            b._visibility = 1;
            return;
        }
        var c = { $type: Point_$type, x: a.b, y: a.e };
        var d = a.g;
        d.itemBrush = a.i;
        var e = d.series.k9(c, this.ca() || this.mv, this.mu);
        if (isNaN_(e.x) || isNaN_(e.y)) {
            b._visibility = 1;
            return;
        }
        this.mq.b7(b, e.x, e.y);
        b.ah = a.h;
        b.content = a.g;
    };
    CategoryItemHighlightLayer.prototype.na = function (a, b) {
        if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
            b._visibility = 1;
            return;
        }
        this.mq.b8(b, a.b, a.e, a.c - a.b, a.a - a.e);
        b._fill = a.i;
        b._stroke = a.j;
        b.ac = a.d;
        if (this.kz != null) {
            b.ai = this.kz;
        }
        else {
            b.ai = null;
        }
        b.ad = this.k0;
    };
    CategoryItemHighlightLayer.prototype.c5 = function () {
        return true;
    };
    CategoryItemHighlightLayer.$t = markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    return CategoryItemHighlightLayer;
}(AnnotationLayer));
export { CategoryItemHighlightLayer };
Type.dep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:mz:nc', [1, 10], 'HighlightType:mr:nd', [CategoryItemHighlightType_$type, enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerTemplate:nb:ne', [DataTemplate.$, null], 'SkipUnknownValues:mw:nf', [0, true], 'TargetSeries:mt:ng', [Series.$, null], 'UseInterpolation:mx:nh', [0, false]]);
var CategoryItemHighlightLayerView = /** @class */ (function (_super) {
    tslib_1.__extends(CategoryItemHighlightLayerView, _super);
    function CategoryItemHighlightLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.bz = null;
        _this.b1 = null;
        _this.b0 = null;
        _this.b2 = null;
        _this.b3 = null;
        _this.bz = a;
        _this.b2 = new List$1(ContentControl.$, 0);
        _this.b3 = new List$1(Rectangle.$, 0);
        return _this;
    }
    CategoryItemHighlightLayerView.prototype.ap = function () {
        var _this = this;
        _super.prototype.ap.call(this);
        this.b1 = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.cf);
            $ret.activate = runOn(_this, _this.b9);
            $ret.disactivate = runOn(_this, _this.cb);
            $ret.destroy = runOn(_this, _this.ca);
            return $ret;
        })());
        this.b0 = ((function () {
            var $ret = new Pool$1(ContentControl.$);
            $ret.create = runOn(_this, _this.cc);
            $ret.activate = runOn(_this, _this.b4);
            $ret.disactivate = runOn(_this, _this.b6);
            $ret.destroy = runOn(_this, _this.b5);
            return $ret;
        })());
    };
    CategoryItemHighlightLayerView.prototype.cf = function () {
        var a = new Rectangle();
        a.ab = false;
        this.b3.add(a);
        return a;
    };
    CategoryItemHighlightLayerView.prototype.b9 = function (a) {
        a._visibility = 0;
    };
    CategoryItemHighlightLayerView.prototype.cb = function (a) {
        a._visibility = 1;
    };
    CategoryItemHighlightLayerView.prototype.ca = function (a) {
        this.b3.remove(a);
    };
    CategoryItemHighlightLayerView.prototype.cc = function () {
        var a = new Marker();
        this.b2.add(a);
        return a;
    };
    CategoryItemHighlightLayerView.prototype.b4 = function (a) {
        a._visibility = 0;
    };
    CategoryItemHighlightLayerView.prototype.b6 = function (a) {
        a._visibility = 1;
    };
    CategoryItemHighlightLayerView.prototype.b5 = function (a) {
        this.b2.remove(a);
    };
    CategoryItemHighlightLayerView.prototype.cd = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(a, 0.3);
    };
    CategoryItemHighlightLayerView.prototype.ce = function (a) {
        if (a != null) {
            var b = BrushUtil.h(a, 0.3);
            if (b.isGradient) {
                var c = b;
                if (c.gradientStops != null) {
                    for (var d = 0; d < c.gradientStops.length; d++) {
                        var e = c.gradientStops[d];
                        e.color = Color.u(truncate(Math.round((e.color.l) * 0.3)), e.color.o, e.color.n, e.color.m);
                        e.color = e.color;
                    }
                }
            }
            else {
                b.color = Color.u(truncate(Math.round((b.color.l & 255) * 0.3)), b.color.o, b.color.n, b.color.m);
                b.color = b.color;
            }
            return b;
        }
        else {
            return null;
        }
    };
    CategoryItemHighlightLayerView.prototype.b8 = function (a, b, c, d, e) {
        a._visibility = 0;
        a.n = b;
        a.o = c;
        a.width = d;
        a.height = e;
    };
    CategoryItemHighlightLayerView.prototype.b7 = function (a, b, c) {
        a.n = b;
        a.o = c;
    };
    CategoryItemHighlightLayerView.prototype.be = function (a, b) {
        _super.prototype.be.call(this, a, b);
        var c = a;
        var d = c.content;
        if (d != null) {
            if (d.itemBrush != null) {
                d.actualItemBrush = d.itemBrush;
            }
            var e = d.series;
            if (e.hasMarkers) {
                d.outline = e.kv();
            }
            d.thickness = 0.5;
        }
    };
    CategoryItemHighlightLayerView.prototype.a3 = function (a, b) {
        _super.prototype.a3.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.b3.count; c++) {
                var d = this.b3._inner[c];
                if (d._visibility == 0) {
                    a.v(d);
                }
            }
            if (this.b2.count > 0) {
                var e = new DataTemplatePassInfo();
                e.isHitTestRender = b;
                e.context = a.g();
                e.viewportTop = this.bp.top;
                e.viewportLeft = this.bp.left;
                e.viewportWidth = this.bp.width;
                e.viewportHeight = this.bp.height;
                e.passID = "ItemMarkers";
                var f = new DataTemplateRenderInfo();
                f.isHitTestRender = b;
                f.passInfo = e;
                var g = new DataTemplateMeasureInfo();
                g.passInfo = e;
                var h = false;
                var i = a.g();
                g.context = i;
                f.context = i;
                g.renderContext = a;
                f.renderContext = a;
                var j = 0;
                var k = 0;
                var l = new Dictionary$2(DataTemplate.$, DataTemplate.$, 0);
                for (var m = 0; m < this.b2.count; m++) {
                    var n = this.b2._inner[m];
                    var o = n.ah;
                    if (!l.containsKey(o)) {
                        l.addItem(o, o);
                        if (o != null && o.passStarting != null) {
                            o.passStarting(e);
                        }
                    }
                    if (n._visibility == 1) {
                        continue;
                    }
                    this.bd(n, m, b);
                    if (!h) {
                        g.data = n.content;
                        g.width = n.width;
                        g.height = n.height;
                        if (o.measure != null) {
                            g.data = n.content;
                            o.measure(g);
                            h = g.isConstant;
                            if (h) {
                                j = g.width;
                                k = g.height;
                            }
                        }
                        f.availableWidth = g.width;
                        f.availableHeight = g.height;
                    }
                    else {
                        f.availableWidth = j;
                        f.availableHeight = k;
                    }
                    if (!isNaN_(n.width) && !isInfinity(n.width)) {
                        f.availableWidth = n.width;
                    }
                    if (!isNaN_(n.height) && !isInfinity(n.height)) {
                        f.availableHeight = n.height;
                    }
                    a.p(f, n);
                    n.m = f.availableWidth;
                    n.l = f.availableHeight;
                }
                try {
                    for (var _a = tslib_1.__values(fromEnum(l.keys)), _b = _a.next(); !_b.done; _b = _a.next()) {
                        var p = _b.value;
                        if (p != null && p.passCompleted != null) {
                            p.passCompleted(e);
                        }
                    }
                }
                catch (e_3_1) { e_3 = { error: e_3_1 }; }
                finally {
                    try {
                        if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                    }
                    finally { if (e_3) throw e_3.error; }
                }
            }
        }
        var e_3, _c;
    };
    CategoryItemHighlightLayerView.prototype.ai = function (a) {
        _super.prototype.ai.call(this, a);
        for (var b = 0; b < this.b3.count; b++) {
            this.e.a2.exportRectangleData(a, this.b3._inner[b], "catItemRect", ["Main", "CategoryItem"]);
        }
        for (var c = 0; c < this.b2.count; c++) {
            this.e.a2.exportMarkerVisualDataFromMarker(this.e, a, this.b2._inner[c]);
        }
    };
    CategoryItemHighlightLayerView.$t = markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
}(AnnotationLayerView));
export { CategoryItemHighlightLayerView };
/*<BeginStatics Name="Infragistics.Controls.Charts.CategoryItemHighlightLayer" />*/
/*<EndStatics Name="Infragistics.Controls.Charts.CategoryItemHighlightLayer" />*/
