var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React from 'react';
import i18n from 'ui-i18n';
import { splitAt, pipe, propEq, map, omit, reject } from 'ramda';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import { SmallIconButtonWithTooltip } from '../SmallIconButton';
import { DropDownMenuButton } from '../DropDownMenuButton';
import { MenuItemRenderer } from './components/MenuItemRenderer';
import { ActionButton as DefaultActionButton } from '../ActionButton';
import { ActionButtonMode } from '../types';
export var ActionsPanel = function (_a) {
    var actions = _a.actions, _b = _a.numberOfButtons, numberOfButtons = _b === void 0 ? 2 : _b, _c = _a.mode, mode = _c === void 0 ? 'normal' : _c, actionButtonSize = _a.actionButtonSize, moreOptionsButtonSize = _a.moreOptionsButtonSize, classes = _a.classes, onActionsMenuOpen = _a.onActionsMenuOpen, onActionsMenuClose = _a.onActionsMenuClose, dataReltioId = _a.dataReltioId;
    var _d = pipe(reject(propEq('show', false)), map(omit(['show'])), splitAt(numberOfButtons))(actions), buttonActions = _d[0], menuActions = _d[1];
    var buttonMode = mode === 'normal' ? ActionButtonMode.button : ActionButtonMode.iconButton;
    var defaultButtonSize = mode === 'normal' ? 'MPlus' : 'S';
    var buttonSize = moreOptionsButtonSize !== null && moreOptionsButtonSize !== void 0 ? moreOptionsButtonSize : defaultButtonSize;
    return (React.createElement(React.Fragment, null,
        buttonActions.map(function (_a, index) {
            var _b = _a.ActionButton, ActionButton = _b === void 0 ? DefaultActionButton : _b, props = __rest(_a, ["ActionButton"]);
            return (React.createElement(ActionButton, __assign({ key: index, mode: buttonMode, className: classes === null || classes === void 0 ? void 0 : classes.actionButton }, (actionButtonSize ? { size: actionButtonSize } : {}), props)));
        }),
        menuActions.length > 0 && (React.createElement(DropDownMenuButton, { buttonComponent: SmallIconButtonWithTooltip, buttonProps: {
                icon: MoreVertIcon,
                size: buttonSize,
                tooltipTitle: i18n.text('More actions'),
                'data-reltio-id': dataReltioId
            }, className: classes === null || classes === void 0 ? void 0 : classes.moreOptions, menuId: "view-actions", menuItems: menuActions, onMenuOpen: onActionsMenuOpen, onMenuClose: onActionsMenuClose, MenuItemRenderer: MenuItemRenderer }))));
};
