"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Action = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const IconDropdownButton_1 = require("../../../IconDropdownButton");
const MenuItem_1 = require("../../../MenuItem");
const Tooltip_1 = require("../../../Tooltip");
const MainIconButton_1 = require("./MainIconButton");
const MobileMainButton_1 = require("./MobileMainButton");
const Action = ({ action, onActionClick, isDisabled, tooltipPlacement, }) => {
    if ('actions' in action) {
        const { disabled, icon, name, disabledReason, actions } = action;
        return ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { title: disabledReason || name, withoutContainer: !disabled, placement: tooltipPlacement, children: (0, jsx_runtime_1.jsx)(IconDropdownButton_1.IconDropdownButton, { icon: icon, variant: "text", disabled: isDisabled || disabled, children: actions.map(({ name: nestedActionName, onClick: onClickNested, ...props }) => ((0, react_1.createElement)(MenuItem_1.MenuItem, { ...props, key: nestedActionName, onClick: onActionClick(onClickNested) }, nestedActionName))) }) }, name));
    }
    const { isMobilePrimary } = action;
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MainIconButton_1.MainIconButton, { action: action, onActionClick: onActionClick, isDisabled: isDisabled, tooltipPlacement: tooltipPlacement }), isMobilePrimary && ((0, jsx_runtime_1.jsx)(MobileMainButton_1.MobileMainButton, { action: action, onActionClick: onActionClick, isDisabled: isDisabled }))] }));
};
exports.Action = Action;
