"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowSequenceEditRenderer = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const FlowConstants_1 = require("@appglue/common/dist/Flow/Utilities/FlowConstants");
const FlowStepSequenceType_1 = require("@appglue/common/dist/Flow/Structure/FlowStepSequenceType");
const FlowUtilities_1 = require("@appglue/common/dist/Flow/Utilities/FlowUtilities");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const PropertyEditorColor_1 = require("../../CommonUI/PropertyEditing/PropertyEditorColor");
const ObserveState_1 = require("../../CommonUI/StateManagement/ObserveState");
const VariablePicker_1 = tslib_1.__importDefault(require("../../CommonUI/VariablePicker"));
const PropertyEditorText_1 = require("../../CommonUI/PropertyEditing/PropertyEditorText");
const core_1 = require("@material-ui/core");
const ExpressionView_1 = require("../../Expressions/Builder/ExpressionView");
class FlowSequenceEditRenderer {
    sequence;
    constructor(sequence) {
        this.sequence = sequence;
    }
    renderEditUI() {
        let isSystem = this.sequence._id === FlowConstants_1.FlowConstants.PRIMARY_SEQUENCE ||
            this.sequence._id == FlowConstants_1.FlowConstants.END_SEQUENCE ||
            this.sequence._id === FlowConstants_1.FlowConstants.ERROR_SEQUENCE;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: this.sequence, control: () => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!isSystem && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Sequence Type", (0, jsx_runtime_1.jsxs)(core_1.RadioGroup, { value: this.sequence.sequenceType, name: "sequence_type", onChange: (event) => {
                                    // @ts-ignore
                                    this.sequence.sequenceType = event.target.value;
                                    StateManager_1.StateManager.changed(this.sequence);
                                }, children: [(0, jsx_runtime_1.jsx)(core_1.FormControlLabel, { value: FlowStepSequenceType_1.FlowStepSequenceType.STANDARD, control: (0, jsx_runtime_1.jsx)(core_1.Radio, {}), label: "Standard" }), (0, jsx_runtime_1.jsx)(core_1.FormControlLabel, { value: FlowStepSequenceType_1.FlowStepSequenceType.BRANCH_MERGE, control: (0, jsx_runtime_1.jsx)(core_1.Radio, {}), label: "Branch/Merge" }), (0, jsx_runtime_1.jsx)(core_1.FormControlLabel, { value: FlowStepSequenceType_1.FlowStepSequenceType.ITERATE, control: (0, jsx_runtime_1.jsx)(core_1.Radio, {}), label: "For Each Item" }), (0, jsx_runtime_1.jsx)(core_1.FormControlLabel, { value: FlowStepSequenceType_1.FlowStepSequenceType.ITERATE_PARALLEL, control: (0, jsx_runtime_1.jsx)(core_1.Radio, {}), label: "For Each Item (Parallel)" }), (0, jsx_runtime_1.jsx)(core_1.FormControlLabel, { value: FlowStepSequenceType_1.FlowStepSequenceType.ITERATE_WHILE, control: (0, jsx_runtime_1.jsx)(core_1.Radio, {}), label: "Repeat While" })] })] })), (this.sequence.sequenceType === FlowStepSequenceType_1.FlowStepSequenceType.ITERATE ||
                        this.sequence.sequenceType === FlowStepSequenceType_1.FlowStepSequenceType.ITERATE_PARALLEL) && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(VariablePicker_1.default, { selected: this.sequence.listArrayVariableName, data: FlowUtilities_1.FlowUtilities.getDataForSequence(this.sequence.flow, this.sequence._id), isList: true, onVariableSet: (path) => {
                                    if (path) {
                                        this.sequence.listArrayVariableName = path;
                                        StateManager_1.StateManager.propertyChanged(this.sequence, "listArrayVariableName");
                                    }
                                }, label: "List Variable", inputProps: {
                                    variant: "outlined",
                                    size: "large",
                                    fullWidth: true,
                                } }), (0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { editObject: this, propertyName: "listItemVariableName", label: "Item Name", updateCallback: () => {
                                    StateManager_1.StateManager.propertyChanged(this.sequence, "listItemVariableName");
                                } })] })), this.sequence.sequenceType === FlowStepSequenceType_1.FlowStepSequenceType.ITERATE_WHILE && (
                    // add the rule
                    (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Repeat while true", (0, jsx_runtime_1.jsx)(ExpressionView_1.ExpressionView, { expression: this.sequence.whileExpression })] })), (0, jsx_runtime_1.jsx)(PropertyEditorColor_1.PropertyEditorColor, { "data-testid": `${this.sequence._id}_stack-color`, editObject: this.sequence, propertyName: "color", label: "Stack Color", updateCallback: () => {
                            StateManager_1.StateManager.propertyChanged(this.sequence, "color");
                        } })] })) }));
    }
}
exports.FlowSequenceEditRenderer = FlowSequenceEditRenderer;
//# sourceMappingURL=FlowSequenceEditRenderer.js.map