"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.factory = void 0;
var tslib_1 = require("tslib");
var React = require("react");
var common_1 = require("../common");
var MyScreen_1 = require("../components/MyScreen");
var Test_Grid_view_1 = require("../components/Test.Grid.view");
exports.factory = function (req) {
    if (req.type === 'EDITOR') {
        return renderEditor(req);
    }
    if (req.type === 'SCREEN') {
        return renderScreen(req);
    }
    if (req.type === 'CELL') {
        return renderCell(req);
    }
    console.log("Factory type '" + req.type + "' not supported by test.", req);
    return null;
};
function renderEditor(req) {
    console.log("\nTODO \uD83D\uDC37  extend [cell.props.view].editor \n");
    return React.createElement(common_1.CellEditor, null);
}
function renderScreen(req) {
    console.group('🌳 renderScreen');
    console.log('req', req);
    console.log('req.view', req.view);
    console.groupEnd();
    var type = req.view.screen ? req.view.screen.type : 'DEFAULT';
    if (type === 'GRID') {
        var grid = common_1.datagrid.Grid.create({ ns: 'foo' });
        var styles = {
            base: common_1.css({
                flex: 1,
                backgroundColor: 'rgba(255, 0, 0, 0.1)',
                display: 'flex',
            }),
            grid: common_1.css({ Absolute: 20, border: "solid 1px " + common_1.color.format(-0.2) }),
        };
        return (React.createElement("div", tslib_1.__assign({}, styles.base),
            React.createElement(Test_Grid_view_1.TestGridView, { grid: grid, style: styles.grid })));
    }
    else {
        return React.createElement(MyScreen_1.MyScreen, null);
    }
}
function renderCell(req) {
    var cell = req.cell;
    var view = cell.props.view;
    if (view && (!view.cell || !view.cell.type)) {
        return formatValue(cell.data);
    }
    else {
        var styles = {
            base: common_1.css({
                Absolute: 0,
                backgroundColor: 'rgba(255, 0, 0, 0.1)',
                fontSize: 11,
                Flex: 'center-center',
            }),
        };
        var type = view && view.cell ? view.cell.type : 'Unknown';
        return React.createElement("div", tslib_1.__assign({}, styles.base),
            "CUSTOM: ",
            type);
    }
}
function formatValue(cell) {
    var value = cell.props && cell.props.value ? cell.props.value : cell.value;
    value = typeof value === 'string' && !value.startsWith('=') ? common_1.markdown.toHtmlSync(value) : value;
    value = typeof value === 'object' ? JSON.stringify(value) : value;
    return value;
}
