/*
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.ba;
        }
        get minText() {
            return this.bd.a6;
        }
        get maxText() {
            return this.bd.a5;
        }
        get bc() {
            return this.bb;
        }
        set bc(a) {
            this.bb = a;
        }
        bi() {
            this.bd.a2();
        }
        restoreOriginalState() {
            this.bi();
        }
        bl(a) {
            if (a == null) {
                return this.bd.a9();
            }
            return ColorUtil.t(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.aw();
                if (!this.bc.forScaleColors((d, e) => this.bd.ay(c, this.bl(d), e))) {
                    a = true;
                }
                this.bd.a3(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.ap = null;
            this.ba = null;
            this.a6 = null;
            this.a5 = null;
            this.ao = null;
            this.aq = null;
            this.bb = new Size();
            this.ar = false;
            this.as = 0;
            this.a8 = null;
            this.a7 = null;
            this.ap = a;
            this.a6 = new TextBlock();
            this.a5 = new TextBlock();
            this.ba = new Polygon();
        }
        a2() {
        }
        z() {
        }
        a9() {
            return Color.u(0, 0, 0, 0);
        }
        aw() {
            return new GradientData();
        }
        ay(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;
            })()));
        }
        a3(a, b, c) {
            if (b) {
                this.a7 = this.ap.bc.actualMarkerBrush;
                this.ao = null;
            }
            else {
                this.a7 = null;
                this.ao = c;
                this.ao.b();
            }
            this.az();
        }
        ai(a) {
            super.ai(a);
            this.aq = this.c.b(a);
            this.bb = this.c.ab();
            this.az();
        }
        az() {
            if (!this.ar) {
                this.ar = true;
                if (this.c.g != null) {
                    this.c.g.setTimeout(runOn(this, this.a4), 0);
                }
                else {
                    window.setTimeout(runOn(this, this.a4), 0);
                }
            }
        }
        a4() {
            if (this.ar) {
                this.ar = false;
                this.a1();
            }
        }
        a1() {
            if (this.aq == null) {
                return;
            }
            this.a0();
        }
        au(a) {
            let b = typeCast(TextBlock.$, a);
            if (b != null && b.al != null) {
                return this.aq.f(b) + 0;
            }
            return 0;
        }
        at(a) {
            return this.as + 0;
        }
        a0() {
            if (this.ap.bc == null || this.ap.bc.container == null || (this.ao == null && this.a7 == null)) {
                return;
            }
            if (this.aq.d) {
                let a = typeCast(IInternalLegendOwner_$type, this.ap.bc.container);
                this.aq.ad(a.getFontInfo());
                this.as = a.getFontHeight();
                this.a8 = a.getFontBrush();
                let b = this.au(this.a6);
                let c = this.au(this.a5);
                let d = Math.max(b, c) + 4;
                if (d >= this.bb.width) {
                    d = 0;
                }
                let e = this.bb.width - d;
                let f = 2;
                let g = 2;
                e = e - 4;
                let h = this.bb.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.ba;
                p.an.clear();
                p.an.add(l);
                p.an.add(m);
                p.an.add(n);
                p.an.add(o);
                this.a6.n = i;
                this.a6.o = j;
                this.a6.ao = this.a8;
                this.a5.n = i;
                this.a5.o = j + k - (this.at(this.a6));
                this.a5.ao = this.a8;
                if (!this.aq.e) {
                    this.aq.l(0, 0, this.bb.width, this.bb.height);
                }
                if (this.ao == null && this.a7 != null) {
                    p._fill = this.a7;
                    this.aq.u(p);
                }
                else {
                    this.c.y(this.aq, p, this.ao, new Rect(0, g, f, e, h));
                }
                if (d > 0) {
                    this.aq.x(this.a6);
                    this.aq.x(this.a5);
                }
            }
        }
        al() {
            super.al();
        }
    }
    ScaleLegendView.$t = markType(ScaleLegendView, 'ScaleLegendView', LegendBaseView.$);
    return ScaleLegendView;
})();
