import React__default, { useState } from 'react';
import { B as Button } from './Button-es.js';
import 'classnames';
import { T as Tooltip } from './Tooltip-es.js';
import { D as DataListActionsMenu } from './DataListActionsMenu-es.js';

function DataListItemActionsOverflow({ actions, }) {
    const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 });
    const [showMenu, setShowMenu] = useState(false);
    if (actions.length === 0)
        return null;
    return (React__default.createElement(React__default.Fragment, null,
        React__default.createElement(Tooltip, { message: "More actions" },
            React__default.createElement(Button, { icon: "more", ariaLabel: "More actions", type: "tertiary", variation: "subtle", onClick: handleMoreClick })),
        React__default.createElement(DataListActionsMenu, { visible: showMenu, position: menuPosition, onRequestClose: handleClose }, actions)));
    function handleMoreClick(event) {
        // Prevent firing the parent's onClick event when it is nested
        // within a clickable list item
        event.stopPropagation();
        // Prevent navigating to the parent's href event when it is nested within a
        // linked list item
        event.preventDefault();
        setShowMenu(true);
        const rect = event.currentTarget.getBoundingClientRect();
        const posX = rect.x;
        const posY = rect.y + rect.height;
        setMenuPosition({ x: posX, y: posY });
    }
    function handleClose() {
        setShowMenu(false);
    }
}

export { DataListItemActionsOverflow as D };
