'use strict';

var React = require('react');
var Button = require('./Button-cjs.js');
require('classnames');
var Tooltip = require('./Tooltip-cjs.js');
var DataListActionsMenu = require('./DataListActionsMenu-cjs.js');

function DataListItemActionsOverflow({ actions, }) {
    const [menuPosition, setMenuPosition] = React.useState({ x: 0, y: 0 });
    const [showMenu, setShowMenu] = React.useState(false);
    if (actions.length === 0)
        return null;
    return (React.createElement(React.Fragment, null,
        React.createElement(Tooltip.Tooltip, { message: "More actions" },
            React.createElement(Button.Button, { icon: "more", ariaLabel: "More actions", type: "tertiary", variation: "subtle", onClick: handleMoreClick })),
        React.createElement(DataListActionsMenu.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);
    }
}

exports.DataListItemActionsOverflow = DataListItemActionsOverflow;
