import { Position, useStore } from "../../xyflow/react.js";
import { memo, useMemo } from "react";
import { useConnectedHandles } from "../BaseCanvas/ConnectedHandlesContext.js";
import { useButtonHandles } from "../ButtonHandle/useButtonHandles.js";
const StageNodeHandlesInner = ({ id, isReadOnly, selected, isHovered, isException })=>{
    const isConnecting = useStore((state)=>!!state.connectionClickStartHandle);
    const connectedHandleIds = useConnectedHandles(id);
    const hasConnections = connectedHandleIds.size > 0;
    const shouldShowHandles = useMemo(()=>!isReadOnly && (selected || isHovered || isConnecting || hasConnections), [
        hasConnections,
        isConnecting,
        selected,
        isHovered,
        isReadOnly
    ]);
    const handleConfigurations = useMemo(()=>isException ? [] : [
            {
                position: Position.Left,
                handles: [
                    {
                        id: `${id}____target____left`,
                        type: 'target',
                        handleType: 'input'
                    }
                ],
                visible: selected || isHovered || isConnecting,
                customPositionAndOffsets: {
                    top: 0,
                    height: 64
                }
            },
            {
                position: Position.Right,
                handles: [
                    {
                        id: `${id}____source____right`,
                        type: 'source',
                        handleType: 'output'
                    }
                ],
                visible: selected || isHovered || isConnecting,
                customPositionAndOffsets: {
                    top: 0,
                    height: 64
                }
            },
            {
                position: Position.Bottom,
                handles: [
                    {
                        id: `${id}____target____bottom`,
                        type: 'target',
                        handleType: 'input'
                    }
                ],
                visible: selected || isHovered || isConnecting
            },
            {
                position: Position.Bottom,
                handles: [
                    {
                        id: `${id}____source____bottom`,
                        type: 'source',
                        handleType: 'output'
                    }
                ],
                visible: selected || isHovered || isConnecting
            }
        ], [
        isException,
        id,
        selected,
        isHovered,
        isConnecting
    ]);
    const handleElements = useButtonHandles({
        handleConfigurations,
        shouldShowHandles,
        nodeId: id,
        selected
    });
    return handleElements;
};
const StageNodeHandles = /*#__PURE__*/ memo(StageNodeHandlesInner);
export { StageNodeHandles };
