import { CompoundedComponent } from "@/types";
import { register } from "@antv/x6-react-shape";
import { Node } from "@antv/x6";
import { ports, defaultData } from "../../config/data";
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} />
        <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 / 2 - strokeWidth}
            ry={size?.height / 2 - strokeWidth}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`M${size.width/2},${size.height - strokeWidth} L${size.width - strokeWidth},${size.height - strokeWidth}`}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const sequentialData: CompoundedComponent = {
  name: "队列数据",
  icon: require("./image/sequentialData.png"),
  node: {
    shape: "custom-react-sequentialData",
    data: {
      label: "",
      ...defaultData,
    },
    ports,
  },
};

export default sequentialData;
