import { createElement as _createElement } from "react";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { forwardRef } from 'react';
import { useConsolidatedRef, useI18n } from '../../hooks';
import Button from '../Button';
import Icon from '../Icon';
import MenuButton from '../MenuButton';
export default forwardRef(function Actions({ 
// @ts-expect-error
'data-testid': dataTestId, items, menuAt = 2, scrollAt, iconOnly = true, menuButtonProps, contextualLabel, compact = false, disabled = false, tabIndex }, ref) {
    const t = useI18n();
    const menuButtonRef = useConsolidatedRef(ref);
    if (!items || items.length === 0) {
        return null;
    }
    return items.length >= menuAt ? (_jsx(MenuButton, { ...(dataTestId ? { 'data-testid': dataTestId } : {}), ref: menuButtonRef, text: t('actions'), "aria-label": contextualLabel && t('actions_for', [contextualLabel]), iconOnly: true, icon: 'more', variant: 'simple', compact: compact, onClick: menuButtonProps?.onClick, onKeyDown: menuButtonProps?.onKeyDown, disabled: disabled, tabIndex: tabIndex, menu: {
            scrollAt,
            items: items.map(({ text, onClick, ...restProps }) => ({
                ...restProps,
                primary: text,
                onClick: onClick
                    ? (id, e) => {
                        onClick(id, e, menuButtonRef.current ?? undefined);
                    }
                    : undefined
            }))
        } })) : (_jsx(_Fragment, { children: items.map(({ id, icon, text, onClick, ...restProps }) => {
            return (_createElement(Button, { ...(dataTestId ? { 'data-testid': dataTestId } : {}), key: id, variant: icon && iconOnly ? 'simple' : undefined, onClick: (event) => onClick?.(id, event), label: icon ? text : undefined, icon: !!icon && iconOnly, compact: compact, "aria-label": contextualLabel ? `${text} - ${contextualLabel}` : text, disabled: disabled, ...restProps }, icon && iconOnly ? _jsx(Icon, { name: icon }) : text));
        }) }));
});
//# sourceMappingURL=Actions.js.map