"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefineUnitTest = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const material_1 = require("@mui/material");
const UILabel_1 = require("../BuildlingBlocks/UILabel");
const UITextField_1 = require("../BuildlingBlocks/UITextField");
const UIStyleConstants_1 = require("@appglue/common/dist/Common/UIStyleConstants");
const UIToggleButton_1 = require("../BuildlingBlocks/UIToggleButton");
const UnitTestEvaluationType_1 = require("@appglue/common/dist/Common/Testing/UnitTestEvaluationType");
const react_1 = require("react");
const IDesignValidationProvider_1 = require("@appglue/common/dist/Common/IDesignValidationProvider");
const OpenBlueIcon_1 = require("../Icon/OpenBlueIcon");
const DropdownBlueIcon_1 = require("../Icon/DropdownBlueIcon");
const styled_components_1 = tslib_1.__importDefault(require("styled-components"));
const UISwitch_1 = require("../BuildlingBlocks/UISwitch");
const UIStandardLayer_1 = require("../BuildlingBlocks/UIStandardLayer");
function DefineUnitTest(props) {
    const [testName, setTestName] = (0, react_1.useState)();
    const [expectError, setExpectError] = (0, react_1.useState)(false);
    const [outcomesMatch, setOutcomesMatch] = (0, react_1.useState)(true);
    const [selectEvents, setSelectEvents] = (0, react_1.useState)(false);
    (0, react_1.useEffect)(() => {
        let testItems = [props.unitTest.resultNode];
        setSelectEvents(false);
        while (testItems.length !== 0) {
            let ti = testItems.pop();
            if (!ti)
                break;
            if (ti.unitTestEvaluationType !== UnitTestEvaluationType_1.UnitTestEvaluationType.NONE) {
                setSelectEvents(true);
                break;
            }
            if (ti.children)
                testItems.push(...ti.children);
        }
        setTestName(props.unitTest.name);
    }, [props.unitTest]);
    function getErrors() {
        let issues = [];
        if (!testName || testName === "")
            issues.push(new IDesignValidationProvider_1.ValidationIssue("Unit Test Name Is Required"));
        return issues;
    }
    return ((0, jsx_runtime_1.jsx)(UIStandardLayer_1.UIStandardLayer, { actionText: "Create Unit Test", validationIssues: getErrors(), onSet: () => {
            // create it here
            props.onTestSave(props.unitTest);
        }, open: props.open, onClose: props.onClose, title: "Define Unit Test", renderLayer: () => {
            return ((0, jsx_runtime_1.jsxs)(material_1.Box, { width: "550px", display: "flex", flexDirection: "column", children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { paddingBottom: "10px", display: "flex", alignItems: "center", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { paddingRight: "15px", children: "Unit Test Name:" }), (0, jsx_runtime_1.jsx)(UITextField_1.UITextField, { value: testName, onChange: (e) => setTestName(e.target.value), variant: "outlined" })] }), (0, jsx_runtime_1.jsx)(material_1.Link, { children: "View Input Data" })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { marginTop: "10px", display: "flex", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { width: "150px", children: (0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { children: "Select Events" }) }), (0, jsx_runtime_1.jsx)(UISwitch_1.UISwitch, { checked: selectEvents, onSet: (v) => {
                                    setSelectEvents(v);
                                } })] }), selectEvents && ((0, jsx_runtime_1.jsx)(material_1.Box, { marginTop: "10px", paddingLeft: "5px", paddingRight: "10px", paddingTop: "10px", border: 1, borderColor: UIStyleConstants_1.UIStyleConstants.GRAY_LIGHT_COLOR, borderRadius: "4px", overflow: "hidden", height: "400px", style: { overflowY: "scroll" }, children: (0, jsx_runtime_1.jsx)(TestItem, { i: props.unitTest.resultNode, startCollapsed: false }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { marginTop: "10px", display: "flex", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { width: "150px", children: (0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { children: "Error Expected" }) }), (0, jsx_runtime_1.jsx)(UISwitch_1.UISwitch, { checked: expectError, onSet: (v) => {
                                    setExpectError(v);
                                } })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { marginTop: "10px", display: "flex", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { width: "150px", children: (0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { children: "Match Outputs" }) }), (0, jsx_runtime_1.jsx)(UISwitch_1.UISwitch, { checked: outcomesMatch, onSet: (v) => {
                                    setOutcomesMatch(v);
                                } })] })] }));
        } }));
}
exports.DefineUnitTest = DefineUnitTest;
const ExpandIconButton = styled_components_1.default.div `
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;

    visibility: ${(props) => (props.visible ? "visible" : "hidden")};
`;
function TestItem(props) {
    const [resultType, setResultType] = (0, react_1.useState)();
    const [collapsed, setCollapsed] = (0, react_1.useState)(true);
    (0, react_1.useEffect)(() => {
        setResultType(props.i.unitTestEvaluationType);
        setCollapsed(props.startCollapsed);
    }, [props.i]);
    return ((0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", flexDirection: "column", children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { paddingRight: "15px", display: "flex", flexDirection: "column", children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(ExpandIconButton, { visible: props.i.children !== undefined && props.i.children.length !== 0, onClick: () => setCollapsed(!collapsed), children: collapsed ? (0, jsx_runtime_1.jsx)(OpenBlueIcon_1.OpenBlueIcon, {}) : (0, jsx_runtime_1.jsx)(DropdownBlueIcon_1.DropdownBlueIcon, {}) }), (0, jsx_runtime_1.jsx)(material_1.Box, { width: "10px", height: "10px", marginRight: "7px", marginLeft: "7px", bgcolor: props.i.isError ? UIStyleConstants_1.UIStyleConstants.RED_COLOR : UIStyleConstants_1.UIStyleConstants.GRAY_DARK_COLOR }), (0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { children: props.i.type })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { display: "flex", paddingLeft: "25px", children: (0, jsx_runtime_1.jsx)(UILabel_1.UILabel, { children: props.i.value }) })] }) }), resultType && ((0, jsx_runtime_1.jsx)(UIToggleButton_1.UIToggleButton, { options: [
                            { value: UnitTestEvaluationType_1.UnitTestEvaluationType.NONE, text: "Ignore" },
                            { value: UnitTestEvaluationType_1.UnitTestEvaluationType.EXISTS, text: "Exists" },
                            { value: UnitTestEvaluationType_1.UnitTestEvaluationType.DATA_MATCHES, text: "Matches" },
                        ], onChange: (v) => {
                            // @ts-ignore
                            setResultType(v);
                            props.i.unitTestEvaluationType = v;
                        }, value: resultType }))] }), !collapsed && ((0, jsx_runtime_1.jsx)(material_1.Box, { paddingLeft: "10px", children: props.i.children?.map((ii) => {
                    return (0, jsx_runtime_1.jsx)(TestItem, { i: ii, startCollapsed: true });
                }) }))] }, "test_item:" + props.i.id));
}
//# sourceMappingURL=DefineUnitTest.js.map