/*
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 {
        get_d5() {
            return true;
        }
        constructor() {
            super();
            this.w6 = false;
            this.w5 = true;
            this.w9 = 10;
            let a = new CategoryItemHighlightLayerFrame();
            let b = new CategoryItemHighlightLayerFrame();
            let c = new CategoryItemHighlightLayerFrame();
            this.uf = a;
            this.ue = b;
            this.ug = c;
            this.ab = CategoryItemHighlightLayer.$;
        }
        cg() {
            return new CategoryItemHighlightLayerView(this);
        }
        o0(a) {
            super.o0(a);
            this.w0 = a;
        }
        vs(a, b) {
            if (this.w4 == null || this.w4 == a) {
                if (!this.at.c) {
                    this.pp(b);
                }
            }
        }
        ul(a) {
            if (!super.ul(a)) {
                return false;
            }
            if (this.xi != null) {
                if (a.ep) {
                    let b = a.lu();
                    if (!Base.equalsStatic(this.xi, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.xi, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.vn(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        vu(a, b) {
            super.vu(a, b);
            let c = a;
            let d = this.w8;
            c.g.clear();
            if (isNaN_(this.wx.x) && isNaN_(this.wx.y)) {
                return;
            }
            if (this.ul(this.w4)) {
                this.xo(this.w4, c, d);
            }
            else {
                for (let e of fromEnum(this.cy.series)) {
                    if (this.ul(e)) {
                        this.xo(e, c, d);
                    }
                    if (e.isStacked) {
                        e.n5((f) => {
                            if (this.ul(f)) {
                                this.xo(f, c, d);
                            }
                            if (f.dv) {
                                f.n3((g) => {
                                    if (this.ul(g)) {
                                        this.xo(g, c, d);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (e.dv) {
                        e.n3((f) => {
                            if (this.ul(f)) {
                                this.xo(f, c, d);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            switch (b) {
                case CategoryItemHighlightLayer.$$p[4]:
                case CategoryItemHighlightLayer.$$p[5]:
                case CategoryItemHighlightLayer.$$p[2]:
                case CategoryItemHighlightLayer.$$p[3]:
                    this.pp(true);
                    break;
                case CategoryItemHighlightLayer.$$p[7]:
                case CategoryItemHighlightLayer.$$p[8]:
                    this.pp(true);
                    break;
                case CategoryItemHighlightLayer.$$p[9]:
                    this.w6 = d;
                    this.pp(true);
                    break;
                case CategoryItemHighlightLayer.$$p[1]:
                    this.pp(true);
                    break;
                case CategoryItemHighlightLayer.$$p[0]:
                    this.w9 = this.xa;
                    this.pp(true);
                    break;
                case CategoryItemHighlightLayer.$$p[6]:
                    this.w5 = d;
                    this.pp(true);
                    break;
            }
        }
        xo(a, b, c) {
            if (this.cj == null || this.cj.by.isEmpty || this.cj.bx.isEmpty) {
                return;
            }
            if (!a.ec && !a.ek) {
                return;
            }
            let d = a;
            if (d.categoryAxis == null) {
                return;
            }
            let e = this.wx.x;
            e = this.cj.bx.left + this.cj.bx.width * (e - this.cj.by.left) / this.cj.by.width;
            let f = this.wx.y;
            f = this.cj.bx.top + this.cj.bx.height * (f - this.cj.by.top) / this.cj.by.height;
            let g = this.w7;
            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.w1 == 2) {
                k = false;
            }
            if (this.w1 == 1) {
                k = true;
            }
            let l = this.vn(a);
            if (!l.c) {
                return;
            }
            if (k) {
                let m = a.th(l.d, this.w8, g);
                if (j != 0 && !d.categoryAxis.cn) {
                    let n = m.x;
                    if (a.ek) {
                        n -= a.getOffsetValue();
                        n += a.getCategoryWidth() * 0.5;
                        m = { $type: Point_$type, x: n, y: m.y };
                    }
                    else if (a.ec) {
                        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.tm(m);
                }
                this.xm(m, b, a);
            }
            else {
                let o = a.th(l.d, this.w8, g);
                let p;
                let q = this.getEffectiveViewport1(this.cj);
                if (a.isVertical) {
                    let r = o.y;
                    let s = d.categoryAxis;
                    let t = this.w9;
                    if (j != 0) {
                        t = s.k4(this.cj.by, this.cj.bx, q);
                    }
                    if (isNaN_(t) || isInfinity(t)) {
                        return;
                    }
                    p = new Rect(0, this.tw.left, r - t / 2, this.tw.width, t);
                }
                else {
                    let u = o.x;
                    let v = d.categoryAxis;
                    let w = this.w9;
                    if (j != 0) {
                        w = v.k4(this.cj.by, this.cj.bx, q);
                    }
                    if (isNaN_(w) || isInfinity(w)) {
                        return;
                    }
                    p = new Rect(0, u - w / 2, this.tw.top, w, this.tw.height);
                }
                p.intersect(this.cj.bx);
                this.xn(p, b, a);
            }
        }
        xm(a, b, c) {
            let d = new ItemHighlightFrameRect();
            d.b = a.x;
            d.e = a.y;
            d.i = this.wn();
            if (this.x2 != null) {
                d.i = this.x2;
            }
            d.j = this.wo();
            if (this.x3 != null) {
                d.j = this.x3;
            }
            if (d.i == null) {
                if (c.hasMarkers) {
                    d.i = this.w0.cl(c.sz());
                }
                else {
                    d.i = this.w0.cl(c.ss);
                }
            }
            if (d.j == null) {
                if (c.hasMarkers) {
                    d.j = this.w0.cl(c.s0());
                }
                else {
                    d.j = this.w0.cl(c.sv);
                }
            }
            d.d = this.hk;
            d.f = Base.getHashCodeStatic(c);
            d.g = this.w2(c, a);
            let e = (typeCast(MarkerSeries.$, c) !== null) ? c.uu : null;
            if (e == null || e == MarkerSeries.ux || (this.w3 != 2 && this.w3 != 0)) {
                let f = MarkerSeries.ub(c, 2);
                if (this.w3 != 2 && this.w3 != 0) {
                    f = this.w3;
                }
                switch (f) {
                    case 3:
                    case 13:
                        e = this.cy.py;
                        break;
                    case 4:
                        e = this.cy.p7;
                        break;
                    case 5:
                        e = this.cy.p4;
                        break;
                    case 6:
                        e = this.cy.p5;
                        break;
                    case 7:
                        e = this.cy.pz;
                        break;
                    case 8:
                        e = this.cy.p2;
                        break;
                    case 9:
                        e = this.cy.p0;
                        break;
                    case 10:
                        e = this.cy.p6;
                        break;
                    case 11:
                        e = this.cy.p3;
                        break;
                    case 12:
                        e = this.cy.p1;
                        break;
                }
            }
            d.h = this.xr != null ? this.xr : e;
            if (!isNaN_(d.b) && !isNaN_(d.e)) {
                b.g.addItem(d.f, d);
            }
        }
        w2(a, b) {
            let c = a.jr(b);
            let d = a.hv(b);
            if (this.w8 && d != Math.floor(d)) {
                c = null;
            }
            return ((() => {
                let $ret = new DataContext();
                $ret.series = a;
                $ret.item = c;
                return $ret;
            })());
        }
        xn(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.wn();
            d.j = this.wo();
            if (d.i == null) {
                if (c != null) {
                    d.i = this.w0.cm(c.ss);
                }
            }
            if (d.j == null) {
                if (c != null) {
                    d.j = this.w0.cm(c.sv);
                }
            }
            d.d = this.hk;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        vx(a, b) {
            super.vx(a, b);
            let c = this.w0.b9;
            let d = this.w0.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.xp(h, i);
                    f++;
                }
                else {
                    let j = c.item(e);
                    this.xq(h, j);
                    e++;
                }
            }
            c.count = e;
            d.count = f;
        }
        xp(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.th(c, this.dj() || this.w6, this.w5);
            if (isNaN_(e.x) || isNaN_(e.y)) {
                b._visibility = 1;
                return;
            }
            this.w0.cf(b, e.x, e.y);
            b.ah = a.h;
            b.content = a.g;
        }
        xq(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.w0.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.s7 != null) {
                b.ai = this.s7;
            }
            else {
                b.ai = null;
            }
            b.aj = this.s8;
            b.am = this.ta;
            b.al = this.s9;
            b.ak = this.s9;
            b.ac = this.il;
        }
        fm() {
            return true;
        }
    }
    CategoryItemHighlightLayer.$t = /*@__PURE__*/ markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    CategoryItemHighlightLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:xa:xs', [1, 10], 'HighlightType:w1:xt', [CategoryItemHighlightType_$type, /*@__PURE__*/ enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerBrush:x2:xu', [Brush.$, null], 'MarkerOutline:x3:xv', [Brush.$, null], 'MarkerTemplate:xr:xw', [DataTemplate.$, null], 'MarkerType:w3:xx', [MarkerType_$type, /*@__PURE__*/ enumGetBox(MarkerType_$type, 2)], 'SkipUnknownValues:w7:xy', [0, true], 'TargetSeriesName:xi:xz', [2, null], 'TargetSeries:w4:x0', [Series.$, null], 'UseInterpolation:w8:x1', [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.s0();
                }
                d.thickness = e.hs();
            }
        }
        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.a9.exportRectangleData(a, this.cb._inner[b], "catItemRect", ["Main", "CategoryItem"]);
            }
            for (let c = 0; c < this.ca.count; c++) {
                this.e.a9.exportMarkerVisualDataFromMarker(this.e, a, this.ca._inner[c]);
            }
        }
    }
    CategoryItemHighlightLayerView.$t = /*@__PURE__*/ markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
})();
