"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 dashboard_1 = require("./dashboard");
var robins_1 = require("../../../robins");
var dashboardsContainer = robins_1.robins.dashboardsContainer;
var DashboardsContainer = /** @class */ (function (_super) {
    __extends(DashboardsContainer, _super);
    function DashboardsContainer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    /**
     *  ComponentDidMount method to initiate robin get dashboard containers request
     */
    DashboardsContainer.prototype.componentDidMount = function () {
        dashboardsContainer.get("container " + this.props.id, this.props.id);
    };
    /**
     *  This is the render method
     */
    DashboardsContainer.prototype.render = function () {
        var dashboardContainer = dashboardsContainer.getResult("container " + this.props.id) || null;
        if (dashboardContainer) {
            var dashboards = dashboardContainer.dashboards;
            var ds = [];
            var d = [];
            var colInd = 0;
            for (var i = 0; i < dashboards.length; i++) {
                if (colInd < dashboardContainer.size) {
                    if (colInd + dashboards[i].cols > dashboardContainer.size) {
                        colInd = dashboardContainer.size;
                        i--;
                    }
                    else {
                        d.push(dashboards[i]);
                        colInd += dashboards[i].cols;
                    }
                    if (colInd >= dashboardContainer.size || i === dashboards.length - 1) {
                        colInd = 0;
                        ds.push({ dashes: d });
                        d = [];
                    }
                }
            }
            return React.createElement("div", { style: { background: '#F9FBFF' } },
                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(dashboard_1.Dashboard, { name: col.name, type: col.type, size: col.size, cols: col.cols, filters: col.filters, sections: col.dashboardSections }));
                    }));
                })));
        }
        else {
            return React.createElement("div", null);
        }
    };
    return DashboardsContainer;
}(React.Component));
exports.DashboardsContainer = DashboardsContainer;
exports.default = DashboardsContainer;
