"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var KpiChart = /** @class */ (function (_super) {
    __extends(KpiChart, _super);
    function KpiChart() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    /**
     *  Render method
     */
    KpiChart.prototype.render = function () {
        var _this = this;
        var DEFAULT_COLORS = ['#333'];
        var DEFAULT_BACKGROUND = ['#FFF'];
        var BACKGROUND = this.props.config.variables.background ? this.props.config.variables.background : DEFAULT_BACKGROUND;
        var COLOR = this.props.config.variables.color ? this.props.config.variables.color : DEFAULT_COLORS;
        var unit = this.props.config.variables.unit ? this.props.config.variables.unit : '';
        var titleField = "";
        var valueField = "";
        var footerField = "";
        this.props.config.fields.forEach(function (f) {
            if (f.key === _this.props.config.variables.title)
                titleField = f.name;
            if (f.key === _this.props.config.variables.value)
                valueField = f.name;
            if (f.key === _this.props.config.variables.footer)
                footerField = f.name;
        });
        return (React.createElement("div", { className: 'kpi-charts' }, this.props.dataSource.map(function (item, index) {
            var title = "";
            var value = "";
            var footer = "";
            Object.keys(item).forEach(function (f, ind) {
                if (titleField === f)
                    title = item[titleField];
                if (valueField === f)
                    value = item[valueField];
                if (footerField === f)
                    footer = item[footerField];
            });
            var border = index < _this.props.dataSource.length - 1 ? '1px solid #999' : '';
            return React.createElement("div", { key: index, className: 'kpi', style: {
                    backgroundColor: BACKGROUND,
                    color: COLOR
                } },
                React.createElement("div", { className: 'kpi-title' }, title),
                React.createElement("div", { className: 'kpi-data', style: { borderRight: border } },
                    value,
                    unit),
                React.createElement("div", { className: 'kpi-footer' }, footer));
        })));
    };
    return KpiChart;
}(React.Component));
exports.KpiChart = KpiChart;
exports.default = KpiChart;
