import {
  Handle,
  useNodeConnections,
  type HandleType,
  type Position
} from '@xyflow/react';


const LimitedConnectionCountHandle = (props: {
  node_id: string,
  type: HandleType,
  position: Position,
  connection_count: number,
  id?: string
}) => {
  const connections = useNodeConnections({
    id: props.node_id,
    handleType: props.type,
    handleId: props.id,
  });

  return (
    <Handle
      {...props}
      isConnectable={connections.length < props.connection_count}
    />
  );
};

export default LimitedConnectionCountHandle;