import { __assign } from "tslib";
import { ErrorBoundary } from '@dash4/ui';
import React from 'react';
import { Cell, Grid } from '../Grid';
var CouldNotLoad = function (_a) {
    var name = _a.name, className = _a.className;
    return (React.createElement("div", { className: className || '' }, "Could not load Plugin " + name));
};
export function Widgets(_a) {
    var tab = _a.tab;
    return (React.createElement(ErrorBoundary, null, tab.rows.map(function (row, rowIndex) {
        return (React.createElement(Grid, { key: tab.title + "-" + rowIndex }, row.map(function (config) {
            var id = config.id, name = config.name, lowerCaseName = config.lowerCaseName;
            if (!window.dash4 || !window.dash4.plugins) {
                return (React.createElement(Cell, { key: tab.title + "-" + rowIndex + "-" + lowerCaseName + "-" + id, width: config.width },
                    React.createElement(CouldNotLoad, { name: name })));
            }
            try {
                var Plugin_1 = window.dash4.plugins[name];
                if (!Plugin_1) {
                    return (React.createElement(Cell, { key: tab.title + "-" + rowIndex + "-" + lowerCaseName + "-" + id, width: config.width },
                        React.createElement(CouldNotLoad, { name: name })));
                }
                return (React.createElement(Cell, { key: tab.title + "-" + rowIndex + "-" + lowerCaseName + "-" + id, width: config.width },
                    React.createElement(ErrorBoundary, null,
                        React.createElement(Plugin_1, __assign({}, config)))));
            }
            catch (err) {
                // eslint-disable-next-line
                console.error(err);
                return (React.createElement(Cell, { key: tab.title + "-" + rowIndex + "-" + lowerCaseName + "-" + id, width: config.width },
                    React.createElement(CouldNotLoad, { name: name })));
            }
        })));
    })));
}
//# sourceMappingURL=index.js.map