/*
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-angular-core";
import { CategoryItemHighlightType_$type } from "./CategoryItemHighlightType";
import { DataTemplate } from "igniteui-angular-core";
import { CategoryItemHighlightLayerFrame } from "./CategoryItemHighlightLayerFrame";
import { Base, enumGetBox, fromEnum, typeCast, Point_$type, markType, markDep, runOn } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { ItemHighlightFrameRect } from "./ItemHighlightFrameRect";
import { List$1 } from "igniteui-angular-core";
import { IHasCategoryModePreference_$type } from "./IHasCategoryModePreference";
import { Rect } from "igniteui-angular-core";
import { MarkerSeries } from "./MarkerSeries";
import { DataContext } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { ContentControl } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity, truncate } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Marker } from "./Marker";
import { BrushUtil } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { DataTemplatePassInfo } from "igniteui-angular-core";
import { DataTemplateRenderInfo } from "igniteui-angular-core";
import { DataTemplateMeasureInfo } from "igniteui-angular-core";
/**
 * @hidden
 */
var CategoryItemHighlightLayer = /** @class */ (function (_super) {
    tslib_1.__extends(CategoryItemHighlightLayer, _super);
    function CategoryItemHighlightLayer() {
        var _this = _super.call(this) || this;
        _this.m9 = false;
        _this.m8 = true;
        _this.nc = 10;
        var a = new CategoryItemHighlightLayerFrame();
        var b = new CategoryItemHighlightLayerFrame();
        var c = new CategoryItemHighlightLayerFrame();
        _this.l2 = a;
        _this.l1 = b;
        _this.l3 = c;
        _this.ab = CategoryItemHighlightLayer.$;
        return _this;
    }
    CategoryItemHighlightLayer.prototype.bf = function () {
        return new CategoryItemHighlightLayerView(this);
    };
    CategoryItemHighlightLayer.prototype.iu = function (a) {
        _super.prototype.iu.call(this, a);
        this.m4 = a;
    };
    CategoryItemHighlightLayer.prototype.ml = function (a, b) {
        if (this.m7 == null || this.m7 == a) {
            if (!this.aq.c) {
                this.jd(b);
            }
        }
    };
    CategoryItemHighlightLayer.prototype.l8 = function (a) {
        if (!_super.prototype.l8.call(this, a)) {
            return false;
        }
        var b = this.mg(a);
        if (!b.c) {
            return false;
        }
        return true;
    };
    CategoryItemHighlightLayer.prototype.mn = function (a, b) {
        var e_1, _a;
        _super.prototype.mn.call(this, a, b);
        var c = a;
        var d = this.nb;
        c.g.clear();
        if (isNaN_(this.m1.x) && isNaN_(this.m1.y)) {
            return;
        }
        if (this.l8(this.m7)) {
            this.nm(this.m7, c, d);
        }
        else {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.bs.series)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var e = _c.value;
                    if (this.l8(e)) {
                        this.nm(e, c, d);
                    }
                }
            }
            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.iz = function (a, b, c, d) {
        _super.prototype.iz.call(this, a, b, c, d);
        switch (b) {
            case CategoryItemHighlightLayer.$$p[4]:
                this.jd(true);
                break;
            case CategoryItemHighlightLayer.$$p[5]:
                this.m9 = d;
                this.jd(true);
                break;
            case CategoryItemHighlightLayer.$$p[1]:
                this.jd(true);
                break;
            case CategoryItemHighlightLayer.$$p[0]:
                this.nc = this.nd;
                this.jd(true);
                break;
            case CategoryItemHighlightLayer.$$p[3]:
                this.m8 = d;
                this.jd(true);
                break;
        }
    };
    CategoryItemHighlightLayer.prototype.nm = function (a, b, c) {
        if (this.bi == null || this.bi.bs.isEmpty || this.bi.br.isEmpty) {
            return;
        }
        if (!a.cl && !a.cr) {
            return;
        }
        var d = a;
        if (d.categoryAxis == null) {
            return;
        }
        var e = this.m1.x;
        e = this.bi.br.left + this.bi.br.width * (e - this.bi.bs.left) / this.bi.bs.width;
        var f = this.m1.y;
        f = this.bi.br.top + this.bi.br.height * (f - this.bi.bs.top) / this.bi.bs.height;
        var g = this.na;
        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.m5 == 2) {
            k = false;
        }
        if (this.m5 == 1) {
            k = true;
        }
        var l = this.mg(a);
        if (!l.c) {
            return;
        }
        if (k) {
            var m = a.ll(l.d, this.nb, g);
            if (j != 0 && !d.categoryAxis.cd) {
                var n = m.x;
                if (a.cr) {
                    n -= a.getOffsetValue();
                    n += a.getCategoryWidth() * 0.5;
                    m = { $type: Point_$type, x: n, y: m.y };
                }
                else if (a.cl) {
                    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.lo(m);
            }
            this.nk(m, b, a);
        }
        else {
            var o = a.ll(l.d, this.nb, 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.nc;
                if (j != 0) {
                    t = s.jr(this.bi.bs, this.bi.br, q);
                }
                if (isNaN_(t) || isInfinity(t)) {
                    return;
                }
                p = new Rect(0, this.ly.left, r - t / 2, this.ly.width, t);
            }
            else {
                var u = o.x;
                var v = d.categoryAxis;
                var w = this.nc;
                if (j != 0) {
                    w = v.jr(this.bi.bs, this.bi.br, q);
                }
                if (isNaN_(w) || isInfinity(w)) {
                    return;
                }
                p = new Rect(0, u - w / 2, this.ly.top, w, this.ly.height);
            }
            p.intersect(this.bi.br);
            this.nl(p, b, a);
        }
    };
    CategoryItemHighlightLayer.prototype.nk = function (a, b, c) {
        var d = new ItemHighlightFrameRect();
        d.b = a.x;
        d.e = a.y;
        d.i = this.mz();
        d.j = this.m0();
        if (d.i == null) {
            if (c.hasMarkers) {
                d.i = this.m4.cf(c.k6());
            }
            else {
                d.i = this.m4.cf(c.k3);
            }
        }
        if (d.j == null) {
            if (c.hasMarkers) {
                d.j = this.m4.cf(c.k7());
            }
            else {
                d.j = this.m4.cf(c.k4);
            }
        }
        d.d = this.ey;
        d.f = Base.getHashCodeStatic(c);
        d.g = this.m6(c, a);
        var e = (typeCast(MarkerSeries.$, c) !== null) ? c.mi : null;
        if (e == null || e == MarkerSeries.ml) {
            var f = MarkerSeries.l2(c, 2);
            switch (f) {
                case 3:
                case 13:
                    e = this.bs.kn;
                    break;
                case 4:
                    e = this.bs.kw;
                    break;
                case 5:
                    e = this.bs.kt;
                    break;
                case 6:
                    e = this.bs.ku;
                    break;
                case 7:
                    e = this.bs.ko;
                    break;
                case 8:
                    e = this.bs.kr;
                    break;
                case 9:
                    e = this.bs.kp;
                    break;
                case 10:
                    e = this.bs.kv;
                    break;
                case 11:
                    e = this.bs.ks;
                    break;
                case 12:
                    e = this.bs.kq;
                    break;
            }
        }
        d.h = this.np != null ? this.np : e;
        if (!isNaN_(d.b) && !isNaN_(d.e)) {
            b.g.addItem(d.f, d);
        }
    };
    CategoryItemHighlightLayer.prototype.m6 = function (a, b) {
        var c = a.fp(b);
        var d = a.eb(b);
        if (this.nb && d != Math.floor(d)) {
            c = null;
        }
        return ((function () {
            var $ret = new DataContext();
            $ret.series = a;
            $ret.item = c;
            return $ret;
        })());
    };
    CategoryItemHighlightLayer.prototype.nl = 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.mz();
        d.j = this.m0();
        if (d.i == null) {
            if (c != null) {
                d.i = this.m4.cg(c.k3);
            }
        }
        if (d.j == null) {
            if (c != null) {
                d.j = this.m4.cg(c.k4);
            }
        }
        d.d = this.ey;
        d.f = Base.getHashCodeStatic(c);
        if (!a.isEmpty) {
            b.g.addItem(d.f, d);
        }
    };
    CategoryItemHighlightLayer.prototype.mq = function (a, b) {
        var e_2, _a;
        _super.prototype.mq.call(this, a, b);
        var c = this.m4.b3;
        var d = this.m4.b2;
        var e = 0;
        var f = 0;
        var g = a;
        try {
            for (var _b = tslib_1.__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.nn(h, i);
                    f++;
                }
                else {
                    var j = c.item(e);
                    this.no(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.nn = 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.ll(c, this.ca() || this.m9, this.m8);
        if (isNaN_(e.x) || isNaN_(e.y)) {
            b._visibility = 1;
            return;
        }
        this.m4.b9(b, e.x, e.y);
        b.ah = a.h;
        b.content = a.g;
    };
    CategoryItemHighlightLayer.prototype.no = function (a, b) {
        if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
            b._visibility = 1;
            return;
        }
        this.m4.ca(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.lb != null) {
            b.ai = this.lb;
        }
        else {
            b.ai = null;
        }
        b.ad = this.lc;
    };
    CategoryItemHighlightLayer.prototype.c8 = function () {
        return true;
    };
    CategoryItemHighlightLayer.$t = markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    CategoryItemHighlightLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:nd:nq', [1, 10], 'HighlightType:m5:nr', [CategoryItemHighlightType_$type, enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerTemplate:np:ns', [DataTemplate.$, null], 'SkipUnknownValues:na:nt', [0, true], 'TargetSeries:m7:nu', [Series.$, null], 'UseInterpolation:nb:nv', [0, false]]);
    return CategoryItemHighlightLayer;
}(AnnotationLayer));
export { CategoryItemHighlightLayer };
/**
 * @hidden
 */
