/*
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 { ScatterBase } from "./ScatterBase";
import { IScaleLegendSeries_$type } from "igniteui-react-core";
import { ISupportsSizeScale_$type } from "./ISupportsSizeScale";
import { ISupportsFillScale_$type } from "./ISupportsFillScale";
import { List$1 } from "igniteui-react-core";
import { UIElement } from "igniteui-react-core";
import { Base, typeCast, Point_$type, fromEnum, markType, markDep, enumGetBox, runOn } from "igniteui-react-core";
import { ActualRange } from "./ActualRange";
import { DependencyProperty } from "igniteui-react-core";
import { SizeScale } from "./SizeScale";
import { BrushScale } from "./BrushScale";
import { ScatterFrame } from "./ScatterFrame";
import { IChartLegend_$type } from "igniteui-react-core";
import { ValueBrushScale } from "./ValueBrushScale";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { ScatterBaseView } from "./ScatterBaseView";
import { ScalerParams } from "./ScalerParams";
import { OwnedPoint } from "./OwnedPoint";
import { Dictionary$2 } from "igniteui-react-core";
import { BubbleMarkerManager } from "./BubbleMarkerManager";
import { IChartItemLegend_$type } from "igniteui-react-core";
import { IChartScaleLegend_$type } from "igniteui-react-core";
import { ContentControl } from "igniteui-react-core";
import { DataContext } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, isInfinity, logBase } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
import { BrushSelectionMode_$type } from "./BrushSelectionMode";
import { ScatterTrendLineManager } from "./ScatterTrendLineManager";
/**
 * @hidden
 */
