import { useEffect, useRef, useState } from "react";
import { Graph, Node } from "@antv/x6";
import img from "@/assets/wf_icon_and.gif";
import { MenuProps } from "antd";
import Port from "./Port";
import Content from "./Content";

export default ({ node, graph }: { node: Node; graph: Graph }) => {
  const [hovered, setHovered] = useState(false);
  const [isSelected, setIsSelected] = useState(false);

  const items: MenuProps["items"] = [
    { key: "copy", label: "复制" },
    { key: "delete", label: "删除", onClick: () => node.remove() },
  ];

  graph?.on("selection:changed", (args) => {
    setIsSelected(graph.isSelected(node));
  });

  return (
    <div
      className="flow-node"
      style={{ 
        
        boxShadow: isSelected ? '0 0 0 8px #2941701a' : ''
      }}
      onMouseEnter={() => setHovered(true)}
      onMouseLeave={() => setHovered(false)}
    >
      <Content
        img={img}
        node={node}
        graph={graph}
        items={items}
        selected={isSelected}
        hovered={hovered}
      />

      <Port hovered={hovered} out={false} style={{ left: -7, cursor: "default" }}  node={node} graph={graph} />
      <Port hovered={hovered} style={{ right: -7, cursor: "crosshair" }}  node={node} graph={graph} />
    </div>
  );
};
