"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 robins_1 = require("../../../robins");
var chart_1 = require("../chart");
var dashboardFilters_1 = require("../filters/dashboardFilters");
var dashboardTabs = robins_1.robins.dashboardTabs;
var DashboardTab = /** @class */ (function (_super) {
    __extends(DashboardTab, _super);
    function DashboardTab() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    /**
     *  ComponentDidMount method to initiate robin get dashboard tab request
     */
    DashboardTab.prototype.componentDidMount = function () {
        dashboardTabs.get("tabs " + this.props.id, this.props.id);
    };
    /**
     *  This is the render method
     */
    DashboardTab.prototype.render = function () {
        var data = dashboardTabs.getResult("tabs " + this.props.id) || null;
        if (data) {
            var items = data.dashboardItems;
            var ds = [];
            var d = [];
            var colInd = 0;
            for (var i = 0; i < items.length; i++) {
                if (colInd < data.size) {
                    if (colInd + items[i].cols > data.size) {
                        colInd = data.size;
                        i--;
                    }
                    else {
                        d.push(items[i]);
                        colInd += items[i].cols;
                    }
                    if (colInd >= data.size || i === items.length - 1) {
                        colInd = 0;
                        ds.push({ dashes: d });
                        d = [];
                    }
                }
            }
            return React.createElement("div", { className: this.props.className },
                React.createElement(dashboardFilters_1.DashboardFilter, { filters: data.filters }),
                React.createElement("table", { style: { width: '100%', tableLayout: 'fixed' } }, ds.map(function (row) {
                    return React.createElement("tr", null, row.dashes.map(function (col) {
                        return React.createElement("td", { colSpan: col.cols },
                            React.createElement(chart_1.Chart, { id: col.chart }));
                    }));
                })));
        }
        else
            return React.createElement("div", null);
    };
    return DashboardTab;
}(React.Component));
exports.DashboardTab = DashboardTab;
exports.default = DashboardTab;
