/*
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 { __extends } from "tslib";
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
 */
var ScaleLegend = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScaleLegend, _super);
    function ScaleLegend() {
        var _this = _super.call(this) || this;
        _this.bf = null;
        _this.bh = 0;
        _this.bg = 0;
        _this.bd = null;
        _this.ab = ScaleLegend.$;
        return _this;
    }
    ScaleLegend.prototype.aj = function () {
        return new ScaleLegendView(this);
    };
    ScaleLegend.prototype.ba = function (a) {
        _super.prototype.ba.call(this, a);
        this.bf = a;
    };
    Object.defineProperty(ScaleLegend.prototype, "legendScaleElement", {
        get: function () {
            return this.bf.bb;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "minText", {
        get: function () {
            return this.bf.a7;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "maxText", {
        get: function () {
            return this.bf.a6;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ScaleLegend.prototype, "be", {
        get: function () {
            return this.bd;
        },
        set: function (a) {
            this.bd = a;
        },
        enumerable: false,
        configurable: true
    });
    ScaleLegend.prototype.bk = function () {
        this.bf.a3();
    };
    ScaleLegend.prototype.restoreOriginalState = function () {
        this.bk();
    };
    ScaleLegend.prototype.bn = function (a) {
        if (a == null) {
            return this.bf.ba();
        }
        return ColorUtil.w(a);
    };
    ScaleLegend.prototype.bi = function (a) {
        this.be = a;
        this.bj();
    };
    ScaleLegend.prototype.initializeLegend = function (a) {
        this.bi(a);
    };
    ScaleLegend.prototype.get_isScale = function () {
        return true;
    };
    ScaleLegend.prototype.bj = function () {
        var _this = this;
        if (this.legendScaleElement == null || this.be == null || !this.be.legendReady) {
            return;
        }
        if (this.be == null || !this.be.isAttachedTo(this)) {
            return;
        }
        var a = false;
        var b = typeCast(Shape.$, this.legendScaleElement);
        if (b != null) {
            var c_1 = this.bf.ax();
            if (!this.be.forScaleColors(function (d, e) { return _this.bf.az(c_1, _this.bn(d), e); })) {
                a = true;
            }
            this.bf.a4(b, a, c_1);
        }
        if (this.minText != null) {
            this.minText.al = this.be.minScaleText;
        }
        if (this.maxText != null) {
            this.maxText.al = this.be.maxScaleText;
        }
    };
    ScaleLegend.$t = markType(ScaleLegend, 'ScaleLegend', LegendBase.$, [IChartScaleLegend_$type]);
    return ScaleLegend;
}(LegendBase));
export { ScaleLegend };
/**
 * @hidden
 */
var ScaleLegendView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScaleLegendView, _super);
    function ScaleLegendView(a) {
        var _this = _super.call(this, a) || this;
        _this.aq = null;
        _this.bb = null;
        _this.a7 = null;
        _this.a6 = null;
        _this.ap = null;
        _this.ar = null;
        _this.bc = new Size();
        _this.as = false;
        _this.at = 0;
        _this.a9 = null;
        _this.a8 = null;
        _this.aq = a;
        _this.a7 = new TextBlock();
        _this.a6 = new TextBlock();
        _this.bb = new Polygon();
        return _this;
    }
    ScaleLegendView.prototype.a3 = function () {
    };
    ScaleLegendView.prototype.aa = function () {
    };
    ScaleLegendView.prototype.ba = function () {
        return Color.u(0, 0, 0, 0);
    };
    ScaleLegendView.prototype.ax = function () {
        return new GradientData();
    };
    ScaleLegendView.prototype.az = 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.a4 = function (a, b, c) {
        if (b) {
            this.a8 = this.aq.be.actualMarkerBrush;
            this.ap = null;
        }
        else {
            this.a8 = null;
            this.ap = c;
            this.ap.b();
        }
        this.a0();
    };
    ScaleLegendView.prototype.aj = function (a) {
        _super.prototype.aj.call(this, a);
        this.ar = this.d.b(a);
        this.bc = this.d.ab();
        this.a0();
    };
    ScaleLegendView.prototype.a0 = function () {
        if (!this.as) {
            this.as = true;
            if (this.d.g != null) {
                this.d.g.setTimeout(runOn(this, this.a5), 0);
            }
            else {
                window.setTimeout(runOn(this, this.a5), 0);
            }
        }
    };
    ScaleLegendView.prototype.a5 = function () {
        if (this.as) {
            this.as = false;
            this.a2();
        }
    };
    ScaleLegendView.prototype.a2 = function () {
        if (this.ar == null) {
            return;
        }
        this.a1();
    };
    ScaleLegendView.prototype.av = function (a) {
        var b = typeCast(TextBlock.$, a);
        if (b != null && b.al != null) {
            return this.ar.f(b) + 0;
        }
        return 0;
    };
    ScaleLegendView.prototype.au = function (a) {
        return this.at + 0;
    };
    ScaleLegendView.prototype.a1 = function () {
        if (this.aq.be == null || this.aq.be.container == null || (this.ap == null && this.a8 == null)) {
            return;
        }
        if (this.ar.d) {
            var a = typeCast(IInternalLegendOwner_$type, this.aq.be.container);
            this.ar.ae(a.getFontInfo());
            this.at = a.getFontHeight();
            this.a9 = a.getFontBrush();
            var b = this.av(this.a7);
            var c = this.av(this.a6);
            var d = Math.max(b, c) + 4;
            if (d >= this.bc.width) {
                d = 0;
            }
            var e = this.bc.width - d;
            var f = 2;
            var g = 2;
            e = e - 4;
            var h = this.bc.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.bb;
            p.an.clear();
            p.an.add(l);
            p.an.add(m);
            p.an.add(n);
            p.an.add(o);
            this.a7.n = i;
            this.a7.o = j;
            this.a7.ao = this.a9;
            this.a6.n = i;
            this.a6.o = j + k - (this.au(this.a7));
            this.a6.ao = this.a9;
            if (!this.ar.e) {
                this.ar.l(0, 0, this.bc.width, this.bc.height);
            }
            if (this.ap == null && this.a8 != null) {
                p._fill = this.a8;
                this.ar.u(p);
            }
            else {
                this.d.y(this.ar, p, this.ap, new Rect(0, g, f, e, h));
            }
            if (d > 0) {
                this.ar.x(this.a7);
                this.ar.x(this.a6);
            }
        }
    };
    ScaleLegendView.prototype.am = function () {
        _super.prototype.am.call(this);
    };
    ScaleLegendView.$t = markType(ScaleLegendView, 'ScaleLegendView', LegendBaseView.$);
    return ScaleLegendView;
}(LegendBaseView));
export { ScaleLegendView };
