import { jsx, jsxs } from "react/jsx-runtime";
import { Position, useStore } from "../../xyflow/react.js";
import { memo, useCallback, useMemo, useState } from "react";
import { CanvasIcon } from "../../utils/icon-registry.js";
import { areNodePropsEqualIgnoringPosition } from "../../utils/nodePropsEqual.js";
import { useConnectedHandles } from "../BaseCanvas/ConnectedHandlesContext.js";
import { useButtonHandles } from "../ButtonHandle/useButtonHandles.js";
import { CanvasTooltip } from "../CanvasTooltip.js";
import { TriggerContainer, TriggerIconWrapper } from "./TriggerNode.styles.js";
const TriggerNodeComponent = (props)=>{
    const { selected, id, details = {} } = props;
    const { tooltip, icon, status } = details;
    const [isHovered, setIsHovered] = useState(false);
    const isConnecting = useStore((state)=>!!state.connectionClickStartHandle);
    const connectedHandleIds = useConnectedHandles(id);
    const hasConnections = connectedHandleIds.size > 0;
    const shouldShowHandles = useMemo(()=>selected || isHovered || isConnecting || hasConnections, [
        selected,
        isHovered,
        isConnecting,
        hasConnections
    ]);
    const handleMouseEnter = useCallback(()=>setIsHovered(true), []);
    const handleMouseLeave = useCallback(()=>setIsHovered(false), []);
    const handleConfigurations = [
        {
            position: Position.Right,
            handles: [
                {
                    id: `${id}____source____right`,
                    type: 'source',
                    handleType: 'output'
                }
            ],
            visible: selected || isHovered || isConnecting
        }
    ];
    const handleElements = useButtonHandles({
        handleConfigurations,
        shouldShowHandles,
        nodeId: id,
        selected
    });
    const triggerContent = /*#__PURE__*/ jsx(TriggerContainer, {
        selected: !!selected,
        status: status,
        children: /*#__PURE__*/ jsx(TriggerIconWrapper, {
            status: status,
            children: icon || /*#__PURE__*/ jsx(CanvasIcon, {
                icon: "zap"
            })
        })
    });
    return /*#__PURE__*/ jsxs("div", {
        style: {
            width: '100%',
            height: '100%',
            position: 'relative'
        },
        onMouseEnter: handleMouseEnter,
        onMouseLeave: handleMouseLeave,
        children: [
            tooltip ? /*#__PURE__*/ jsx(CanvasTooltip, {
                content: tooltip,
                placement: "top",
                children: triggerContent
            }) : triggerContent,
            handleElements
        ]
    });
};
const TriggerNode = /*#__PURE__*/ memo(TriggerNodeComponent, areNodePropsEqualIgnoringPosition);
export { TriggerNode };
