"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RenderStepStrategy = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_draggable_1 = tslib_1.__importDefault(require("react-draggable"));
const core_1 = require("@material-ui/core");
const CommonStyles_1 = require("../CommonStyles");
const CloseGrayIcon_1 = require("../../../CommonUI/Icon/CloseGrayIcon");
const FlowStepOutputInstructions_1 = require("@appglue/common/dist/Flow/Structure/FlowStepOutputInstructions");
const BaseStepStrategy_1 = require("../BaseStepStrategy");
const ObserveState_1 = require("../../../CommonUI/StateManagement/ObserveState");
class RenderStepStrategy extends BaseStepStrategy_1.BaseStepStrategy {
    render() {
        const { editContext } = this.props;
        if (!editContext.selectedStepStrategy) {
            return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
        }
        let { step, position } = editContext.selectedStepStrategy;
        let paths = step.getOutcomeInstructions() || [];
        if (paths.length === 0) {
            return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
        }
        return ((0, jsx_runtime_1.jsx)(core_1.ClickAwayListener, { onClickAway: this.onUnselectStepStrategyConnect, children: (0, jsx_runtime_1.jsx)(react_draggable_1.default, { handle: ".StrategyDialog-title", defaultPosition: position, children: (0, jsx_runtime_1.jsx)(CommonStyles_1.StrategyDialogDiv, { "data-testid": "select-strategy-dialog", children: (0, jsx_runtime_1.jsxs)(CommonStyles_1.StrategyDialogContent, { onClick: (e) => e.stopPropagation(), children: [(0, jsx_runtime_1.jsx)(core_1.Button, { onClick: this.onUnselectStepStrategyConnect, className: "StrategyDialog-close", children: (0, jsx_runtime_1.jsx)(CloseGrayIcon_1.CloseGrayIcon, {}) }), (0, jsx_runtime_1.jsxs)(core_1.Typography, { className: "StrategyDialog-title", children: [step?.name, " Paths"] }), (0, jsx_runtime_1.jsx)(core_1.TableContainer, { className: "StrategyDialog-table", children: (0, jsx_runtime_1.jsxs)(core_1.Table, { children: [(0, jsx_runtime_1.jsx)(core_1.TableHead, { children: (0, jsx_runtime_1.jsxs)(core_1.TableRow, { children: [(0, jsx_runtime_1.jsx)(core_1.TableCell, { children: "Path" }), (0, jsx_runtime_1.jsx)(core_1.TableCell, { children: "Strategies" })] }) }), (0, jsx_runtime_1.jsx)(core_1.TableBody, { children: paths.map((instruction, idx) => ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: instruction, control: () => {
                                                    return ((0, jsx_runtime_1.jsxs)(core_1.TableRow, { children: [(0, jsx_runtime_1.jsx)(core_1.TableCell, { children: instruction.pathName }), (0, jsx_runtime_1.jsx)(core_1.TableCell, { align: idx > 0 ? "right" : "left", style: { width: 196 }, children: idx > 0 ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(core_1.Select, { fullWidth: true, className: `StrategyDialog-select ${instruction.strategy ===
                                                                                FlowStepOutputInstructions_1.FlowStepOutputInstructionType.THROW_EXCEPTION &&
                                                                                "StrategyDialog-select-error"}`, variant: "outlined", native: true, value: instruction.strategy, onChange: (event) => {
                                                                                instruction.strategy = event.target
                                                                                    .value;
                                                                            }, "data-testid": `select-strategy-dialog_${instruction.pathName}`, children: [(0, jsx_runtime_1.jsx)("option", { value: FlowStepOutputInstructions_1.FlowStepOutputInstructionType.CONTINUE, children: "Continue" }), (0, jsx_runtime_1.jsx)("option", { value: FlowStepOutputInstructions_1.FlowStepOutputInstructionType.THROW_EXCEPTION, children: "End in error" }), (0, jsx_runtime_1.jsx)("option", { value: FlowStepOutputInstructions_1.FlowStepOutputInstructionType.END_FLOW, children: "End Flow" }), (0, jsx_runtime_1.jsx)("option", { value: FlowStepOutputInstructions_1.FlowStepOutputInstructionType.BRANCH, children: "Link to new sequence" })] }), instruction.strategy ===
                                                                            FlowStepOutputInstructions_1.FlowStepOutputInstructionType.THROW_EXCEPTION && ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: instruction, properties: [
                                                                                FlowStepOutputInstructions_1.FlowStepOutputInstructions.ERROR_MESSAGE,
                                                                            ], control: () => ((0, jsx_runtime_1.jsx)(core_1.OutlinedInput, { className: "Strategy-error", value: instruction.errorMessage, "data-testid": `select-strategy-dialog_${instruction.pathName}-set-error`, onChange: (e) => {
                                                                                    instruction.errorMessage =
                                                                                        e.target.value;
                                                                                }, placeholder: "Error Message" })) }))] })) : ((0, jsx_runtime_1.jsx)("label", { className: "StrategyDialog-default__text", children: "Continue Next Step" })) })] }, idx));
                                                } }))) })] }) })] }) }) }) }));
    }
}
exports.RenderStepStrategy = RenderStepStrategy;
//# sourceMappingURL=RenderStepStrategy.js.map