/*
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";
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.a5 = function (a) {
        _super.prototype.a5.call(this, a);
        this.bb = a;
    };
    Object.defineProperty(ScaleLegend.prototype, "legendScaleElement", {
        get: function () {
            return this.bb.a3;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "minText", {
        get: function () {
            return this.bb.az;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "maxText", {
        get: function () {
            return this.bb.ay;
        },
        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.av();
    };
    ScaleLegend.prototype.restoreOriginalState = function () {
        this.bg();
    };
    ScaleLegend.prototype.bj = function (a) {
        if (a == null) {
            return this.bb.a2();
        }
        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;
    };
    Object.defineProperty(ScaleLegend.prototype, "isScale", {
        get: function () {
            return this.get_isScale();
        },
        enumerable: true,
        configurable: 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.ap();
            if (!this.ba.forScaleColors(function (d, e) { return _this.bb.ar(c_1, _this.bj(d), e); })) {
                a = true;
            }
            this.bb.aw(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 };
var ScaleLegendView = /** @class */ (function (_super) {
    tslib_1.__extends(ScaleLegendView, _super);
    function ScaleLegendView(a) {
        var _this = _super.call(this, a) || this;
        _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();
        return _this;
    }
    ScaleLegendView.prototype.av = function () {
    };
    ScaleLegendView.prototype.u = function () {
    };
    ScaleLegendView.prototype.a2 = function () {
        return Color.u(0, 0, 0, 0);
    };
    ScaleLegendView.prototype.ap = function () {
        return new GradientData();
    };
    ScaleLegendView.prototype.ar = 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.aw = function (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();
    };
    ScaleLegendView.prototype.ac = function (a) {
        _super.prototype.ac.call(this, a);
        this.aj = this.b.b(a);
        this.a4 = this.b.z();
        this.as();
    };
    ScaleLegendView.prototype.as = function () {
        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);
            }
        }
    };
    ScaleLegendView.prototype.ax = function () {
        if (this.ak) {
            this.ak = false;
            this.au();
        }
    };
    ScaleLegendView.prototype.au = function () {
        if (this.aj == null) {
            return;
        }
        this.at();
    };
    ScaleLegendView.prototype.an = function (a) {
        var b = typeCast(TextBlock.$, a);
        if (b != null && b.ak != null) {
            return this.aj.e(b) + 0;
        }
        return 0;
    };
    ScaleLegendView.prototype.am = function (a) {
        return this.al + 0;
    };
    ScaleLegendView.prototype.at = function () {
        if (this.ai.ba == null || this.ai.ba.container == null || (this.ah == null && this.a0 == null)) {
            return;
        }
        if (this.aj.d) {
            var a = typeCast(IInternalLegendOwner_$type, this.ai.ba.container);
            this.aj.ac(a.getFontInfo());
            this.al = a.getFontHeight();
            this.a1 = a.getFontBrush();
            var b = this.an(this.az);
            var c = this.an(this.ay);
            var d = Math.max(b, c) + 4;
            if (d >= this.a4.width) {
                d = 0;
            }
            var e = this.a4.width - d;
            var f = 2;
            var g = 2;
            e = e - 4;
            var h = this.a4.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.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);
            }
        }
    };
    ScaleLegendView.prototype.ae = function () {
        _super.prototype.ae.call(this);
    };
    ScaleLegendView.$t = markType(ScaleLegendView, 'ScaleLegendView', LegendBaseView.$);
    return ScaleLegendView;
}(LegendBaseView));
export { ScaleLegendView };
