/*
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 { __extends, __values } from "tslib";
import { AnnotationLayer } from "./AnnotationLayer";
import { Series } from "./Series";
import { DependencyProperty } from "igniteui-react-core";
import { CategoryItemHighlightType_$type } from "./CategoryItemHighlightType";
import { MarkerType_$type } from "./MarkerType";
import { Brush } from "igniteui-react-core";
import { DataTemplate } from "igniteui-react-core";
import { CategoryItemHighlightLayerFrame } from "./CategoryItemHighlightLayerFrame";
import { Base, enumGetBox, fromEnum, typeCast, Point_$type, markType, markDep, runOn } from "igniteui-react-core";
import { Dictionary$2 } from "igniteui-react-core";
import { ItemHighlightFrameRect } from "./ItemHighlightFrameRect";
import { List$1 } from "igniteui-react-core";
import { IHasCategoryModePreference_$type } from "./IHasCategoryModePreference";
import { Rect } from "igniteui-react-core";
import { MarkerSeries } from "./MarkerSeries";
import { DataContext } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { ContentControl } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, isInfinity, truncate } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Marker } from "./Marker";
import { BrushUtil } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
import { DataTemplatePassInfo } from "igniteui-react-core";
import { DataTemplateRenderInfo } from "igniteui-react-core";
import { DataTemplateMeasureInfo } from "igniteui-react-core";
/**
 * @hidden
 */