export let BubbleSeries = /*@__PURE__*/ (() => {
    class BubbleSeries extends ScatterBase {
        constructor() {
            super();
            this.qq = null;
            this.qp = null;
            this.pp = null;
            this.ph = null;
            this.pg = null;
            this.pf = null;
            this.ab = BubbleSeries.$;
            this.nm = new ScatterFrame();
            this.no = new ScatterFrame();
            this.nl = new ScatterFrame();
        }
        bf() {
            return new BubbleSeriesView(this);
        }
        i2(a) {
            super.i2(a);
            this.pd = a;
        }
        isAttachedTo(a) {
            return this.aw == a;
        }
        ci() {
            return true;
        }
        ie(a) {
            super.ie(a);
            if (this.pk != null && this.pp != null && this.pp.count > 0) {
                for (let b = 0; b < this.pp.count; b++) {
                    a(this.pp._inner[b]);
                }
            }
        }
        get pj() {
            return this.pl;
        }
        qo(a) {
            let b = typeCast(CustomPaletteBrushScale.$, this.pc);
            let c = typeCast(ValueBrushScale.$, this.pc);
            let d = this.pc;
            if (b != null && this.bz != null) {
                return b.getBrush1(a, this.bz.count);
            }
            else if (c != null) {
                return c.getBrushByIndex(a, this.pi);
            }
            else if (d != null) {
                return d.getBrush(a);
            }
            return null;
        }
        get legendReady() {
            return this.pl != null && this.pl.count != 0;
        }
        get minScaleText() {
            let a = this.pb(this.pe).b;
            return (Math.round(a * 1000) / 1000).toString();
        }
        get maxScaleText() {
            let a = this.pb(this.pe).a;
            return (Math.round(a * 1000) / 1000).toString();
        }
        forScaleColors(a) {
            for (let b = 0; b < this.pl.count; b++) {
                if (this.pc == null || !this.pc.isReady) {
                    return false;
                }
                let c = NaN;
                if (this.pi != null) {
                    c = (this.pi.item(b) - this.pi.minimum) / (this.pi.maximum - this.pi.minimum);
                }
                let d = (this.pl.item(b) - this.pl.minimum) / (this.pl.maximum - this.pl.minimum);
                if (isNaN_(c)) {
                    c = 0;
                }
                if (isNaN_(d)) {
                    d = c;
                }
                let e = this.m8;
                let f = this.qo(b);
                let g = f != null ? f : e;
                a(g, d);
            }
            return true;
        }
        fs(a, b) {
            let c = this.g2(b);
            if (c == BubbleSeries.$$p[3]) {
                return this.ft(a, b, this.p0);
            }
            if (c == BubbleSeries.$$p[7]) {
                return this.ft(a, b, this.p6);
            }
            if (c == ScatterBase.$$p[4]) {
                return this.ft(a, b, this.n4);
            }
            if (c == ScatterBase.$$p[6]) {
                return this.ft(a, b, this.n8);
            }
            if (c == BubbleSeries.$$p[0]) {
                return this.ft(a, b, this.pv);
            }
            return super.fs(a, b);
        }
        get pl() {
            return this.ph;
        }
        set pl(a) {
            if (this.ph != a) {
                let b = this.pl;
                this.ph = a;
                this.raisePropertyChanged("RadiusColumn", b, this.pl);
            }
        }
        get pk() {
            return this.pg;
        }
        set pk(a) {
            if (this.pg != a) {
                let b = this.pk;
                this.pg = a;
                this.raisePropertyChanged("LabelColumn", b, this.pk);
            }
        }
        get pi() {
            return this.pf;
        }
        set pi(a) {
            if (this.pf != a) {
                let b = this.pi;
                this.pf = a;
                this.raisePropertyChanged("FillColumn", b, this.pi);
            }
        }
        ob(a, b, c, d, e) {
            if (c <= this.nx) {
                b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
            }
            let f = this.nx;
            let g = this.bz;
            let h;
            let i;
            let j = this.getEffectiveViewport1(a);
            let k = new ScalerParams(0, d, e, this.nh.d, j);
            let l = new ScalerParams(0, d, e, this.nh.e, j);
            let m = false;
            let n = 0;
            if (this.bs != null) {
                if (this.bs.d1()) {
                    let o = this.bs.h4(d, k);
                    m = o.c;
                    n = o.d;
                }
            }
            for (let p = 0; p < c; p++) {
                h = this.nq.item(p);
                i = this.ns.item(p);
                let q = { $type: Point_$type, x: this.nh.a.dy(h, k), y: this.nh.b.dy(i, l) };
                if (m) {
                    if (q.x < e.left || q.x > e.right) {
                        if (q.x + n >= e.left && q.x + n <= e.right) {
                            q = { $type: Point_$type, x: q.x + n, y: i };
                        }
                    }
                }
                if (!isInfinity(q.x) && !isInfinity(q.y)) {
                    let r = g.item(p);
                    if (c <= f) {
                        if (!b.g.containsKey(r)) {
                            let s = { $type: Point_$type, x: h, y: i };
                            b.g.addItem(r, ((() => {
                                let $ret = new OwnedPoint();
                                $ret.a = r;
                                $ret.b = s;
                                $ret.c = q;
                                return $ret;
                            })()));
                        }
                    }
                }
            }
        }
        of(a, b) {
            let c = typeCast(BubbleSeriesView.$, b);
            let d = c.cr;
            d.m = this.pl;
            super.of(a, b);
            let e = Math.min(this.nq != null ? this.nq.count : 0, this.ns != null ? this.ns.count : 0);
            if (e < 1) {
                return;
            }
            c.dc();
            c.dd();
        }
        qb() {
            if (this.bs == null) {
                return;
            }
            if (this.aw == null) {
                return;
            }
            if (this.aw.isItemwise) {
                let a = this.aw;
                this.aw.clearLegendItemsForSeries(this);
                this.qa();
                a.renderItemwiseContent(this);
            }
            if (this.aw.isScale) {
                let b = this.aw;
                b.restoreOriginalState();
                b.initializeLegend(this);
            }
        }
        static pq(a, b, c, d, e) {
            if (e <= a || isNaN_(e) || isInfinity(e)) {
                return c;
            }
            if (e >= b) {
                return d;
            }
            let f = c + ((d - c) / (b - a)) * (e - a);
            return f;
        }
        static pr(a, b, c, d, logBase_, e) {
            let f = logBase(e, logBase_);
            let g = logBase(a, logBase_);
            let h = logBase(b, logBase_);
            return BubbleSeries.pq(g, h, c, d, f);
        }
        dw(a, b, c) {
            let d = super.dw(a, b, c);
            if (this.pl == null || this.bz == null || this.pl.count == 0 || this.bz.count != this.pl.count) {
                d = false;
            }
            return d;
        }
        nv(a, b) {
            if (b != 3) {
                return true;
            }
            if (a == null) {
                return true;
            }
            if (this.n4 == a || this.n8 == a || this.p6 == a) {
                return true;
            }
            return false;
        }
        qa() {
            let a = typeCast(IChartLegend_$type, this.aw);
            if (a == null || this.bz == null) {
                return;
            }
            this.pp = new List$1(UIElement.$, 0);
            let b = typeCast(CustomPaletteBrushScale.$, this.pc);
            let c = typeCast(ValueBrushScale.$, this.pc);
            let d = this.pc;
            let e = this.pa();
            let f = e.b;
            let g = e.a;
            let h = this.bz;
            for (let i = 0; i < h.count; i++) {
                let j = null;
                if (c != null && this.pi != null) {
                    let k = this.pi.item(i);
                    j = c.getBrushByRange(k, f, g);
                }
                else if (b != null) {
                    j = b.getBrush1(i, h.count);
                }
                else if (d != null) {
                    j = d.getBrush(i);
                }
                let l = new ContentControl();
                let m = this.pk != null && this.pk.item(i) != null ? this.pk.item(i).toString() : "";
                l.content = ((() => {
                    let $ret = new DataContext();
                    $ret.series = this;
                    $ret.item = h.item(i);
                    $ret.itemBrush = j;
                    $ret.itemLabel = m;
                    return $ret;
                })());
                let n = this.j6;
                if (n == null) {
                    n = this.bi.bi(this.bk);
                }
                l.ah = n;
                this.pp.add(l);
            }
        }
        h6(a, b, c, d) {
            super.h6(a, b, c, d);
            if (this.pe != null) {
                this.pe.aa();
            }
            if (this.pc != null) {
                this.pc.w();
            }
            this.qb();
        }
        im() {
            super.im();
            this.qb();
        }
        is() {
            super.is();
            this.qb();
        }
        i7(a, b, c, d) {
            super.i7(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    if (this.pe != null) {
                        this.pe.aa();
                    }
                    if (this.pc != null) {
                        this.pc.w();
                    }
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.pl);
                        c.deregisterColumn(this.pi);
                        c.deregisterColumn(this.pk);
                        this.pl = null;
                        this.pi = null;
                        this.pk = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.pl = this.bw(this.p6);
                        if (!stringIsNullOrEmpty(this.pv)) {
                            this.pi = this.bw(this.pv);
                        }
                        this.pk = this.by(this.p0);
                    }
                    this.jl(false);
                    this.qb();
                    break;
                case BubbleSeries.$$p[7]:
                    if (this.pe != null) {
                        this.pe.aa();
                    }
                    if (this.bz != null) {
                        this.bz.deregisterColumn(this.pl);
                        this.pl = this.bw(this.p6);
                        this.qb();
                    }
                    break;
                case "RadiusColumn":
                    if (this.pe != null) {
                        this.pe.aa();
                    }
                    this.ni.ct.g$i();
                    this.jl(false);
                    this.iu();
                    break;
                case BubbleSeries.$$p[8]:
                    if (c != null) {
                        c.l.remove(this);
                        c.aa();
                    }
                    if (d != null) {
                        d.l.add(this);
                        d.aa();
                    }
                    this.jl(false);
                    this.it();
                    break;
                case BubbleSeries.$$p[9]:
                    this.jl(false);
                    this.it();
                    break;
                case "DiscreteLegendItemTemplate":
                    this.qb();
                    break;
                case BubbleSeries.$$p[1]:
                    if (c != null) {
                        c.o.remove(this);
                        c.w();
                    }
                    if (d != null) {
                        d.o.add(this);
                        d.w();
                    }
                    this.jl(false);
                    this.qb();
                    this.it();
                    break;
                case BubbleSeries.$$p[2]:
                case BubbleSeries.$$p[6]:
                case BubbleSeries.$$p[5]:
                case BubbleSeries.$$p[4]:
                    this.jl(false);
                    this.qb();
                    this.it();
                    break;
                case "FillColumn":
                    this.jl(false);
                    this.it();
                    break;
                case BubbleSeries.$$p[0]:
                    if (this.pc != null) {
                        this.pc.w();
                    }
                    if (this.bz != null) {
                        this.bz.deregisterColumn(this.pi);
                        this.pi = this.bw(this.pv);
                        this.qb();
                    }
                    break;
                case BubbleSeries.$$p[3]:
                    if (this.bz != null) {
                        this.bz.deregisterColumn(this.pk);
                        this.pk = this.by(this.p0);
                        this.qb();
                    }
                    break;
                case "ActualLegend":
                    let e = typeCast(IChartLegend_$type, c);
                    if (e != null && e.isItemwise) {
                        let f = typeCast(IChartItemLegend_$type, e);
                        f.clearLegendItemsForSeries(this);
                    }
                    if (e != null && e.isScale) {
                        let g = typeCast(IChartScaleLegend_$type, e);
                        let h = true;
                        let i = null;
                        if (this.bs != null) {
                            for (let j of fromEnum(this.bs.series)) {
                                if (j.legend == g) {
                                    i = j;
                                    h = false;
                                }
                            }
                        }
                        if (h) {
                            g.restoreOriginalState();
                        }
                        else {
                            g.initializeLegend(typeCast(IScaleLegendSeries_$type, i));
                        }
                    }
                    this.qb();
                    break;
                case "SeriesViewer":
                    this.qb();
                    break;
            }
        }
        updateSizeScaleGlobals() {
            let a = new ActualRange();
            a.b = NaN;
            a.a = NaN;
            if (this.pl != null) {
                a.b = this.pl.minimum;
                a.a = this.pl.maximum;
            }
            if (this.pe != null) {
                this.pe.ab(a.b, a.a);
            }
        }
        updateFillScaleGlobals() {
            let a = new ActualRange();
            a.b = NaN;
            a.a = NaN;
            if (this.pi != null) {
                a.b = this.pi.minimum;
                a.a = this.pi.maximum;
            }
            if (this.pc != null) {
                this.pc.y(a.b, a.a);
            }
        }
        pb(a) {
            let b = new ActualRange();
            b.b = NaN;
            b.a = NaN;
            if (this.pl != null) {
                b.b = this.pl.minimum;
                b.a = this.pl.maximum;
            }
            if (a != null) {
                a.x();
                if (this.po) {
                    b.b = a.globalMinimum;
                    b.a = a.globalMaximum;
                }
            }
            return b;
        }
        pa() {
            let a = new ActualRange();
            a.b = NaN;
            a.a = NaN;
            if (this.pi != null) {
                a.b = this.pi.minimum;
                a.a = this.pi.maximum;
            }
            let b = typeCast(ValueBrushScale.$, this.pc);
            if (b != null) {
                b.s();
                if (this.pm && this.pc.o.count > 1) {
                    a.b = b.q;
                    a.a = b.p;
                }
            }
            return a;
        }
        qd(a, b, c, d) {
            let e = c.width;
            if (!this.bi.br.isEmpty) {
                e = this.bi.br.width;
            }
            else if (this.bs != null && !this.bs.oh.isEmpty) {
                e = this.bs.oh.width;
            }
            let f = DeviceUtils.c(e);
            let g = this.pe || ((() => {
                let $ret = new SizeScale();
                $ret.minimumValue = f / 10;
                $ret.maximumValue = f / 5;
                return $ret;
            })());
            if (g != null) {
                let h = g.minimumValue;
                let i = g.maximumValue;
                let j = g.logarithmBase;
                let k = this.pb(g);
                let l = k.b;
                let m = k.a;
                if (g.isLogarithmic) {
                    for (let n = 0; n < b.count; n++) {
                        b._inner[n] = BubbleSeries.pr(l, m, h, i, j, b._inner[n]);
                    }
                }
                else {
                    for (let o = 0; o < b.count; o++) {
                        b._inner[o] = BubbleSeries.pq(l, m, h, i, b._inner[o]);
                    }
                }
            }
            let p = 1;
            p = DeviceUtils.d();
            let q = this.pe == null;
            if (d) {
                let r = c.width / e;
                for (let s = 0; s < b.count; s++) {
                    if (q) {
                        b._inner[s] = b._inner[s] / p;
                    }
                    b._inner[s] = b._inner[s] * r;
                }
            }
            for (let t = 0; t < a.count; t++) {
                let u = a._inner[t];
                if (q && !d) {
                    u.width = Math.max(0, b._inner[t] / p);
                    u.height = Math.max(0, b._inner[t] / p);
                }
                else {
                    u.width = Math.max(0, b._inner[t]);
                    u.height = Math.max(0, b._inner[t]);
                }
            }
        }
        qc(a) {
            let b = typeCast(BubbleSeriesView.$, this.bh);
            this.pd.b0 = false;
            if (b != null) {
                b.b0 = false;
            }
            let c = typeCast(CustomPaletteBrushScale.$, this.pc);
            let d = typeCast(ValueBrushScale.$, this.pc);
            let e = this.pc;
            let f = this.pa();
            let g = f.b;
            let h = f.a;
            let i = this.pc == null || !this.pc.isReady || (d != null && this.pv == null);
            if (i) {
                this.pd.db();
                if (b != null) {
                    b.db();
                }
                return;
            }
            this.pd.b0 = true;
            if (b != null) {
                b.b0 = true;
            }
            let j = a.count;
            let k = this.bz;
            for (let l = 0; l < j; l++) {
                let m = a._inner[l];
                let n = typeCast(DataContext.$, m.content);
                if (n != null) {
                    let o = null;
                    let p = k.indexOf(n.item);
                    if (c != null) {
                        o = c.getBrush1(p, k.count);
                    }
                    else if (d != null && this.pi != null) {
                        let q = this.pi.item(p);
                        o = d.getBrushByRange(q, g, h);
                    }
                    else if (e != null) {
                        o = e.getBrush(p);
                    }
                    else {
                        if (this.na == null) {
                            o = this.m8;
                        }
                        else {
                            o = this.na;
                        }
                    }
                    let r = null;
                    if (this.nb == null) {
                        r = this.m9;
                    }
                    else {
                        r = this.nb;
                    }
                    if (this.pn && o != null) {
                        r = o;
                    }
                    if (r != null && !isNaN_(this.pt)) {
                        r = BrushUtil.l(r, this.pt);
                    }
                    if (o != null && !isNaN_(this.ps)) {
                        o = BrushUtil.l(o, this.ps);
                    }
                    n.itemBrush = o;
                    n.actualItemBrush = o;
                    n.outline = r;
                }
            }
        }
        get_cy() {
            return false;
        }
        get actualMarkerBrush() {
            return this.m8;
        }
    }
    BubbleSeries.$t = /*@__PURE__*/ markType(BubbleSeries, 'BubbleSeries', ScatterBase.$, [IScaleLegendSeries_$type, ISupportsSizeScale_$type, ISupportsFillScale_$type]);
    BubbleSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, BubbleSeries, 'raisePropertyChanged', ['FillMemberPath:pv:qe', [2], 'FillScale:pc:qf', [BrushScale.$], 'FillScaleUseGlobalValues:pm:qg', [0, false], 'LabelMemberPath:p0:qh', [2], 'MarkerBrushBrightness:ps:qi', [1, NaN], 'MarkerOutlineBrightness:pt:qj', [1, NaN], 'MarkerOutlineUsesFillScale:pn:qk', [0, false], 'RadiusMemberPath:p6:ql', [2, null], 'RadiusScale:pe:qm', [SizeScale.$], 'RadiusScaleUseGlobalValues:po:qn', [0, false]]);
    return BubbleSeries;
})();
/**
 * @hidden
 */