var CategoryItemHighlightLayerView = /** @class */ (function (_super) {
    tslib_1.__extends(CategoryItemHighlightLayerView, _super);
    function CategoryItemHighlightLayerView(a) {
        var _this = _super.call(this, a) || this;
        _this.b1 = null;
        _this.b3 = null;
        _this.b2 = null;
        _this.b4 = null;
        _this.b5 = null;
        _this.b1 = a;
        _this.b4 = new List$1(ContentControl.$, 0);
        _this.b5 = new List$1(Rectangle.$, 0);
        return _this;
    }
    CategoryItemHighlightLayerView.prototype.ap = function () {
        var _this = this;
        _super.prototype.ap.call(this);
        this.b3 = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.ch);
            $ret.activate = runOn(_this, _this.cb);
            $ret.disactivate = runOn(_this, _this.cd);
            $ret.destroy = runOn(_this, _this.cc);
            return $ret;
        })());
        this.b2 = ((function () {
            var $ret = new Pool$1(ContentControl.$);
            $ret.create = runOn(_this, _this.ce);
            $ret.activate = runOn(_this, _this.b6);
            $ret.disactivate = runOn(_this, _this.b8);
            $ret.destroy = runOn(_this, _this.b7);
            return $ret;
        })());
    };
    CategoryItemHighlightLayerView.prototype.ch = function () {
        var a = new Rectangle();
        a.ab = false;
        this.b5.add(a);
        return a;
    };
    CategoryItemHighlightLayerView.prototype.cb = function (a) {
        a._visibility = 0;
    };
    CategoryItemHighlightLayerView.prototype.cd = function (a) {
        a._visibility = 1;
    };
    CategoryItemHighlightLayerView.prototype.cc = function (a) {
        this.b5.remove(a);
    };
    CategoryItemHighlightLayerView.prototype.ce = function () {
        var a = new Marker();
        this.b4.add(a);
        return a;
    };
    CategoryItemHighlightLayerView.prototype.b6 = function (a) {
        a._visibility = 0;
    };
    CategoryItemHighlightLayerView.prototype.b8 = function (a) {
        a._visibility = 1;
    };
    CategoryItemHighlightLayerView.prototype.b7 = function (a) {
        this.b4.remove(a);
    };
    CategoryItemHighlightLayerView.prototype.cf = function (a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.l(a, 0.3);
    };
    CategoryItemHighlightLayerView.prototype.cg = function (a) {
        if (a != null) {
            var b = BrushUtil.l(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.ca = function (a, b, c, d, e) {
        a._visibility = 0;
        a.n = b;
        a.o = c;
        a.width = d;
        a.height = e;
    };
    CategoryItemHighlightLayerView.prototype.b9 = 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.k7();
            }
            d.thickness = 0.5;
        }
    };
    CategoryItemHighlightLayerView.prototype.a3 = function (a, b) {
        var e_3, _a;
        _super.prototype.a3.call(this, a, b);
        if (a.d && !b) {
            for (var c = 0; c < this.b5.count; c++) {
                var d = this.b5._inner[c];
                if (d._visibility == 0) {
                    a.v(d);
                }
            }
            if (this.b4.count > 0) {
                var e = new DataTemplatePassInfo();
                e.isHitTestRender = b;
                e.context = a.g();
                e.viewportTop = this.br.top;
                e.viewportLeft = this.br.left;
                e.viewportWidth = this.br.width;
                e.viewportHeight = this.br.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.b4.count; m++) {
                    var n = this.b4._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 _b = tslib_1.__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.ai = function (a) {
        _super.prototype.ai.call(this, a);
        for (var b = 0; b < this.b5.count; b++) {
            this.e.a2.exportRectangleData(a, this.b5._inner[b], "catItemRect", ["Main", "CategoryItem"]);
        }
        for (var c = 0; c < this.b4.count; c++) {
            this.e.a2.exportMarkerVisualDataFromMarker(this.e, a, this.b4._inner[c]);
        }
    };
    CategoryItemHighlightLayerView.$t = markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
}(AnnotationLayerView));
export { CategoryItemHighlightLayerView };
//# sourceMappingURL=CategoryItemHighlightLayer_combined.js.map