import { __decorate, __metadata } from "tslib";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import React from "react";
import styled from "styled-components";
import { IconButton } from "@material-ui/core";
import { StepNameLabel } from "../CommonUI/StepNameLabel";
import { DataUtilities } from "../../Common/DataUtilities";
import { FlowStepOutputInstructions } from "../Structure/FlowStepOutputInstructions";
import { AutoBind } from "../../Common/AutoBind";
import { StateManager } from "../../CommonUI/StateManagement/StateManager";
import { DeleteGrayIcon } from "../../CommonUI/Icon/DeleteGrayIcon";
import { DescriptionIcon } from "../../CommonUI/Icon/DescriptionIcon";
import { StepDescription } from "../CommonUI/StepDescription";
import { FlowStepRegistration } from "../Utilities/RegisterFlowStep";
import { MultiExecutableOutputDefinition } from "../../Common/Execution/MultiExecutable";
export const BasicStep = styled.div `
    width: 100%;
`;
export class BaseFlowStep extends React.Component {
    constructor() {
        super({});
        this._id = DataUtilities.generateUniqueId();
        this.isShowDescription = false;
        // this is where we put instructions on what to do with non default paths
        this._nonDefaultOutputInstructions = {};
        this.renderActionUI = () => {
            return (_jsxs("div", Object.assign({ className: "StepEdit" }, { children: [_jsx(IconButton, Object.assign({ onClick: () => {
                            this.isShowDescription = !this.isShowDescription;
                            this.stepUpdate();
                        }, "data-testid": `${this._id}_toggle-description` }, { children: _jsx(DescriptionIcon, {}, void 0) }), void 0),
                    _jsx(IconButton, Object.assign({ onClick: this.remove }, { children: _jsx(DeleteGrayIcon, {}, void 0) }), void 0)] }), void 0));
        };
        this.paths = [];
        this.name = Reflect.get(this, "__type");
        this.description = "";
    }
    stepUpdate() {
        StateManager.changed(this);
        if (this.sequence)
            StateManager.propertyChanged(this.sequence, "steps");
    }
    // forces refresh of entire designer (expensive)
    designerUpdate() {
        //        this.getFormContext()?.refreshDesigner();
    }
    remove() {
        var _a, _b, _c;
        (_c = (_b = (_a = this.sequence) === null || _a === void 0 ? void 0 : _a.flow) === null || _b === void 0 ? void 0 : _b.context) === null || _c === void 0 ? void 0 : _c.onDelete(this._id);
    }
    getOutcomeInstructions() {
        let inst = [];
        let paths = this.getOutcomes();
        if (paths) {
            for (let p of paths) {
                inst.push(this.findOutputInstruction(p.name));
            }
        }
        return inst;
    }
    getAlternateOutcomeInstructions() {
        var _a;
        let inst = ((_a = this.sequence.editContext) === null || _a === void 0 ? void 0 : _a.displayBehavior.getPathsForStep(this)) || [];
        return inst;
    }
    render() {
        return (_jsxs(_Fragment, { children: [_jsxs(BasicStep, Object.assign({ className: "Step_root" }, { children: [_jsx(StepNameLabel, { step: this }, void 0), this.renderActionUI()] }), void 0),
                this.isShowDescription && _jsx(StepDescription, { step: this }, void 0)] }, void 0));
    }
    findOutputInstruction(name) {
        var _a;
        let inst = (_a = this._nonDefaultOutputInstructions[name]) !== null && _a !== void 0 ? _a : null;
        if (!inst) {
            inst = new FlowStepOutputInstructions(name, this._id);
            this._nonDefaultOutputInstructions[name] = inst;
        }
        return inst;
    }
    isCurrentOutcome(name) {
        let outcomes = this.getOutcomes();
        if (!outcomes)
            return false;
        for (let o of outcomes) {
            if (o.name === name)
                return true;
        }
        return false;
    }
    getOutcomes() {
        return this.paths.map((value) => {
            return new MultiExecutableOutputDefinition(value);
        });
    }
    addNewPath() { }
    get icon() {
        var _a;
        const icon = (_a = FlowStepRegistration.getByName(this.type)) === null || _a === void 0 ? void 0 : _a.icon;
        return icon;
    }
    get type() {
        return Reflect.get(Reflect.get(this, "__proto__"), "__type");
    }
}
__decorate([
    AutoBind,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], BaseFlowStep.prototype, "stepUpdate", null);
__decorate([
    AutoBind,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], BaseFlowStep.prototype, "designerUpdate", null);
__decorate([
    AutoBind,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], BaseFlowStep.prototype, "remove", null);
//# sourceMappingURL=BaseFlowStep.js.map