import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "../components/ui/dropdown-menu";
import { MagicEditImageIcon } from "./ui/Icons";
import { ImagePlus } from "lucide-react";
export function ImageEditButton({ actions, triggerButton, buttonText = "Edit", buttonIcon = "MoreVertical", testId = "menu-toggle-button", buttonClassName, defaultActionId = "select", onOpenChange, }) {
    const [showMenu, setShowMenu] = useState(false);
    const handleOpenChange = (open) => {
        setShowMenu(open);
        onOpenChange?.(open);
    };
    const defaultAction = actions.find((a) => a.id === defaultActionId);
    const defaultTriggerButton = (_jsxs("div", { className: `text-dark border-gray-3 absolute right-2 bottom-2 flex cursor-pointer items-center justify-center overflow-hidden rounded border bg-white text-xs font-medium opacity-70 shadow-lg transition-opacity hover:opacity-85 ${buttonClassName || ""}`, onClick: (e) => {
            // Prevent clicks from reaching underlying elements
            e.stopPropagation();
        }, children: [defaultAction && (_jsx("button", { type: "button", className: "hover:bg-gray-5 cursor-pointer px-2 py-1.5", onClick: (e) => {
                    e.stopPropagation();
                    defaultAction.onClick?.(e);
                    handleOpenChange(false);
                }, "data-testid": `${testId}-quick-select`, children: _jsx(ImagePlus, { strokeWidth: 1, size: 16 }) })), _jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "hover:bg-gray-5 border-gray-3 flex cursor-pointer items-center gap-2 border-l px-2 py-1.5", "data-testid": testId, children: [_jsx(MagicEditImageIcon, { className: "mr-1" }), " ", buttonText] }) })] }));
    return (_jsxs(DropdownMenu, { open: showMenu, onOpenChange: handleOpenChange, children: [triggerButton ? (_jsx(DropdownMenuTrigger, { asChild: true, children: triggerButton })) : (defaultTriggerButton), _jsx(DropdownMenuContent, { align: "end", side: "top", sideOffset: 8, children: actions.map((action) => (_jsxs(DropdownMenuItem, { "data-testid": `menu-item-${action.id}`, onClick: (e) => {
                        action.onClick(e);
                        handleOpenChange(false);
                    }, children: [action.icon, action.label] }, action.id))) })] }));
}
//# sourceMappingURL=ImageEditButton.js.map