import { jsx } from "react/jsx-runtime";
import styled from "@emotion/styled";
import { Handle, Position, useConnection } from "../../xyflow/react.js";
const StyledHandle = styled(Handle, {
    shouldForwardProp: (prop)=>!prop.startsWith('$')
})`
  position: absolute;
  top: ${(props)=>{
    if (props.position === Position.Top) return '-15px';
    if (props.position === Position.Bottom) return 'auto';
    return '0';
}};
  bottom: ${(props)=>props.position === Position.Bottom ? '-15px' : 'auto'};
  left: ${(props)=>{
    if (props.position === Position.Left) return '-15px';
    if (props.position === Position.Right) return 'auto';
    return '0';
}};
  right: ${(props)=>props.position === Position.Right ? '-15px' : 'auto'};
  width: ${(props)=>{
    if (props.position === Position.Top || props.position === Position.Bottom) return props.$isConnecting && props.type !== props.$sourceType ? 'calc(100% + 20px)' : '100%';
    return props.$isConnecting && props.type !== props.$sourceType ? 'calc(20px + 100%)' : '20px';
}};
  height: ${(props)=>{
    if (props.position === Position.Left || props.position === Position.Right) return '100%';
    return '20px';
}};
  background: transparent;
  border: 0px solid transparent;
  border-radius: 0;
  transform: unset;
  opacity: ${(props)=>props.$isVisible && props.type !== props.$sourceType ? 0.5 : 0};
`;
const HANDLE_ID_SEPARATOR = '____';
function generateHandleId(nodeId, sourceOrTarget, handlePosition) {
    return [
        nodeId,
        sourceOrTarget,
        handlePosition
    ].join(HANDLE_ID_SEPARATOR);
}
const StageHandle = ({ id, type, position, isVisible = true })=>{
    const { inProgress, fromHandle } = useConnection();
    const sourceType = fromHandle?.type;
    return /*#__PURE__*/ jsx(StyledHandle, {
        isConnectableStart: 'source' === type,
        isConnectableEnd: 'target' === type,
        id: generateHandleId(id, type, position),
        type: type,
        $sourceType: sourceType,
        $isConnecting: inProgress,
        position: position,
        $isVisible: isVisible,
        isConnectable: true
    });
};
export { StageHandle };
