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