
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"
        ref={ref}
        style={{ opacity: opacity / 100 }}
      >
        <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>
          <path
            d={`
              M ${strokeWidth},${strokeWidth}  
              L ${w-strokeWidth},${strokeWidth}  
              L ${w-strokeWidth},${h-strokeWidth} 
              L ${strokeWidth},${h-strokeWidth}
              L ${strokeWidth},${strokeWidth} Z
              M ${Math.min(w/6,20)},${strokeWidth}
              L ${Math.min(w/6,20)},${h-strokeWidth} Z
              M ${w-Math.min(w/6,20)},${strokeWidth}
              L ${w-Math.min(w/6,20)},${h-strokeWidth} Z
            `}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const predefinedProcess = {
  name: "子流程",
  icon: require("./image/predefinedProcess.png"),
  node: {
    shape: "custom-react-predefinedProcess",
    data: {
      label: "",
    },
  },
};

export default predefinedProcess;
