
import { register } from "@antv/x6-react-shape";
import { Node } from "@antv/x6";
import { useSizeHook, useShapeProps } from "../../hooks";

const component = ({ node }: { node: Node }) => {
  const { fill, stroke, opacity } = node.getData();
  const { size, ref } = useSizeHook();
  const {
    fillContent,
    strokeColor,
    strokeWidth,
  } = useShapeProps(fill, size, stroke);

  const handleStartMove = () => {
    node.setData({
      ignoreDrag: false,
    });
  };

  const handleEndMove = () => {
    node.setData({
      ignoreDrag: true,
    });
  };

  return (
    <>
      <div
        className="relative text-0 w-full h-full"
        style={{
          opacity: opacity / 100,
          border: `solid ${strokeWidth}px ${strokeColor}`,
        }}
        ref={ref}
      >
        <div
          className="w-full h-40px relative cursor-move"
          style={{
            background: fillContent,
            borderBottom: `solid ${strokeWidth}px ${strokeColor}`,
          }}
          onMouseEnter={handleStartMove}
          onMouseLeave={handleEndMove}
        >
        </div>
        <div className="pool">
          <div className="stage"></div>
          <div className="lane"></div>
        </div>
      </div>
    </>
  );
};

register({
  shape: "custom-react-verticalLane",
  width: 250,
  height: 540,
  effect: ["data"],
  component: component,
});

const verticalLane = {
  name: "泳道(垂直)",
  icon: require("./image/verticalLane.png"),
  node: {
    shape: "custom-react-verticalLane",
    data: {
      label: "",
      // 泳池名称
      poolName: "",
      // 泳道
      lane: [],
      // 阶段
      stage: [],
      isLane: true,
      laneDirection: "vertical",
      ignoreDrag: true,
      noCreate: true,
    },
  },
};

export default verticalLane;
