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

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

  const { width:w, height:h } = size;

  return (
    <>
      <div
        className="relative text-0 w-full h-full"
        style={{ opacity: opacity / 100 }}
        ref={ref}
      >
        <CustomInput
          value={label}
          styles={text}
          node={node}
          placeholder="请输入文本"
          txtStyle={{ bottom: "-60%" }}
        />
        <svg
          className="w-full h-full"
          viewBox={`0 0 ${w} ${h}`}
          xmlns="http://www.w3.org/2000/svg"
        >
          <defs>{defsContent}</defs>
          <ellipse
            cx={w / 2}
            cy={h / 2}
            rx={w / 2 - strokeWidth}
            ry={h / 2 - strokeWidth}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`
              M ${w*(1/6)},${h*(1/6)}
              L ${w*(5/6)},${h*(5/6)}
              M ${w*(5/6)},${h*(1/6)}
              L ${w*(1/6)},${h*(5/6)}
              `}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const summation = {
  name: "或者",
  icon: require("./image/summation.png"),
  node: {
    shape: "custom-react-summation",
    data: {
      label: "",
    },
  },
};

export default summation;
