/*
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";
/**
 * @hidden
 */
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);
    }
    a6(a) {
        super.a6(a);
        this.bb = a;
    }
    get legendScaleElement() {
        return this.bb.a8;
    }
    get minText() {
        return this.bb.a4;
    }
    get maxText() {
        return this.bb.a3;
    }
    get ba() {
        return this.a9;
    }
    set ba(a) {
        this.a9 = a;
    }
    bg() {
        this.bb.a0();
    }
    restoreOriginalState() {
        this.bg();
    }
    bj(a) {
        if (a == null) {
            return this.bb.a7();
        }
        return ColorUtil.m(a);
    }
    be(a) {
        this.ba = a;
        this.bf();
    }
    initializeLegend(a) {
        this.be(a);
    }
    get_isScale() {
        return true;
    }
    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.au();
            if (!this.ba.forScaleColors((d, e) => this.bb.aw(c, this.bj(d), e))) {
                a = true;
            }
            this.bb.a1(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]);
/**
 * @hidden
 */
export class ScaleLegendView extends LegendBaseView {
    constructor(a) {
        super(a);
        this.an = null;
        this.a8 = null;
        this.a4 = null;
        this.a3 = null;
        this.am = null;
        this.ao = null;
        this.a9 = new Size();
        this.ap = false;
        this.aq = 0;
        this.a6 = null;
        this.a5 = null;
        this.an = a;
        this.a4 = new TextBlock();
        this.a3 = new TextBlock();
        this.a8 = new Polygon();
    }
    a0() {
    }
    z() {
    }
    a7() {
        return Color.u(0, 0, 0, 0);
    }
    au() {
        return new GradientData();
    }
    aw(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;
        })()));
    }
    a1(a, b, c) {
        if (b) {
            this.a5 = this.an.ba.actualMarkerBrush;
            this.am = null;
        }
        else {
            this.a5 = null;
            this.am = c;
            this.am.b();
        }
        this.ax();
    }
    ah(a) {
        super.ah(a);
        this.ao = this.c.b(a);
        this.a9 = this.c.aa();
        this.ax();
    }
    ax() {
        if (!this.ap) {
            this.ap = true;
            if (this.c.h != null) {
                this.c.h.setTimeout(runOn(this, this.a2), 0);
            }
            else {
                window.setTimeout(runOn(this, this.a2), 0);
            }
        }
    }
    a2() {
        if (this.ap) {
            this.ap = false;
            this.az();
        }
    }
    az() {
        if (this.ao == null) {
            return;
        }
        this.ay();
    }
    as(a) {
        let b = typeCast(TextBlock.$, a);
        if (b != null && b.ak != null) {
            return this.ao.e(b) + 0;
        }
        return 0;
    }
    ar(a) {
        return this.aq + 0;
    }
    ay() {
        if (this.an.ba == null || this.an.ba.container == null || (this.am == null && this.a5 == null)) {
            return;
        }
        if (this.ao.d) {
            let a = typeCast(IInternalLegendOwner_$type, this.an.ba.container);
            this.ao.ac(a.getFontInfo());
            this.aq = a.getFontHeight();
            this.a6 = a.getFontBrush();
            let b = this.as(this.a4);
            let c = this.as(this.a3);
            let d = Math.max(b, c) + 4;
            if (d >= this.a9.width) {
                d = 0;
            }
            let e = this.a9.width - d;
            let f = 2;
            let g = 2;
            e = e - 4;
            let h = this.a9.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.a8;
            p.aj.clear();
            p.aj.add(l);
            p.aj.add(m);
            p.aj.add(n);
            p.aj.add(o);
            this.a4.n = i;
            this.a4.o = j;
            this.a4.am = this.a6;
            this.a3.n = i;
            this.a3.o = j + k - (this.ar(this.a4));
            this.a3.am = this.a6;
            this.ao.k(0, 0, this.a9.width, this.a9.height);
            if (this.am == null && this.a5 != null) {
                p._fill = this.a5;
                this.ao.t(p);
            }
            else {
                this.c.x(this.ao, p, this.am, new Rect(0, g, f, e, h));
            }
            if (d > 0) {
                this.ao.w(this.a4);
                this.ao.w(this.a3);
            }
        }
    }
    aj() {
        super.aj();
    }
}
ScaleLegendView.$t = markType(ScaleLegendView, 'ScaleLegendView', LegendBaseView.$);
