import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import ReactDraggable from "react-draggable";
import { ClickAwayListener, Button, Typography, TableContainer, TableHead, TableCell, OutlinedInput, Select, Table, TableRow, TableBody, } from "@material-ui/core";
import { StrategyDialogContent, StrategyDialogDiv } from '../CommonStyles';
import { CloseGrayIcon } from '../../../CommonUI/Icon/CloseGrayIcon';
import { FlowStepOutputInstructionType } from '../../Structure/FlowStepOutputInstructions';
import { BaseStepStrategy } from '../BaseStepStrategy';
import { ObserveState } from '../../../CommonUI/StateManagement/ObserveState';
import { StateManager } from '../../../CommonUI/StateManagement/StateManager';
export class RegularStepStrategy extends BaseStepStrategy {
    render() {
        const { editContext } = this.props;
        if (!editContext.selectedStepStrategy) {
            return _jsx(_Fragment, {}, void 0);
        }
        let { step, position } = editContext.selectedStepStrategy;
        let paths = step.getOutcomeInstructions() || [];
        if (paths.length === 0) {
            return _jsx(_Fragment, {}, void 0);
        }
        return _jsx(ClickAwayListener, Object.assign({ onClickAway: this.onUnselectStepStrategyConnect }, { children: _jsx(ReactDraggable, Object.assign({ handle: ".StrategyDialog-title", defaultPosition: position }, { children: _jsx(StrategyDialogDiv, Object.assign({ "data-testid": "select-strategy-dialog" }, { children: _jsxs(StrategyDialogContent, Object.assign({ onClick: (e) => e.stopPropagation() }, { children: [_jsx(Button, Object.assign({ onClick: this.onUnselectStepStrategyConnect, className: 'StrategyDialog-close' }, { children: _jsx(CloseGrayIcon, {}, void 0) }), void 0),
                            _jsxs(Typography, Object.assign({ className: 'StrategyDialog-title' }, { children: [step === null || step === void 0 ? void 0 : step.name, " Paths"] }), void 0),
                            _jsx(TableContainer, Object.assign({ className: "StrategyDialog-table" }, { children: _jsxs(Table, { children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableCell, { children: "Path" }, void 0),
                                                    _jsx(TableCell, { children: "Strategies" }, void 0)] }, void 0) }, void 0),
                                        _jsx(TableBody, { children: paths.map((instruction, idx) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: instruction.pathName }, void 0),
                                                    _jsx(TableCell, Object.assign({ align: idx > 0 ? 'right' : 'left', style: { width: 196 } }, { children: idx > 0
                                                            ? _jsxs(_Fragment, { children: [_jsxs(Select, Object.assign({ fullWidth: true, className: `StrategyDialog-select ${instruction.strategy === FlowStepOutputInstructionType.THROW_EXCEPTION && 'StrategyDialog-select-error'}`, variant: "outlined", native: true, value: instruction.strategy, onChange: (event) => {
                                                                            instruction.strategy = event.target.value;
                                                                            if (step.sequence) {
                                                                                editContext.onSequenceUpdate(step.sequence);
                                                                            }
                                                                        }, "data-testid": `select-strategy-dialog_${instruction.pathName}` }, { children: [_jsx("option", Object.assign({ value: FlowStepOutputInstructionType.CONTINUE }, { children: "Continue" }), void 0),
                                                                            _jsx("option", Object.assign({ value: FlowStepOutputInstructionType.THROW_EXCEPTION }, { children: "End in error" }), void 0),
                                                                            _jsx("option", Object.assign({ value: FlowStepOutputInstructionType.END_FLOW }, { children: "End Flow" }), void 0),
                                                                            _jsx("option", Object.assign({ value: FlowStepOutputInstructionType.BRANCH }, { children: "Link to new sequence" }), void 0)] }), void 0),
                                                                    instruction.strategy === FlowStepOutputInstructionType.THROW_EXCEPTION &&
                                                                        _jsx(ObserveState, { listenTo: instruction, properties: ['errorMessage'], control: () => _jsx(OutlinedInput, { className: "Strategy-error", value: instruction.errorMessage, "data-testid": `select-strategy-dialog_${instruction.pathName}-set-error`, onChange: (e) => {
                                                                                    instruction.errorMessage = e.target.value;
                                                                                    StateManager.propertyChanged(instruction, 'errorMessage');
                                                                                }, placeholder: "Error Message" }, void 0) }, void 0)] }, void 0)
                                                            : _jsx("label", Object.assign({ className: "StrategyDialog-default__text" }, { children: "Continue Next Step" }), void 0) }), void 0)] }, idx))) }, void 0)] }, void 0) }), void 0)] }), void 0) }), void 0) }), void 0) }), void 0);
    }
}
//# sourceMappingURL=StepStrategy.js.map