"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 __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var robin_react_1 = require("@simplus/robin-react");
var robins_1 = require("../../robins");
var charts_1 = require("./charts");
var charts = robins_1.robins.charts;
// We bind the component to the robins we want to use
var Chart = /** @class */ (function (_super) {
    __extends(Chart, _super);
    function Chart() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.getSampleData = function (chartType) {
            var line_data = [
                {
                    'category': 'Risk hours (Benchmark)',
                    'risk': 78,
                },
                {
                    'category': 'Risk hours (Actual)',
                    'risk': 38,
                },
                {
                    'category': 'Team impact (Hours)',
                    'risk': 60,
                },
                {
                    'category': 'Total productivity (Hours)',
                    'risk': 73,
                }
            ];
            var table_data = [
                {
                    'Problem type': 'Partner/Spouse',
                    'Risk hours (Benchmark)': '1300',
                    'Risk hours (Actuals)': '0',
                    'Team impact (Hours)': '1300'
                },
                {
                    'Problem type': 'Self esteem',
                    'Risk hours (Benchmark)': '840',
                    'Risk hours (Actuals)': '320',
                    'Team impact (Hours)': '200'
                },
                {
                    'Problem type': 'Bereavement',
                    'Risk hours (Benchmark)': '510',
                    'Risk hours (Actuals)': '640',
                    'Team impact (Hours)': '110'
                },
                {
                    'Problem type': 'Interpersonal conflict',
                    'Risk hours (Benchmark)': '320',
                    'Risk hours (Actuals)': '85',
                    'Team impact (Hours)': '20'
                },
                {
                    'Problem type': 'Suicide',
                    'Risk hours (Benchmark)': '1300',
                    'Risk hours (Actuals)': '120',
                    'Team impact (Hours)': '110'
                }
            ];
            var bar_data = [
                {
                    'category': 'Partner/Spouse',
                    'problem': 93,
                },
                {
                    'category': 'Self-esteem',
                    'problem': 82,
                },
                {
                    'category': 'Bereavement',
                    'problem': 78,
                },
                {
                    'category': 'Interpersonal-conflict',
                    'problem': 75,
                },
                {
                    'category': 'Suicide',
                    'problem': 74,
                },
                {
                    'category': 'Alcohol Use/Misuse/Abuse',
                    'problem': 65,
                },
                {
                    'category': 'Service-enquiry',
                    'problem': 64,
                },
                {
                    'category': 'Chronic-illness/Condition',
                    'problem': 63,
                },
                {
                    'category': 'Consumer/Credit-laws',
                    'problem': 48,
                },
                {
                    'category': 'Budget/Affordability',
                    'problem': 28,
                },
                {
                    'category': 'Retirement/Invest/Savings',
                    'problem': 27,
                },
                {
                    'category': 'Family-members',
                    'problem': 17,
                }
            ];
            var column_data = [
                {
                    'category': 'Risk hours (Benchmark)',
                    'risk': 78,
                },
                {
                    'category': 'Risk hours (Actual)',
                    'risk': 38,
                },
                {
                    'category': 'Team impact (Hours)',
                    'risk': 60,
                },
                {
                    'category': 'Total productivity (Hours)',
                    'risk': 73,
                }
            ];
            var kpi_data = [
                {
                    'title': 'Work impact score',
                    'value': 74,
                    'footer': 'select relative for benchmark comparison'
                },
                {
                    'title': 'Working hours at risk',
                    'value': "1,345",
                    'footer': 'select relative for benchmark comparison'
                },
                {
                    'title': 'Man-Days at risk',
                    'value': 73,
                    'footer': 'select relative for benchmark comparison'
                }
            ];
            if (chartType === ChartType.BarChart)
                return bar_data;
            if (chartType === ChartType.ColumnChart)
                return column_data;
            if (chartType === ChartType.KpiChart)
                return kpi_data;
            if (chartType === ChartType.TableChart)
                return table_data;
            return line_data;
        };
        _this.getChart = function (config, data) {
            if (config.type !== undefined) {
                switch (config.type) {
                    case (ChartType.LineChart): {
                        return React.createElement(charts_1.LineChart, { config: config, dataSource: data });
                    }
                    case (ChartType.BarChart): {
                        return React.createElement(charts_1.BarChart, { config: config, dataSource: data });
                    }
                    case (ChartType.ColumnChart): {
                        return React.createElement(charts_1.ColumnChart, { config: config, dataSource: data });
                    }
                    case (ChartType.PieChart): {
                        return React.createElement(charts_1.PieChart, { config: config, dataSource: data });
                    }
                    case (ChartType.KpiChart): {
                        return React.createElement(charts_1.KpiChart, { config: config, dataSource: data });
                    }
                    case (ChartType.TableChart): {
                        return React.createElement(charts_1.TableChart, { config: config, dataSource: data });
                    }
                }
                return React.createElement("div", null, "Unknown chart!");
            }
            return React.createElement("div", null, "...");
        };
        return _this;
    }
    /**
     *  componentDidMount method to initiate robin get charts method
     */
    Chart.prototype.componentDidMount = function () {
        charts.get("get-chart-" + this.props.id, "/" + this.props.id);
        charts.findOne(this.props.id.toString());
    };
    /**
     *  Render method
     */
    Chart.prototype.render = function () {
        if (charts.isError(charts.ACTIONS.FIND))
            return React.createElement("a", null, charts.isError(charts.ACTIONS.FIND));
        if (charts.isLoading(charts.ACTIONS.FIND))
            return React.createElement("a", null, "Loading chart...");
        var configChart = charts.getResult("get-chart-" + this.props.id) || [];
        if (configChart !== []) {
            var data = this.getSampleData(configChart.type);
            var chart = this.getChart(configChart, data);
            return React.createElement("div", null, chart);
        }
        return React.createElement("div", null, "...");
    };
    Chart = __decorate([
        robin_react_1.connectRobin([charts])
    ], Chart);
    return Chart;
}(React.Component));
exports.Chart = Chart;
var ChartType;
(function (ChartType) {
    ChartType["LineChart"] = "lineChart";
    ChartType["BarChart"] = "barChart";
    ChartType["ColumnChart"] = "columnChart";
    ChartType["PieChart"] = "pieChart";
    ChartType["KpiChart"] = "kpiChart";
    ChartType["TableChart"] = "tableChart";
})(ChartType = exports.ChartType || (exports.ChartType = {}));
exports.default = Chart;
