/*
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 { LegendBase } from "./LegendBase";
import { IChartScaleLegend_$type } from "igniteui-angular-core";
import { TextBlock } from "igniteui-angular-core";
import { LegendBaseView } from "./LegendBaseView";
import { typeCast, markType, runOn, Point_$type } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { Brush } from "igniteui-angular-core";
import { ColorUtil } from "igniteui-angular-core";
import { Shape } from "igniteui-angular-core";
import { GradientData } from "./GradientData";
import { Size } from "igniteui-angular-core";
import { Polygon } from "igniteui-angular-core";
import { GradientStopData } from "./GradientStopData";
import { IInternalLegendOwner_$type } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
/**
 * @hidden
 */
export let ScaleLegend = /*@__PURE__*/ (() => {
    class ScaleLegend extends LegendBase {
        constructor() {
            super();
            this.bd = null;
            this.bf = 0;
            this.be = 0;
            this.bb = null;
            this.ab = ScaleLegend.$;
        }
        aj() {
            return new ScaleLegendView(this);
        }
        a8(a) {
            super.a8(a);
            this.bd = a;
        }
        get legendScaleElement() {
            return this.bd.bb;
        }
        get minText() {
            return this.bd.a7;
        }
        get maxText() {
            return this.bd.a6;
        }
        get bc() {
            return this.bb;
        }
        set bc(a) {
            this.bb = a;
        }
        bi() {
            this.bd.a3();
        }
        restoreOriginalState() {
            this.bi();
        }
        bl(a) {
            if (a == null) {
                return this.bd.ba();
            }
            return ColorUtil.w(a);
        }
        bg(a) {
            this.bc = a;
            this.bh();
        }
        initializeLegend(a) {
            this.bg(a);
        }
        get_isScale() {
            return true;
        }
        bh() {
            if (this.legendScaleElement == null || this.bc == null || !this.bc.legendReady) {
                return;
            }
            if (this.bc == null || !this.bc.isAttachedTo(this)) {
                return;
            }
            let a = false;
            let b = typeCast(Shape.$, this.legendScaleElement);
            if (b != null) {
                let c = this.bd.ax();
                if (!this.bc.forScaleColors((d, e) => this.bd.az(c, this.bl(d), e))) {
                    a = true;
                }
                this.bd.a4(b, a, c);
            }
            if (this.minText != null) {
                this.minText.al = this.bc.minScaleText;
            }
            if (this.maxText != null) {
                this.maxText.al = this.bc.maxScaleText;
            }
        }
    }
    ScaleLegend.$t = markType(ScaleLegend, 'ScaleLegend', LegendBase.$, [IChartScaleLegend_$type]);
    return ScaleLegend;
})();
/**
 * @hidden
 */
export let ScaleLegendView = /*@__PURE__*/ (() => {
    class ScaleLegendView extends LegendBaseView {
        constructor(a) {
            super(a);
            this.aq = null;
            this.bb = null;
            this.a7 = null;
            this.a6 = null;
            this.ap = null;
            this.ar = null;
            this.bc = new Size();
            this.as = false;
            this.at = 0;
            this.a9 = null;
            this.a8 = null;
            this.aq = a;
            this.a7 = new TextBlock();
            this.a6 = new TextBlock();
            this.bb = new Polygon();
        }
        a3() {
        }
        aa() {
        }
        ba() {
            return Color.u(0, 0, 0, 0);
        }
        ax() {
            return new GradientData();
        }
        az(a, b, c) {
            let d = a;
            d.a.add(((() => {
                let $ret = new GradientStopData();
                $ret.b = ((() => {
                    let $ret = new Brush();
                    $ret.color = b;
                    return $ret;
                })());
                $ret.a = c;
                return $ret;
            })()));
        }
        a4(a, b, c) {
            if (b) {
                this.a8 = this.aq.bc.actualMarkerBrush;
                this.ap = null;
            }
            else {
                this.a8 = null;
                this.ap = c;
                this.ap.b();
            }
            this.a0();
        }
        aj(a) {
            super.aj(a);
            this.ar = this.d.b(a);
            this.bc = this.d.ab();
            this.a0();
        }
        a0() {
            if (!this.as) {
                this.as = true;
                if (this.d.g != null) {
                    this.d.g.setTimeout(runOn(this, this.a5), 0);
                }
                else {
                    window.setTimeout(runOn(this, this.a5), 0);
                }
            }
        }
        a5() {
            if (this.as) {
                this.as = false;
                this.a2();
            }
        }
        a2() {
            if (this.ar == null) {
                return;
            }
            this.a1();
        }
        av(a) {
            let b = typeCast(TextBlock.$, a);
            if (b != null && b.al != null) {
                return this.ar.f(b) + 0;
            }
            return 0;
        }
        au(a) {
            return this.at + 0;
        }
        a1() {
            if (this.aq.bc == null || this.aq.bc.container == null || (this.ap == null && this.a8 == null)) {
                return;
            }
            if (this.ar.d) {
                let a = typeCast(IInternalLegendOwner_$type, this.aq.bc.container);
                this.ar.ad(a.getFontInfo());
                this.at = a.getFontHeight();
                this.a9 = a.getFontBrush();
                let b = this.av(this.a7);
                let c = this.av(this.a6);
                let d = Math.max(b, c) + 4;
                if (d >= this.bc.width) {
                    d = 0;
                }
                let e = this.bc.width - d;
                let f = 2;
                let g = 2;
                e = e - 4;
                let h = this.bc.height - 4;
                let i = f + e + 4;
                let j = g;
                let k = h;
                let l = { $type: Point_$type, x: f + (3 / 5) * e, y: g };
                let m = { $type: Point_$type, x: f + (5 / 5) * e, y: g };
                let n = { $type: Point_$type, x: f + (5 / 5) * e, y: h };
                let o = { $type: Point_$type, x: f, y: h };
                let p = this.bb;
                p.an.clear();
                p.an.add(l);
                p.an.add(m);
                p.an.add(n);
                p.an.add(o);
                this.a7.n = i;
                this.a7.o = j;
                this.a7.ao = this.a9;
                this.a6.n = i;
                this.a6.o = j + k - (this.au(this.a7));
                this.a6.ao = this.a9;
                if (!this.ar.e) {
                    this.ar.l(0, 0, this.bc.width, this.bc.height);
                }
                if (this.ap == null && this.a8 != null) {
                    p._fill = this.a8;
                    this.ar.u(p);
                }
                else {
                    this.d.y(this.ar, p, this.ap, new Rect(0, g, f, e, h));
                }
                if (d > 0) {
                    this.ar.x(this.a7);
                    this.ar.x(this.a6);
                }
            }
        }
        am() {
            super.am();
        }
    }
    ScaleLegendView.$t = markType(ScaleLegendView, 'ScaleLegendView', LegendBaseView.$);
    return ScaleLegendView;
})();
