
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,
    defsContent,
    strokeColor,
    strokeWidth,
    strokeDasharray,
  } = useShapeProps(fill, size, stroke);

  const { width, height } = size || { width: 0, height: 0 };

  return (
    <>
      <div
        className="relative text-0 w-full h-full"
        ref={ref}
        style={{ opacity: opacity / 100 }}
      >
        <svg
          className="w-full h-full"
          viewBox={`0 0 ${width} ${height}`}
          xmlns="http://www.w3.org/2000/svg"
        >
          <defs>{defsContent}</defs>
          <path
            d={`
              M ${strokeWidth},${strokeWidth}
              L ${width - strokeWidth},${strokeWidth}
              L ${strokeWidth},${height - strokeWidth}
              L ${width - strokeWidth},${height - strokeWidth}
              L ${strokeWidth},${strokeWidth}
              Z
            `}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const sequenceTimerSignal = {
  name: "时间信号",
  icon: require("./image/sequenceTimerSignal.png"),
  node: {
    shape: "custom-react-sequenceTimerSignal",
    data: {
      label: "",
    },
  },
};

export default sequenceTimerSignal;
