/*
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-angular-core";
import { CategoryItemHighlightType_$type } from "./CategoryItemHighlightType";
import { MarkerType_$type } from "./MarkerType";
import { Brush } from "igniteui-angular-core";
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
 */
export let CategoryItemHighlightLayer = /*@__PURE__*/ (() => {
    class CategoryItemHighlightLayer extends AnnotationLayer {
        constructor() {
            super();
            this.th = false;
            this.tg = true;
            this.tk = 10;
            let a = new CategoryItemHighlightLayerFrame();
            let b = new CategoryItemHighlightLayerFrame();
            let c = new CategoryItemHighlightLayerFrame();
            this.qq = a;
            this.qp = b;
            this.qr = c;
            this.ab = CategoryItemHighlightLayer.$;
        }
        get_dc() {
            return true;
        }
        by() {
            return new CategoryItemHighlightLayerView(this);
        }
        l4(a) {
            super.l4(a);
            this.tb = a;
        }
        r3(a, b) {
            if (this.tf == null || this.tf == a) {
                if (!this.at.c) {
                    this.mn(b);
                }
            }
        }
        qw(a) {
            if (!super.qw(a)) {
                return false;
            }
            if (this.tt != null) {
                if (a.dx) {
                    let b = a.ju();
                    if (!Base.equalsStatic(this.tt, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.tt, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.ry(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        r5(a, b) {
            super.r5(a, b);
            let c = a;
            let d = this.tj;
            c.g.clear();
            if (isNaN_(this.s8.x) && isNaN_(this.s8.y)) {
                return;
            }
            if (this.qw(this.tf)) {
                this.tz(this.tf, c, d);
            }
            else {
                for (let e of fromEnum(this.ce.series)) {
                    if (this.qw(e)) {
                        this.tz(e, c, d);
                    }
                    if (e.isStacked) {
                        e.lf((f) => {
                            if (this.qw(f)) {
                                this.tz(f, c, d);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        l9(a, b, c, d) {
            super.l9(a, b, c, d);
            switch (b) {
                case CategoryItemHighlightLayer.$$p[4]:
                case CategoryItemHighlightLayer.$$p[5]:
                case CategoryItemHighlightLayer.$$p[2]:
                case CategoryItemHighlightLayer.$$p[3]:
                    this.mn(true);
                    break;
                case CategoryItemHighlightLayer.$$p[7]:
                case CategoryItemHighlightLayer.$$p[8]:
                    this.mn(true);
                    break;
                case CategoryItemHighlightLayer.$$p[9]:
                    this.th = d;
                    this.mn(true);
                    break;
                case CategoryItemHighlightLayer.$$p[1]:
                    this.mn(true);
                    break;
                case CategoryItemHighlightLayer.$$p[0]:
                    this.tk = this.tl;
                    this.mn(true);
                    break;
                case CategoryItemHighlightLayer.$$p[6]:
                    this.tg = d;
                    this.mn(true);
                    break;
            }
        }
        tz(a, b, c) {
            if (this.b1 == null || this.b1.bv.isEmpty || this.b1.bu.isEmpty) {
                return;
            }
            if (!a.dj && !a.ds) {
                return;
            }
            let d = a;
            if (d.categoryAxis == null) {
                return;
            }
            let e = this.s8.x;
            e = this.b1.bu.left + this.b1.bu.width * (e - this.b1.bv.left) / this.b1.bv.width;
            let f = this.s8.y;
            f = this.b1.bu.top + this.b1.bu.height * (f - this.b1.bv.top) / this.b1.bv.height;
            let g = this.ti;
            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.tc == 2) {
                k = false;
            }
            if (this.tc == 1) {
                k = true;
            }
            let l = this.ry(a);
            if (!l.c) {
                return;
            }
            if (k) {
                let m = a.ps(l.d, this.tj, g);
                if (j != 0 && !d.categoryAxis.cm) {
                    let n = m.x;
                    if (a.ds) {
                        n -= a.getOffsetValue();
                        n += a.getCategoryWidth() * 0.5;
                        m = { $type: Point_$type, x: n, y: m.y };
                    }
                    else if (a.dj) {
                        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.px(m);
                }
                this.tx(m, b, a);
            }
            else {
                let o = a.ps(l.d, this.tj, g);
                let p;
                let q = this.getEffectiveViewport1(this.b1);
                if (a.isVertical) {
                    let r = o.y;
                    let s = d.categoryAxis;
                    let t = this.tk;
                    if (j != 0) {
                        t = s.k3(this.b1.bv, this.b1.bu, q);
                    }
                    if (isNaN_(t) || isInfinity(t)) {
                        return;
                    }
                    p = new Rect(0, this.p7.left, r - t / 2, this.p7.width, t);
                }
                else {
                    let u = o.x;
                    let v = d.categoryAxis;
                    let w = this.tk;
                    if (j != 0) {
                        w = v.k3(this.b1.bv, this.b1.bu, q);
                    }
                    if (isNaN_(w) || isInfinity(w)) {
                        return;
                    }
                    p = new Rect(0, u - w / 2, this.p7.top, w, this.p7.height);
                }
                p.intersect(this.b1.bu);
                this.ty(p, b, a);
            }
        }
        tx(a, b, c) {
            let d = new ItemHighlightFrameRect();
            d.b = a.x;
            d.e = a.y;
            d.i = this.sy();
            if (this.ud != null) {
                d.i = this.ud;
            }
            d.j = this.sz();
            if (this.ue != null) {
                d.j = this.ue;
            }
            if (d.i == null) {
                if (c.hasMarkers) {
                    d.i = this.tb.ci(c.pc());
                }
                else {
                    d.i = this.tb.ci(c.o5);
                }
            }
            if (d.j == null) {
                if (c.hasMarkers) {
                    d.j = this.tb.ci(c.pd());
                }
                else {
                    d.j = this.tb.ci(c.o8);
                }
            }
            d.d = this.fy;
            d.f = Base.getHashCodeStatic(c);
            d.g = this.td(c, a);
            let e = (typeCast(MarkerSeries.$, c) !== null) ? c.q5 : null;
            if (e == null || e == MarkerSeries.q8 || (this.te != 2 && this.te != 0)) {
                let f = MarkerSeries.qm(c, 2);
                if (this.te != 2 && this.te != 0) {
                    f = this.te;
                }
                switch (f) {
                    case 3:
                    case 13:
                        e = this.ce.pm;
                        break;
                    case 4:
                        e = this.ce.pv;
                        break;
                    case 5:
                        e = this.ce.ps;
                        break;
                    case 6:
                        e = this.ce.pt;
                        break;
                    case 7:
                        e = this.ce.pn;
                        break;
                    case 8:
                        e = this.ce.pq;
                        break;
                    case 9:
                        e = this.ce.po;
                        break;
                    case 10:
                        e = this.ce.pu;
                        break;
                    case 11:
                        e = this.ce.pr;
                        break;
                    case 12:
                        e = this.ce.pp;
                        break;
                }
            }
            d.h = this.t2 != null ? this.t2 : e;
            if (!isNaN_(d.b) && !isNaN_(d.e)) {
                b.g.addItem(d.f, d);
            }
        }
        td(a, b) {
            let c = a.hy(b);
            let d = a.f9(b);
            if (this.tj && d != Math.floor(d)) {
                c = null;
            }
            return ((() => {
                let $ret = new DataContext();
                $ret.series = a;
                $ret.item = c;
                return $ret;
            })());
        }
        ty(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.sy();
            d.j = this.sz();
            if (d.i == null) {
                if (c != null) {
                    d.i = this.tb.cj(c.o5);
                }
            }
            if (d.j == null) {
                if (c != null) {
                    d.j = this.tb.cj(c.o8);
                }
            }
            d.d = this.fy;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        r8(a, b) {
            super.r8(a, b);
            let c = this.tb.b6;
            let d = this.tb.b5;
            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.t0(h, i);
                    f++;
                }
                else {
                    let j = c.item(e);
                    this.t1(h, j);
                    e++;
                }
            }
            c.count = e;
            d.count = f;
        }
        t0(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.ps(c, this.cw() || this.th, this.tg);
            if (isNaN_(e.x) || isNaN_(e.y)) {
                b._visibility = 1;
                return;
            }
            this.tb.cc(b, e.x, e.y);
            b.ah = a.h;
            b.content = a.g;
        }
        t1(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.tb.cd(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.pi != null) {
                b.ai = this.pi;
            }
            else {
                b.ai = null;
            }
            b.aj = this.pj;
            b.am = this.pl;
            b.al = this.pk;
            b.ak = this.pk;
            b.ac = this.gw;
        }
        ep() {
            return true;
        }
    }
    CategoryItemHighlightLayer.$t = markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    CategoryItemHighlightLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:tl:t3', [1, 10], 'HighlightType:tc:t4', [CategoryItemHighlightType_$type, enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerBrush:ud:t5', [Brush.$, null], 'MarkerOutline:ue:t6', [Brush.$, null], 'MarkerTemplate:t2:t7', [DataTemplate.$, null], 'MarkerType:te:t8', [MarkerType_$type, enumGetBox(MarkerType_$type, 2)], 'SkipUnknownValues:ti:t9', [0, true], 'TargetSeriesName:tt:ua', [2, null], 'TargetSeries:tf:ub', [Series.$, null], 'UseInterpolation:tj:uc', [0, false]]);
    return CategoryItemHighlightLayer;
})();
/**
 * @hidden
 */
export let CategoryItemHighlightLayerView = /*@__PURE__*/ (() => {
    class CategoryItemHighlightLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b4 = null;
            this.b6 = null;
            this.b5 = null;
            this.b7 = null;
            this.b8 = null;
            this.b4 = a;
            this.b7 = new List$1(ContentControl.$, 0);
            this.b8 = new List$1(Rectangle.$, 0);
        }
        as() {
            super.as();
            this.b6 = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.ck);
                $ret.activate = runOn(this, this.ce);
                $ret.disactivate = runOn(this, this.cg);
                $ret.destroy = runOn(this, this.cf);
                return $ret;
            })());
            this.b5 = ((() => {
                let $ret = new Pool$1(ContentControl.$);
                $ret.create = runOn(this, this.ch);
                $ret.activate = runOn(this, this.b9);
                $ret.disactivate = runOn(this, this.cb);
                $ret.destroy = runOn(this, this.ca);
                return $ret;
            })());
        }
        ck() {
            let a = new Rectangle();
            a.ab = false;
            this.b8.add(a);
            return a;
        }
        ce(a) {
            a._visibility = 0;
        }
        cg(a) {
            a._visibility = 1;
        }
        cf(a) {
            this.b8.remove(a);
        }
        ch() {
            let a = new Marker();
            this.b7.add(a);
            return a;
        }
        b9(a) {
            a._visibility = 0;
        }
        cb(a) {
            a._visibility = 1;
        }
        ca(a) {
            this.b7.remove(a);
        }
        ci(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, 0.3);
        }
        cj(a) {
            if (a != null) {
                let b = BrushUtil.l(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;
            }
        }
        cd(a, b, c, d, e) {
            a._visibility = 0;
            a.n = b;
            a.o = c;
            a.width = d;
            a.height = e;
        }
        cc(a, b, c) {
            a.n = b;
            a.o = c;
        }
        bh(a, b) {
            super.bh(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.pd();
                }
                d.thickness = e.f6();
            }
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b8.count; c++) {
                    let d = this.b8._inner[c];
                    if (d._visibility == 0) {
                        a.w(d);
                    }
                }
                if (this.b7.count > 0) {
                    let e = new DataTemplatePassInfo();
                    e.isHitTestRender = b;
                    e.context = a.h();
                    e.viewportTop = this.bu.top;
                    e.viewportLeft = this.bu.left;
                    e.viewportWidth = this.bu.width;
                    e.viewportHeight = this.bu.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.b7.count; m++) {
                        let n = this.b7._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.bg(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);
                        }
                    }
                }
            }
        }
        al(a) {
            super.al(a);
            for (let b = 0; b < this.b8.count; b++) {
                this.e.a9.exportRectangleData(a, this.b8._inner[b], "catItemRect", ["Main", "CategoryItem"]);
            }
            for (let c = 0; c < this.b7.count; c++) {
                this.e.a9.exportMarkerVisualDataFromMarker(this.e, a, this.b7._inner[c]);
            }
        }
    }
    CategoryItemHighlightLayerView.$t = markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
})();
