import { CompoundedComponent } from "@/types";
import { register } from "@antv/x6-react-shape";
import { Node } from "@antv/x6";
import CustomInput from "@/components/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, height } = size || { width: 0, height: 0 };
  const offsetX = width*(1/5);
  return (
    <>
      <div
        className="relative text-0 w-full h-full"
        ref={ref}
        style={{ opacity: opacity / 100 }}
      >
        <CustomInput value={label} styles={text} node={node} />
        <svg
          className="w-full h-full"
          viewBox={`0 0 ${width} ${height}`}
          xmlns="http://www.w3.org/2000/svg"
        >
          <defs>{defsContent}</defs>
          <ellipse
            cx={width / 2 + offsetX / 2 }
            cy={height / 2}
            rx={(width - offsetX) / 2 - strokeWidth}
            ry={height / 2 - strokeWidth}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`
              M ${strokeWidth},${strokeWidth}
              L ${strokeWidth},${height - strokeWidth}
              M ${strokeWidth},${height / 2}
              L ${offsetX},${height / 2}
            `}
            fill="none"
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

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

export default sequenceBoundary;
