import { jsx } from "react/jsx-runtime";
import { EdgeLabelRenderer } from "../../../xyflow/react.js";
import { AnimatePresence, motion } from "motion/react";
import { memo, useMemo } from "react";
import { CanvasInlineButton } from "../../ButtonHandle/CanvasInlineButton.js";
const EdgeToolbarComponent = ({ edgeId, visible, positioning, config, onMouseEnter, onMouseLeave })=>{
    const transform = useMemo(()=>`translate(-50%, -50%) translate(${positioning.offsetPosition.x}px, ${positioning.offsetPosition.y}px)`, [
        positioning.offsetPosition
    ]);
    return /*#__PURE__*/ jsx(EdgeLabelRenderer, {
        children: /*#__PURE__*/ jsx(AnimatePresence, {
            children: visible && /*#__PURE__*/ jsx(motion.div, {
                className: "nodrag nopan absolute top-0 left-0 z-1004 pointer-events-auto flex flex-row items-center gap-1",
                initial: {
                    opacity: 0
                },
                animate: {
                    opacity: 1
                },
                exit: {
                    opacity: 0
                },
                transition: {
                    duration: 0.15,
                    ease: 'easeOut'
                },
                style: {
                    transform
                },
                onMouseEnter: onMouseEnter,
                onMouseLeave: onMouseLeave,
                children: config.actions.map((action)=>/*#__PURE__*/ jsx(CanvasInlineButton, {
                        "aria-label": action.label ?? action.id,
                        disabled: action.disabled,
                        icon: action.icon ?? 'plus',
                        onClick: (e)=>{
                            e.stopPropagation();
                            e.preventDefault();
                            if (!action.disabled) action.onAction(edgeId, positioning.pathPosition);
                        }
                    }, action.id))
            }, `edge-toolbar-${edgeId}`)
        })
    });
};
EdgeToolbarComponent.displayName = 'EdgeToolbar';
const EdgeToolbar = /*#__PURE__*/ memo(EdgeToolbarComponent);
export { EdgeToolbar };