var CategoryItemHighlightLayer = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategoryItemHighlightLayer, _super);
    function CategoryItemHighlightLayer() {
        var _this = _super.call(this) || this;
        _this.zv = false;
        _this.zu = true;
        _this.zy = 10;
        var a = new CategoryItemHighlightLayerFrame();
        var b = new CategoryItemHighlightLayerFrame();
        var c = new CategoryItemHighlightLayerFrame();
        _this.w4 = a;
        _this.w3 = b;
        _this.w5 = c;
        _this.ab = CategoryItemHighlightLayer.$;
        return _this;
    }
    CategoryItemHighlightLayer.prototype.bi = function () {
        return new CategoryItemHighlightLayer();
    };
    CategoryItemHighlightLayer.prototype.get_ep = function () {
        return true;
    };
    CategoryItemHighlightLayer.prototype.cq = function () {
        return new CategoryItemHighlightLayerView(this);
    };
    CategoryItemHighlightLayer.prototype.qx = function (a) {
        _super.prototype.qx.call(this, a);
        this.zp = a;
    };
    CategoryItemHighlightLayer.prototype.yh = function (a, b) {
        if (this.zt == null || this.zt == a) {
            if (!this.a0.c) {
                this.rn(b);
            }
        }
    };
    CategoryItemHighlightLayer.prototype.xa = function (a) {
        if (!_super.prototype.xa.call(this, a)) {
            return false;
        }
        if (this.z7 != null) {
            if (a.e9) {
                var b = a.na();
                if (!Base.equalsStatic(this.z7, b)) {
                    return false;
                }
            }
            else {
                if (!Base.equalsStatic(this.z7, a.name)) {
                    return false;
                }
            }
        }
        var c = this.yc(a);
        if (!c.c) {
            return false;
        }
        return true;
    };
    CategoryItemHighlightLayer.prototype.yj = function (a, b) {
        var e_1, _a;
        var _this = this;
        _super.prototype.yj.call(this, a, b);
        var c = a;
        var d = this.zx;
        c.g.clear();
        if (isNaN_(this.zm.x) && isNaN_(this.zm.y)) {
            return;
        }
        if (this.xa(this.zt)) {
            this.aad(this.zt, c, d);
        }
        else {
            try {
                for (var _b = __values(fromEnum(this.c9.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    if (this.xa(e)) {
                        this.aad(e, c, d);
                    }
                    if (e.isStacked) {
                        e.pz(function (f) {
                            if (_this.xa(f)) {
                                _this.aad(f, c, d);
                            }
                            if (f.ee) {
                                f.px(function (g) {
                                    if (_this.xa(g)) {
                                        _this.aad(g, c, d);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (e.ee) {
                        e.px(function (f) {
                            if (_this.xa(f)) {
                                _this.aad(f, c, d);
                            }
                            return true;
                        });
                    }
                }
            }
            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;
                }
            }
        }
    };
    CategoryItemHighlightLayer.prototype.q5 = function (a, b, c, d) {
        _super.prototype.q5.call(this, a, b, c, d);
        switch (b) {
            case CategoryItemHighlightLayer.$$p[4]:
            case CategoryItemHighlightLayer.$$p[5]:
            case CategoryItemHighlightLayer.$$p[2]:
            case CategoryItemHighlightLayer.$$p[3]:
                this.rn(true);
                break;
            case CategoryItemHighlightLayer.$$p[7]:
            case CategoryItemHighlightLayer.$$p[8]:
                this.rn(true);
                break;
            case CategoryItemHighlightLayer.$$p[9]:
                this.zv = d;
                this.rn(true);
                break;
            case CategoryItemHighlightLayer.$$p[1]:
                this.rn(true);
                break;
            case CategoryItemHighlightLayer.$$p[0]:
                this.zy = this.zz;
                this.rn(true);
                break;
            case CategoryItemHighlightLayer.$$p[6]:
                this.zu = d;
                this.rn(true);
                break;
        }
    };
    CategoryItemHighlightLayer.prototype.aad = function (a, b, c) {
        if (this.ct == null || this.ct.by.isEmpty || this.ct.bx.isEmpty) {
            return;
        }
        if (!a.ew && !a.e4) {
            return;
        }
        var d = a;
        if (d.categoryAxis == null) {
            return;
        }
        var e = this.zm.x;
        e = this.ct.bx.left + this.ct.bx.width * (e - this.ct.by.left) / this.ct.by.width;
        var f = this.zm.y;
        f = this.ct.bx.top + this.ct.bx.height * (f - this.ct.by.top) / this.ct.by.height;
        var g = this.zw;
        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.zq == 2) {
            k = false;
        }
        if (this.zq == 1) {
            k = true;
        }
        var l = this.yc(a);
        if (!l.c) {
            return;
        }
        if (k) {
            var m = a.v6(l.d, this.zx, g);
            if (j != 0 && !d.categoryAxis.cn) {
                var n = m.x;
                if (a.e4) {
                    n -= a.getOffsetValue();
                    n += a.getCategoryWidth() * 0.5;
                    m = { $type: Point_$type, x: n, y: m.y };
                }
                else if (a.ew) {
                    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.wb(m);
            }
            this.aab(m, b, a);
        }
        else {
            var o = a.v6(l.d, this.zx, g);
            var p = void 0;
            var q = this.getEffectiveViewport1(this.ct);
            if (a.isVertical) {
                var r = o.y;
                var s = d.categoryAxis;
                var t = this.zy;
                if (j != 0) {
                    t = s.k5(this.ct.by, this.ct.bx, q);
                }
                if (isNaN_(t) || isInfinity(t)) {
                    return;
                }
                p = new Rect(0, this.wl.left, r - t / 2, this.wl.width, t);
            }
            else {
                var u = o.x;
                var v = d.categoryAxis;
                var w = this.zy;
                if (j != 0) {
                    w = v.k5(this.ct.by, this.ct.bx, q);
                }
                if (isNaN_(w) || isInfinity(w)) {
                    return;
                }
                p = new Rect(0, u - w / 2, this.wl.top, w, this.wl.height);
            }
            p.intersect(this.ct.bx);
            this.aac(p, b, a);
        }
    };
    CategoryItemHighlightLayer.prototype.aab = function (a, b, c) {
        var d = new ItemHighlightFrameRect();
        d.b = a.x;
        d.e = a.y;
        d.i = this.zc();
        if (this.aar != null) {
            d.i = this.aar;
        }
        d.j = this.zd();
        if (this.aas != null) {
            d.j = this.aas;
        }
        if (d.i == null) {
            if (c.hasMarkers) {
                d.i = this.zp.cl(c.vf());
            }
            else {
                d.i = this.zp.cl(c.u3);
            }
        }
        if (d.j == null) {
            if (c.hasMarkers) {
                d.j = this.zp.cl(c.vg());
            }
            else {
                d.j = this.zp.cl(c.u7);
            }
        }
        d.d = this.ic;
        d.f = Base.getHashCodeStatic(c);
        d.g = this.zr(c, a);
        var e = (typeCast(MarkerSeries.$, c) !== null) ? c.xs : null;
        if (e == null || e == MarkerSeries.xv || (this.zs != 2 && this.zs != 0)) {
            var f = MarkerSeries.w3(c, 2);
            if (this.zs != 2 && this.zs != 0) {
                f = this.zs;
            }
            switch (f) {
                case 3:
                case 13:
                    e = this.c9.rn;
                    break;
                case 4:
                    e = this.c9.rw;
                    break;
                case 5:
                    e = this.c9.rt;
                    break;
                case 6:
                    e = this.c9.ru;
                    break;
                case 7:
                    e = this.c9.ro;
                    break;
                case 8:
                    e = this.c9.rr;
                    break;
                case 9:
                    e = this.c9.rp;
                    break;
                case 10:
                    e = this.c9.rv;
                    break;
                case 11:
                    e = this.c9.rs;
                    break;
                case 12:
                    e = this.c9.rq;
                    break;
            }
        }
        d.h = this.aag != null ? this.aag : e;
        if (!isNaN_(d.b) && !isNaN_(d.e)) {
            b.g.addItem(d.f, d);
        }
    };
    CategoryItemHighlightLayer.prototype.zr = function (a, b) {
        var c = a.kl(b);
        var d = a.ip(b);
        if (this.zx && d != Math.floor(d)) {
            c = null;
        }
        return ((function () {
            var $ret = new DataContext();
            $ret.series = a;
            $ret.item = c;
            return $ret;
        })());
    };
    CategoryItemHighlightLayer.prototype.aac = 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.zc();
        d.j = this.zd();
        if (d.i == null) {
            if (c != null) {
                d.i = this.zp.cm(c.u3);
            }
        }
        if (d.j == null) {
            if (c != null) {
                d.j = this.zp.cm(c.u7);
            }
        }
        d.d = this.ic;
        d.f = Base.getHashCodeStatic(c);
        if (!a.isEmpty) {
            b.g.addItem(d.f, d);
        }
    };
    CategoryItemHighlightLayer.prototype.ym = function (a, b) {
        var e_2, _a;
        _super.prototype.ym.call(this, a, b);
        var c = this.zp.b9;
        var d = this.zp.b8;
        var e = 0;
        var f = 0;
        var g = a;
        try {
            for (var _b = __values(fromEnum(g.g.values)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var h = _c.value;
                if (h.h != null) {
                    var i = d.item(f);
                    this.aae(h, i);
                    f++;
                }
                else {
                    var j = c.item(e);
                    this.aaf(h, j);
                    e++;
                }
            }
        }
        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;
            }
        }
        c.count = e;
        d.count = f;
    };
    CategoryItemHighlightLayer.prototype.aae = 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.v6(c, this.d1() || this.zv, this.zu);
        if (isNaN_(e.x) || isNaN_(e.y)) {
            b._visibility = 1;
            return;
        }
        this.zp.cf(b, e.x, e.y);
        b.ah = a.h;
        b.content = a.g;
    };
    CategoryItemHighlightLayer.prototype.aaf = function (a, b) {
        if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
            b._visibility = 1;
            return;
        }
        this.zp.cg(b, a.b, a.e, a.c - a.b, a.a - a.e);
        b._fill = a.i;
        b._stroke = a.j;
        b.ad = a.d;
        if (this.vw != null) {
            b.ai = this.vw;
        }
        else {
            b.ai = null;
        }
        b.aj = this.vx;
        b.am = this.vz;
        b.al = this.vy;
        b.ak = this.vy;
        b.ac = this.jf;
    };
    CategoryItemHighlightLayer.prototype.f8 = function () {
        return true;
    };
    CategoryItemHighlightLayer.$t = markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    CategoryItemHighlightLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:zz:aah', [1, 10], 'HighlightType:zq:aai', [CategoryItemHighlightType_$type, enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerBrush:aar:aaj', [Brush.$, null], 'MarkerOutline:aas:aak', [Brush.$, null], 'MarkerTemplate:aag:aal', [DataTemplate.$, null], 'MarkerType:zs:aam', [MarkerType_$type, enumGetBox(MarkerType_$type, 2)], 'SkipUnknownValues:zw:aan', [0, true], 'TargetSeriesName:z7:aao', [2, null], 'TargetSeries:zt:aap', [Series.$, null], 'UseInterpolation:zx:aaq', [0, false]]);
    return CategoryItemHighlightLayer;
}(AnnotationLayer));
export { CategoryItemHighlightLayer };
/**
 * @hidden
 */
