
import { useVueFlow } from "@vue-flow/core";
const { addNodes, addEdges } = useVueFlow();

const typeNode: any = {
    'image': '图片',
    'text': '文本',
}

export function generateRandomNode(type: string) {
  return {
    id: Math.random().toString(),
    type: type, //special
    position: { x: 340, y: 150 },
    label: "Random Node",
    connectable: true,
    data: {
      hello: "world",
      label: typeNode[type],
    },
  };
}

export function onHandleClick(event: MouseEvent, props: any) {
  event.stopPropagation();

  console.log(32222, props);
  // 计算新节点的位置
  // 这里我们简单地将新节点放在当前节点的右侧 200px 处
  // 你可以根据 event.clientX/Y 获取鼠标点击的屏幕坐标，然后通过 project 方法转换为画布坐标
  const newNodePosition = {
    x: props.position.x + 200,
    y: props.position.y,
  };
  addNodes({
    id: `node_${Date.now()}`,
    type: props.handleType, // 或者是你的自定义节点类型 'special'
    position: newNodePosition,
    data: { label: "New Node" },
  });
  addEdges({
    id: `e${props.id}-node_${Date.now()}`,
    source: props.id,
    target: `node_${Date.now()}`,
  });
}