/*
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 * as tslib_1 from "tslib";
import { LegendBase } from "./LegendBase";
import { IChartScaleLegend_$type } from "igniteui-react-core/ES5/IChartScaleLegend";
import { TextBlock } from "igniteui-react-core/ES5/TextBlock";
import { LegendBaseView } from "./LegendBaseView";
import { typeCast, markType, runOn, Point_$type } from "igniteui-react-core/ES5/type";
import { Color } from "igniteui-react-core/ES5/Color";
import { Brush } from "igniteui-react-core/ES5/Brush";
import { ColorUtil } from "igniteui-react-core/ES5/ColorUtil";
import { Shape } from "igniteui-react-core/ES5/Shape";
import { GradientData } from "./GradientData";
import { Size } from "igniteui-react-core/ES5/Size";
import { Polygon } from "igniteui-react-core/ES5/Polygon";
import { GradientStopData } from "./GradientStopData";
import { IInternalLegendOwner_$type } from "igniteui-react-core/ES5/IInternalLegendOwner";
import { Rect } from "igniteui-react-core/ES5/Rect";
/**
 * @hidden
 */
var ScaleLegend = /** @class */ (function (_super) {
    tslib_1.__extends(ScaleLegend, _super);
    function ScaleLegend() {
        var _this = _super.call(this) || this;
        _this.bb = null;
        _this.bd = 0;
        _this.bc = 0;
        _this.a9 = null;
        _this.ab = ScaleLegend.$;
        return _this;
    }
    ScaleLegend.prototype.aj = function () {
        return new ScaleLegendView(this);
    };
    ScaleLegend.prototype.a6 = function (a) {
        _super.prototype.a6.call(this, a);
        this.bb = a;
    };
    Object.defineProperty(ScaleLegend.prototype, "legendScaleElement", {
        get: function () {
            return this.bb.a8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "minText", {
        get: function () {
            return this.bb.a4;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "maxText", {
        get: function () {
            return this.bb.a3;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "ba", {
        get: function () {
            return this.a9;
        },
        set: function (a) {
            this.a9 = a;
        },
        enumerable: true,
        configurable: true
    });
    ScaleLegend.prototype.bg = function () {
        this.bb.a0();
    };
    ScaleLegend.prototype.restoreOriginalState = function () {
        this.bg();
    };
    ScaleLegend.prototype.bj = function (a) {
        if (a == null) {
            return this.bb.a7();
        }
        return ColorUtil.m(a);
    };
    ScaleLegend.prototype.be = function (a) {
        this.ba = a;
        this.bf();
    };
    ScaleLegend.prototype.initializeLegend = function (a) {
        this.be(a);
    };
    ScaleLegend.prototype.get_isScale = function () {
        return true;
    };
    ScaleLegend.prototype.bf = function () {
        var _this = this;
        if (this.legendScaleElement == null || this.ba == null || !this.ba.legendReady) {
            return;
        }
        if (this.ba == null || !this.ba.isAttachedTo(this)) {
            return;
        }
        var a = false;
        var b = typeCast(Shape.$, this.legendScaleElement);
        if (b != null) {
            var c_1 = this.bb.au();
            if (!this.ba.forScaleColors(function (d, e) { return _this.bb.aw(c_1, _this.bj(d), e); })) {
                a = true;
            }
            this.bb.a1(b, a, c_1);
        }
        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]);
    return ScaleLegend;
}(LegendBase));
export { ScaleLegend };
/**
 * @hidden
 */
var ScaleLegendView = /** @class */ (function (_super) {
    tslib_1.__extends(ScaleLegendView, _super);
    function ScaleLegendView(a) {
        var _this = _super.call(this, a) || this;
        _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();
        return _this;
    }
    ScaleLegendView.prototype.a0 = function () {
    };
    ScaleLegendView.prototype.z = function () {
    };
    ScaleLegendView.prototype.a7 = function () {
        return Color.u(0, 0, 0, 0);
    };
    ScaleLegendView.prototype.au = function () {
        return new GradientData();
    };
    ScaleLegendView.prototype.aw = function (a, b, c) {
        var d = a;
        d.a.add(((function () {
            var $ret = new GradientStopData();
            $ret.b = ((function () {
                var $ret = new Brush();
                $ret.color = b;
                return $ret;
            })());
            $ret.a = c;
            return $ret;
        })()));
    };
    ScaleLegendView.prototype.a1 = function (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();
    };
    ScaleLegendView.prototype.ah = function (a) {
        _super.prototype.ah.call(this, a);
        this.ao = this.c.b(a);
        this.a9 = this.c.aa();
        this.ax();
    };
    ScaleLegendView.prototype.ax = function () {
        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);
            }
        }
    };
    ScaleLegendView.prototype.a2 = function () {
        if (this.ap) {
            this.ap = false;
            this.az();
        }
    };
    ScaleLegendView.prototype.az = function () {
        if (this.ao == null) {
            return;
        }
        this.ay();
    };
    ScaleLegendView.prototype.as = function (a) {
        var b = typeCast(TextBlock.$, a);
        if (b != null && b.ak != null) {
            return this.ao.e(b) + 0;
        }
        return 0;
    };
    ScaleLegendView.prototype.ar = function (a) {
        return this.aq + 0;
    };
    ScaleLegendView.prototype.ay = function () {
        if (this.an.ba == null || this.an.ba.container == null || (this.am == null && this.a5 == null)) {
            return;
        }
        if (this.ao.d) {
            var a = typeCast(IInternalLegendOwner_$type, this.an.ba.container);
            this.ao.ac(a.getFontInfo());
            this.aq = a.getFontHeight();
            this.a6 = a.getFontBrush();
            var b = this.as(this.a4);
            var c = this.as(this.a3);
            var d = Math.max(b, c) + 4;
            if (d >= this.a9.width) {
                d = 0;
            }
            var e = this.a9.width - d;
            var f = 2;
            var g = 2;
            e = e - 4;
            var h = this.a9.height - 4;
            var i = f + e + 4;
            var j = g;
            var k = h;
            var l = { $type: Point_$type, x: f + (3 / 5) * e, y: g };
            var m = { $type: Point_$type, x: f + (5 / 5) * e, y: g };
            var n = { $type: Point_$type, x: f + (5 / 5) * e, y: h };
            var o = { $type: Point_$type, x: f, y: h };
            var 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);
            }
        }
    };
    ScaleLegendView.prototype.aj = function () {
        _super.prototype.aj.call(this);
    };
    ScaleLegendView.$t = markType(ScaleLegendView, 'ScaleLegendView', LegendBaseView.$);
    return ScaleLegendView;
}(LegendBaseView));
export { ScaleLegendView };
