/*
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 { 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
 */
export let CategoryItemHighlightLayer = /*@__PURE__*/ (() => {
    class CategoryItemHighlightLayer extends AnnotationLayer {
        bi() {
            return new CategoryItemHighlightLayer();
        }
        get_ep() {
            return true;
        }
        constructor() {
            super();
            this.zu = false;
            this.zt = true;
            this.zx = 10;
            let a = new CategoryItemHighlightLayerFrame();
            let b = new CategoryItemHighlightLayerFrame();
            let c = new CategoryItemHighlightLayerFrame();
            this.w3 = a;
            this.w2 = b;
            this.w4 = c;
            this.ab = CategoryItemHighlightLayer.$;
        }
        cq() {
            return new CategoryItemHighlightLayerView(this);
        }
        qw(a) {
            super.qw(a);
            this.zo = a;
        }
        yg(a, b) {
            if (this.zs == null || this.zs == a) {
                if (!this.a0.c) {
                    this.rm(b);
                }
            }
        }
        w9(a) {
            if (!super.w9(a)) {
                return false;
            }
            if (this.z6 != null) {
                if (a.e9) {
                    let b = a.m9();
                    if (!Base.equalsStatic(this.z6, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.z6, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.yb(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        yi(a, b) {
            super.yi(a, b);
            let c = a;
            let d = this.zw;
            c.g.clear();
            if (isNaN_(this.zl.x) && isNaN_(this.zl.y)) {
                return;
            }
            if (this.w9(this.zs)) {
                this.aac(this.zs, c, d);
            }
            else {
                for (let e of fromEnum(this.c9.series)) {
                    if (this.w9(e)) {
                        this.aac(e, c, d);
                    }
                    if (e.isStacked) {
                        e.py((f) => {
                            if (this.w9(f)) {
                                this.aac(f, c, d);
                            }
                            if (f.ee) {
                                f.pw((g) => {
                                    if (this.w9(g)) {
                                        this.aac(g, c, d);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (e.ee) {
                        e.pw((f) => {
                            if (this.w9(f)) {
                                this.aac(f, c, d);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        q4(a, b, c, d) {
            super.q4(a, b, c, d);
            switch (b) {
                case CategoryItemHighlightLayer.$$p[4]:
                case CategoryItemHighlightLayer.$$p[5]:
                case CategoryItemHighlightLayer.$$p[2]:
                case CategoryItemHighlightLayer.$$p[3]:
                    this.rm(true);
                    break;
                case CategoryItemHighlightLayer.$$p[7]:
                case CategoryItemHighlightLayer.$$p[8]:
                    this.rm(true);
                    break;
                case CategoryItemHighlightLayer.$$p[9]:
                    this.zu = d;
                    this.rm(true);
                    break;
                case CategoryItemHighlightLayer.$$p[1]:
                    this.rm(true);
                    break;
                case CategoryItemHighlightLayer.$$p[0]:
                    this.zx = this.zy;
                    this.rm(true);
                    break;
                case CategoryItemHighlightLayer.$$p[6]:
                    this.zt = d;
                    this.rm(true);
                    break;
            }
        }
        aac(a, b, c) {
            if (this.ct == null || this.ct.by.isEmpty || this.ct.bx.isEmpty) {
                return;
            }
            if (!a.ew && !a.e4) {
                return;
            }
            let d = a;
            if (d.categoryAxis == null) {
                return;
            }
            let e = this.zl.x;
            e = this.ct.bx.left + this.ct.bx.width * (e - this.ct.by.left) / this.ct.by.width;
            let f = this.zl.y;
            f = this.ct.bx.top + this.ct.bx.height * (f - this.ct.by.top) / this.ct.by.height;
            let g = this.zv;
            let h = true;
            let i = typeCast(IHasCategoryModePreference_$type, a);
            let j = 0;
            if (i != null) {
                j = i.preferredCategoryMode(d.categoryAxis);
                if (j == 2) {
                    h = false;
                }
            }
            let k = true;
            if (!h || this.zp == 2) {
                k = false;
            }
            if (this.zp == 1) {
                k = true;
            }
            let l = this.yb(a);
            if (!l.c) {
                return;
            }
            if (k) {
                let m = a.v5(l.d, this.zw, g);
                if (j != 0 && !d.categoryAxis.cn) {
                    let 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.wa(m);
                }
                this.aaa(m, b, a);
            }
            else {
                let o = a.v5(l.d, this.zw, g);
                let p;
                let q = this.getEffectiveViewport1(this.ct);
                if (a.isVertical) {
                    let r = o.y;
                    let s = d.categoryAxis;
                    let t = this.zx;
                    if (j != 0) {
                        t = s.k5(this.ct.by, this.ct.bx, q);
                    }
                    if (isNaN_(t) || isInfinity(t)) {
                        return;
                    }
                    p = new Rect(0, this.wk.left, r - t / 2, this.wk.width, t);
                }
                else {
                    let u = o.x;
                    let v = d.categoryAxis;
                    let w = this.zx;
                    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.wk.top, w, this.wk.height);
                }
                p.intersect(this.ct.bx);
                this.aab(p, b, a);
            }
        }
        aaa(a, b, c) {
            let d = new ItemHighlightFrameRect();
            d.b = a.x;
            d.e = a.y;
            d.i = this.zb();
            if (this.aaq != null) {
                d.i = this.aaq;
            }
            d.j = this.zc();
            if (this.aar != null) {
                d.j = this.aar;
            }
            if (d.i == null) {
                if (c.hasMarkers) {
                    d.i = this.zo.cl(c.ve());
                }
                else {
                    d.i = this.zo.cl(c.u2);
                }
            }
            if (d.j == null) {
                if (c.hasMarkers) {
                    d.j = this.zo.cl(c.vf());
                }
                else {
                    d.j = this.zo.cl(c.u6);
                }
            }
            d.d = this.ic;
            d.f = Base.getHashCodeStatic(c);
            d.g = this.zq(c, a);
            let e = (typeCast(MarkerSeries.$, c) !== null) ? c.xr : null;
            if (e == null || e == MarkerSeries.xu || (this.zr != 2 && this.zr != 0)) {
                let f = MarkerSeries.w2(c, 2);
                if (this.zr != 2 && this.zr != 0) {
                    f = this.zr;
                }
                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.aaf != null ? this.aaf : e;
            if (!isNaN_(d.b) && !isNaN_(d.e)) {
                b.g.addItem(d.f, d);
            }
        }
        zq(a, b) {
            let c = a.kl(b);
            let d = a.ip(b);
            if (this.zw && d != Math.floor(d)) {
                c = null;
            }
            return ((() => {
                let $ret = new DataContext();
                $ret.series = a;
                $ret.item = c;
                return $ret;
            })());
        }
        aab(a, b, c) {
            let d = new ItemHighlightFrameRect();
            d.b = a.left;
            d.e = a.top;
            d.c = a.right;
            d.a = a.bottom;
            d.i = this.zb();
            d.j = this.zc();
            if (d.i == null) {
                if (c != null) {
                    d.i = this.zo.cm(c.u2);
                }
            }
            if (d.j == null) {
                if (c != null) {
                    d.j = this.zo.cm(c.u6);
                }
            }
            d.d = this.ic;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        yl(a, b) {
            super.yl(a, b);
            let c = this.zo.b9;
            let d = this.zo.b8;
            let e = 0;
            let f = 0;
            let g = a;
            for (let h of fromEnum(g.g.values)) {
                if (h.h != null) {
                    let i = d.item(f);
                    this.aad(h, i);
                    f++;
                }
                else {
                    let j = c.item(e);
                    this.aae(h, j);
                    e++;
                }
            }
            c.count = e;
            d.count = f;
        }
        aad(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.d) || a.g == null) {
                b._visibility = 1;
                return;
            }
            let c = { $type: Point_$type, x: a.b, y: a.e };
            let d = a.g;
            d.itemBrush = a.i;
            let e = d.series.v5(c, this.d1() || this.zu, this.zt);
            if (isNaN_(e.x) || isNaN_(e.y)) {
                b._visibility = 1;
                return;
            }
            this.zo.cf(b, e.x, e.y);
            b.ah = a.h;
            b.content = a.g;
        }
        aae(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.zo.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.vv != null) {
                b.ai = this.vv;
            }
            else {
                b.ai = null;
            }
            b.aj = this.vw;
            b.am = this.vy;
            b.al = this.vx;
            b.ak = this.vx;
            b.ac = this.jf;
        }
        f8() {
            return true;
        }
    }
    CategoryItemHighlightLayer.$t = /*@__PURE__*/ markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    CategoryItemHighlightLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:zy:aag', [1, 10], 'HighlightType:zp:aah', [CategoryItemHighlightType_$type, /*@__PURE__*/ enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerBrush:aaq:aai', [Brush.$, null], 'MarkerOutline:aar:aaj', [Brush.$, null], 'MarkerTemplate:aaf:aak', [DataTemplate.$, null], 'MarkerType:zr:aal', [MarkerType_$type, /*@__PURE__*/ enumGetBox(MarkerType_$type, 2)], 'SkipUnknownValues:zv:aam', [0, true], 'TargetSeriesName:z6:aan', [2, null], 'TargetSeries:zs:aao', [Series.$, null], 'UseInterpolation:zw:aap', [0, false]]);
    return CategoryItemHighlightLayer;
})();
/**
 * @hidden
 */
export let CategoryItemHighlightLayerView = /*@__PURE__*/ (() => {
    class CategoryItemHighlightLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            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);
        }
        au() {
            super.au();
            this.b9 = ((() => {
                let $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 = ((() => {
                let $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;
            })());
        }
        cn() {
            let a = new Rectangle();
            a.ab = false;
            this.cb.add(a);
            return a;
        }
        ch(a) {
            a._visibility = 0;
        }
        cj(a) {
            a._visibility = 1;
        }
        ci(a) {
            this.cb.remove(a);
        }
        ck() {
            let a = new Marker();
            this.ca.add(a);
            return a;
        }
        cc(a) {
            a._visibility = 0;
        }
        ce(a) {
            a._visibility = 1;
        }
        cd(a) {
            this.ca.remove(a);
        }
        cl(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.m(a, 0.3);
        }
        cm(a) {
            if (a != null) {
                let b = BrushUtil.m(a, 0.3);
                if (b.isGradient) {
                    let c = b;
                    if (c.gradientStops != null) {
                        for (let d = 0; d < c.gradientStops.length; d++) {
                            let 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;
            }
        }
        cg(a, b, c, d, e) {
            a._visibility = 0;
            a.n = b;
            a.o = c;
            a.width = d;
            a.height = e;
        }
        cf(a, b, c) {
            a.n = b;
            a.o = c;
        }
        bj(a, b) {
            super.bj(a, b);
            let c = a;
            let d = c.content;
            if (d != null) {
                if (d.itemBrush != null) {
                    d.actualItemBrush = d.itemBrush;
                }
                let e = d.series;
                if (e.hasMarkers) {
                    d.outline = e.vf();
                }
                d.thickness = e.il();
            }
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.cb.count; c++) {
                    let d = this.cb._inner[c];
                    if (d._visibility == 0) {
                        a.w(d);
                    }
                }
                if (this.ca.count > 0) {
                    let 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";
                    let f = new DataTemplateRenderInfo();
                    f.isHitTestRender = b;
                    f.passInfo = e;
                    let g = new DataTemplateMeasureInfo();
                    g.passInfo = e;
                    let h = false;
                    let i = a.h();
                    g.context = i;
                    f.context = i;
                    g.renderContext = a;
                    f.renderContext = a;
                    let j = 0;
                    let k = 0;
                    let l = new Dictionary$2(DataTemplate.$, DataTemplate.$, 0);
                    for (let m = 0; m < this.ca.count; m++) {
                        let n = this.ca._inner[m];
                        if (n == null || n.ah == null) {
                            continue;
                        }
                        let 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;
                    }
                    for (let p of fromEnum(l.keys)) {
                        if (p != null && p.passCompleted != null) {
                            p.passCompleted(e);
                        }
                    }
                }
            }
        }
        an(a) {
            super.an(a);
            for (let b = 0; b < this.cb.count; b++) {
                this.e.bb.exportRectangleData(a, this.cb._inner[b], "catItemRect", ["Main", "CategoryItem"]);
            }
            for (let c = 0; c < this.ca.count; c++) {
                this.e.bb.exportMarkerVisualDataFromMarker(this.e, a, this.ca._inner[c]);
            }
        }
    }
    CategoryItemHighlightLayerView.$t = /*@__PURE__*/ markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
})();
