"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestDisplayFactory = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const TestResultDataType_1 = require("@appglue/common/dist/Common/Testing/TestResultDataType");
const ExpressionBuilder_1 = require("../../Expressions/ExpressionBuilder");
const ObserveState_1 = require("../StateManagement/ObserveState");
const react_diff_viewer_1 = tslib_1.__importDefault(require("@mockingjay-io/react-diff-viewer"));
const FormTestResult_1 = require("../../Form/Structure/FormTestResult");
const TextMergeBuilderEditor_1 = require("../../TextMerge/Builder/TextMergeBuilderEditor");
const IntersectionRuleDesigner_1 = require("../../Rule/Intersection/Builder/IntersectionRuleDesigner");
const RuleTableDesigner_1 = require("../../Rule/Table/RuleTable/Builder/RuleTableDesigner");
const ValueTableRuleDesigner_1 = require("../../Rule/Table/ValueTable/Builder/ValueTableRuleDesigner");
const TreeRuleDesigner_1 = require("../../Rule/Tree/Builder/TreeRuleDesigner");
const TextMergeRenderTestResult_1 = require("../../TextMerge/Builder/TextMergeRenderTestResult");
const XFlowEditor_Designer_1 = require("../../Flow/Builder/Components/XFlowEditor.Designer");
const FlowEditContext_1 = require("../../Flow/FlowEditContext");
const material_1 = require("@mui/material");
class TestDisplayFactory {
    static renderTestDisplay(resultItem) {
        switch (resultItem.type) {
            case TestResultDataType_1.TestResultDataType.FLOW:
                let editContext = new FlowEditContext_1.FlowEditContext(resultItem.flowConfiguration);
                return ((0, jsx_runtime_1.jsx)(material_1.Box, { height: "100%", children: (0, jsx_runtime_1.jsx)(XFlowEditor_Designer_1.FlowDesignPage, { flow: resultItem.flowConfiguration, editContext: editContext }) }));
            case TestResultDataType_1.TestResultDataType.FLOW_STEP:
                return (0, jsx_runtime_1.jsx)(material_1.Box, { children: "step ui" });
            case TestResultDataType_1.TestResultDataType.FLOW_SEQUENCE:
                break;
            case TestResultDataType_1.TestResultDataType.FLOW_BRANCH:
                break;
            case TestResultDataType_1.TestResultDataType.FORM:
                return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: resultItem.form.render() });
            case TestResultDataType_1.TestResultDataType.EXPRESSION:
                return (0, jsx_runtime_1.jsx)(ExpressionBuilder_1.ExpressionBuilder, { expression: resultItem.expression });
            case TestResultDataType_1.TestResultDataType.EXPRESSION_VALUE:
                break;
            case TestResultDataType_1.TestResultDataType.EXPRESSION_ELEMENT:
                break;
            case TestResultDataType_1.TestResultDataType.STATEMENT_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.VALUE_TABLE_RULE:
                return resultItem.definition &&
                    resultItem.editContext ? ((0, jsx_runtime_1.jsx)(ValueTableRuleDesigner_1.ValueTableRuleDesigner, { ruleDefinition: resultItem.definition, editContext: resultItem.editContext })) : undefined;
            case TestResultDataType_1.TestResultDataType.VALUE_TABLE_RULE_ROW:
                break;
            case TestResultDataType_1.TestResultDataType.VALUE_TABLE_RULE_RULE_COLUMN:
                break;
            case TestResultDataType_1.TestResultDataType.RULE_TABLE:
                return resultItem.definition &&
                    resultItem.editContext ? ((0, jsx_runtime_1.jsx)(RuleTableDesigner_1.RuleTableDesigner, { ruleDefinition: resultItem.definition, editContext: resultItem.editContext })) : undefined;
            case TestResultDataType_1.TestResultDataType.RULE_TABLE_ROW:
                break;
            case TestResultDataType_1.TestResultDataType.RULE_TABLE_COLUMN:
                break;
            case TestResultDataType_1.TestResultDataType.INTERSECTION_RULE:
                return resultItem.definition &&
                    resultItem.editContext ? ((0, jsx_runtime_1.jsx)(IntersectionRuleDesigner_1.IntersectionRuleDesigner, { ruleDefinition: resultItem.definition, editContext: resultItem.editContext })) : undefined;
            case TestResultDataType_1.TestResultDataType.INTERSECTION_X_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.INTERSECTION_Y_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.TREE_RULE:
                return resultItem.definition &&
                    resultItem.editContext ? ((0, jsx_runtime_1.jsx)(TreeRuleDesigner_1.TreeRuleDesigner, { ruleDefinition: resultItem.definition, editContext: resultItem.editContext })) : undefined;
            case TestResultDataType_1.TestResultDataType.TREE_NODE_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.TEXT_MERGE:
                return resultItem.definition &&
                    resultItem.editContext ? ((0, jsx_runtime_1.jsx)(TextMergeBuilderEditor_1.TextMergeBuilderEditor, { definition: resultItem.definition, editContext: resultItem.editContext })) : undefined;
            case TestResultDataType_1.TestResultDataType.TEXT_MERGE_VALUE:
                break;
        }
        return undefined;
    }
    static renderTabs(resultItem) {
        switch (resultItem.type) {
            case TestResultDataType_1.TestResultDataType.FLOW:
                break;
            case TestResultDataType_1.TestResultDataType.FLOW_STEP:
                break;
            case TestResultDataType_1.TestResultDataType.FLOW_SEQUENCE:
                break;
            case TestResultDataType_1.TestResultDataType.FLOW_BRANCH:
                break;
            case TestResultDataType_1.TestResultDataType.FORM:
                return [
                    {
                        name: "ui",
                        ui: ((0, jsx_runtime_1.jsx)(FormTestResult_1.FormUI, { renderUI: resultItem.form.render, context: resultItem.formContext })),
                    },
                    {
                        name: "compare",
                        ui: ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: this, control: () => ((0, jsx_runtime_1.jsx)(react_diff_viewer_1.default, { oldValue: JSON.stringify(resultItem.startData.values, null, 2), newValue: JSON.stringify(resultItem.formContext.data.values, null, 2) })) })),
                    },
                ];
            case TestResultDataType_1.TestResultDataType.EXPRESSION:
                break;
            case TestResultDataType_1.TestResultDataType.EXPRESSION_VALUE:
                break;
            case TestResultDataType_1.TestResultDataType.EXPRESSION_ELEMENT:
                break;
            case TestResultDataType_1.TestResultDataType.STATEMENT_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.VALUE_TABLE_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.VALUE_TABLE_RULE_ROW:
                break;
            case TestResultDataType_1.TestResultDataType.VALUE_TABLE_RULE_RULE_COLUMN:
                break;
            case TestResultDataType_1.TestResultDataType.RULE_TABLE:
                break;
            case TestResultDataType_1.TestResultDataType.RULE_TABLE_ROW:
                break;
            case TestResultDataType_1.TestResultDataType.RULE_TABLE_COLUMN:
                break;
            case TestResultDataType_1.TestResultDataType.INTERSECTION_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.INTERSECTION_X_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.INTERSECTION_Y_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.TREE_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.TREE_NODE_RULE:
                break;
            case TestResultDataType_1.TestResultDataType.TEXT_MERGE:
                return [
                    {
                        name: "results",
                        ui: (0, jsx_runtime_1.jsx)(TextMergeRenderTestResult_1.RenderTestResult, { definition: resultItem.definition }),
                    },
                    {
                        name: "merge text detail",
                        ui: TestDisplayFactory.renderTestDisplay(resultItem) ?? (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}),
                    },
                ];
            case TestResultDataType_1.TestResultDataType.TEXT_MERGE_VALUE:
                break;
        }
        return undefined;
    }
}
exports.TestDisplayFactory = TestDisplayFactory;
//# sourceMappingURL=TestDisplayFactory.js.map