export let CustomPaletteBrushScale = /*@__PURE__*/ (() => {
    class CustomPaletteBrushScale extends BrushScale {
        constructor() {
            super();
        }
        getBrush1(a, b) {
            if (this.brushes == null || this.brushes.count == 0) {
                return null;
            }
            if (this.brushSelectionMode == 0) {
                return super.getBrush(a % this.brushes.count);
            }
            let c = BubbleSeries.pq(0, b - 1, 0, this.brushes.count - 1, a);
            return this.aa(c);
        }
        get_isReady() {
            return this.brushes != null && this.brushes.count > 0;
        }
    }
    CustomPaletteBrushScale.$t = /*@__PURE__*/ markType(CustomPaletteBrushScale, 'CustomPaletteBrushScale', BrushScale.$);
    CustomPaletteBrushScale.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CustomPaletteBrushScale, 'u', ['BrushSelectionMode', [BrushSelectionMode_$type, /*@__PURE__*/ enumGetBox(BrushSelectionMode_$type, 0)]]);
    return CustomPaletteBrushScale;
})();
/**
 * @hidden
 */
export let BubbleSeriesView = /*@__PURE__*/ (() => {
    class BubbleSeriesView extends ScatterBaseView {
        constructor(a) {
            super(a);
            this.da = null;
            this.da = a;
            this.ct = new ScatterTrendLineManager();
        }
        ap() {
            super.ap();
            if (!this.n) {
                this.by.mb = 2;
                this.e.bj = 4;
            }
        }
        cq() {
            return new BubbleMarkerManager((a) => this.cu.item(a), (a) => this.cs.nh.c.item(a), runOn(this, this.c4), runOn(this, this.cn), runOn(this, this.cv));
        }
        dc() {
            let a = this.cr;
            this.da.qd(a.n, a.o, this.br, this == this.e.bh);
            this.an();
        }
        dd() {
            let a = this.cr;
            this.da.qc(a.n);
        }
        db() {
            let a = this.cr;
            for (let b of fromEnum(a.n)) {
                let c = typeCast(DataContext.$, b.content);
                if (c != null) {
                    c.itemBrush = null;
                    c.outline = null;
                }
            }
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'><span";
            let b = this.e.a0.a$q(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.da.fx + "</span><br/><span>" + "(${item." + this.da.n4 + "}, ${item." + this.da.n8 + "})</span>";
            if (!stringIsNullOrEmpty(this.da.p6)) {
                a += "<span>, Radius: ${item." + this.da.p6 + "}</span>";
            }
            a += "</div>";
            return a;
        }
    }
    BubbleSeriesView.$t = /*@__PURE__*/ markType(BubbleSeriesView, 'BubbleSeriesView', ScatterBaseView.$);
    return BubbleSeriesView;
})();
//# sourceMappingURL=BubbleSeries_combined.js.map
