import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { useRef } from "react";
import { useIntl } from "react-intl";
import { Dropdown } from "../../../Dropdown/Dropdown.js";
import { DropdownList } from "../../../Dropdown/DropdownList.js";
import { UiButton } from "../../UiButton/UiButton.js";
import { UiAutofocus } from "../../UiFocusManager/UiAutofocus.js";
import { e } from "../asyncTableBem.js";
import { messages } from "../locales.js";
import { ASYNC_TABLE_BULK_ACTIONS_BUTTON_ID, ASYNC_TABLE_BULK_ACTIONS_MENU_ID } from "./constants.js";
import { UiAsyncTableDropdownItem } from "./UiAsyncTableDropdownItem.js";
export function UiAsyncTableBulkActions({ bulkActions }) {
    const buttonRef = useRef(null);
    const intl = useIntl();
    return (_jsx("div", { className: e("bulk-actions"), children: _jsx(Dropdown, { renderButton: ({ toggleDropdown, isOpen }) => (_jsx(UiButton, { id: ASYNC_TABLE_BULK_ACTIONS_BUTTON_ID, ref: buttonRef, isDisabled: !bulkActions.length, label: intl.formatMessage(messages["chooseAction"]), onClick: () => toggleDropdown(), size: "small", iconAfter: "navigateDown", accessibilityConfig: {
                    ariaExpanded: isOpen,
                    ariaHaspopup: true,
                    ariaControls: ASYNC_TABLE_BULK_ACTIONS_MENU_ID,
                    iconAriaHidden: true,
                } })), alignPoints: [{ align: "bl tl" }], renderBody: ({ closeDropdown }) => (_jsx(UiAutofocus, { children: _jsx(DropdownList, { id: ASYNC_TABLE_BULK_ACTIONS_MENU_ID, items: bulkActions, renderItem: ({ item }) => (_jsx(UiAsyncTableDropdownItem, { label: item.label, onClick: () => {
                            item.onClick();
                            closeDropdown();
                        }, accessibilityConfig: item.accessibilityConfig })), width: 200, accessibilityConfig: {
                        role: "menu",
                        ariaLabelledBy: ASYNC_TABLE_BULK_ACTIONS_BUTTON_ID,
                    } }) })) }) }));
}
