import { CompoundedComponent } from "@/types";
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);

  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 ${size?.width} ${size?.height}`}
          xmlns="http://www.w3.org/2000/svg"
        >
          <defs>{defsContent}</defs>
          <ellipse
            cx={size?.width / 2}
            cy={size?.height / 2}
            rx={size?.width ? size.width / 2 - strokeWidth : 0}
            ry={size?.height  ? size.height /  2 - strokeWidth : 0}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`
              M ${size?.width / 2},${strokeWidth}
              L ${size?.width / 2},${size?.height - strokeWidth}
              M ${strokeWidth},${size.height / 2}
              L ${size.width - strokeWidth},${size.height / 2}
              `}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

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

export default maybe;