var CategoryItemHighlightLayerView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategoryItemHighlightLayerView, _super);
    function CategoryItemHighlightLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.b7 = null;
        _this.b9 = null;
        _this.b8 = null;
        _this.ca = null;
        _this.cb = null;
        _this.b7 = a;
        _this.ca = new List$1(ContentControl.$, 0);
        _this.cb = new List$1(Rectangle.$, 0);
        return _this;
    }
    CategoryItemHighlightLayerView.prototype.au = function () {
        var _this = this;
        _super.prototype.au.call(this);
        this.b9 = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.cn);
            $ret.activate = runOn(_this, _this.ch);
            $ret.disactivate = runOn(_this, _this.cj);
            $ret.destroy = runOn(_this, _this.ci);
            return $ret;
        })());
        this.b8 = ((function () {
            var $ret = new Pool$1(ContentControl.$);
            $ret.create = runOn(_this, _this.ck);
            $ret.activate = runOn(_this, _this.cc);
            $ret.disactivate = runOn(_this, _this.ce);
            $ret.destroy = runOn(_this, _this.cd);
            return $ret;
        })());
    };
    CategoryItemHighlightLayerView.prototype.cn = function () {
        var a = new Rectangle();
        a.ab = false;
        this.cb.add(a);
        return a;
    };
    CategoryItemHighlightLayerView.prototype.ch = function (a) {
        a._visibility = 0;
    };
    CategoryItemHighlightLayerView.prototype.cj = function (a) {
        a._visibility = 1;
    };
    CategoryItemHighlightLayerView.prototype.ci = function (a) {
        this.cb.remove(a);
    };
    CategoryItemHighlightLayerView.prototype.ck = function () {
        var a = new Marker();
        this.ca.add(a);
        return a;
    };
    CategoryItemHighlightLayerView.prototype.cc = function (a) {
        a._visibility = 0;
    };
    CategoryItemHighlightLayerView.prototype.ce = function (a) {
        a._visibility = 1;
    };
    CategoryItemHighlightLayerView.prototype.cd = function (a) {
        this.ca.remove(a);
    };
    CategoryItemHighlightLayerView.prototype.cl = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.m(a, 0.3);
    };
    CategoryItemHighlightLayerView.prototype.cm = function (a) {
        if (a != null) {
            var b = BrushUtil.m(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.cg = function (a, b, c, d, e) {
        a._visibility = 0;
        a.n = b;
        a.o = c;
        a.width = d;
        a.height = e;
    };
    CategoryItemHighlightLayerView.prototype.cf = function (a, b, c) {
        a.n = b;
        a.o = c;
    };
    CategoryItemHighlightLayerView.prototype.bj = function (a, b) {
        _super.prototype.bj.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.vg();
            }
            d.thickness = e.il();
        }
    };
    CategoryItemHighlightLayerView.prototype.a8 = function (a, b) {
        var e_3, _a;
        _super.prototype.a8.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.cb.count; c++) {
                var d = this.cb._inner[c];
                if (d._visibility == 0) {
                    a.w(d);
                }
            }
            if (this.ca.count > 0) {
                var e = new DataTemplatePassInfo();
                e.isHitTestRender = b;
                e.context = a.h();
                e.viewportTop = this.bx.top;
                e.viewportLeft = this.bx.left;
                e.viewportWidth = this.bx.width;
                e.viewportHeight = this.bx.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.h();
                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.ca.count; m++) {
                    var n = this.ca._inner[m];
                    if (n == null || n.ah == null) {
                        continue;
                    }
                    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.bi(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.q(f, n);
                    n.m = f.availableWidth;
                    n.l = f.availableHeight;
                }
                try {
                    for (var _b = __values(fromEnum(l.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var p = _c.value;
                        if (p != null && p.passCompleted != null) {
                            p.passCompleted(e);
                        }
                    }
                }
                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;
                    }
                }
            }
        }
    };
    CategoryItemHighlightLayerView.prototype.an = function (a) {
        _super.prototype.an.call(this, a);
        for (var b = 0; b < this.cb.count; b++) {
            this.e.bb.exportRectangleData(a, this.cb._inner[b], "catItemRect", ["Main", "CategoryItem"]);
        }
        for (var c = 0; c < this.ca.count; c++) {
            this.e.bb.exportMarkerVisualDataFromMarker(this.e, a, this.ca._inner[c]);
        }
    };
    CategoryItemHighlightLayerView.$t = markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
}(AnnotationLayerView));
export { CategoryItemHighlightLayerView };
