import React, { useMemo, useState } from 'react';
import Button from '@mui/material/Button';
import { ModeSwitcherSelect } from '../../../ModeSwitcherSelect';
export var WorkflowActionButtons = function (_a) {
    var actions = _a.workflowActions, actionRequestIsInProgress = _a.actionRequestIsInProgress, preferredAction = _a.preferredAction, _b = _a.comment, comment = _b === void 0 ? '' : _b;
    var _c = useState(function () { var _a; return (preferredAction === null || preferredAction === void 0 ? void 0 : preferredAction.label) || ((_a = actions[0]) === null || _a === void 0 ? void 0 : _a.text); }), currentAction = _c[0], setCurrentAction = _c[1];
    var buttonsGroup = useMemo(function () {
        return actions.map(function (_a) {
            var text = _a.text, onClick = _a.onClick;
            return ({
                label: text,
                onClick: function () {
                    setCurrentAction(text);
                    onClick(comment);
                },
                value: text
            });
        });
    }, [actions, comment]);
    if (buttonsGroup.length === 0) {
        return null;
    }
    if (buttonsGroup.length === 1) {
        return (React.createElement(Button, { variant: "outlined", onClick: buttonsGroup[0].onClick, disabled: actionRequestIsInProgress, size: "small" }, buttonsGroup[0].label));
    }
    return (React.createElement(ModeSwitcherSelect, { buttonsGroup: buttonsGroup, value: currentAction, loading: actionRequestIsInProgress, disabled: actionRequestIsInProgress }));
};
