
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 ${w*(6/12)},${h*(2/8)}
              a ${h*(1/8) - strokeWidth},${h*(1/8) - strokeWidth} 0 1,0 0,${-h*(1/4)}
              a ${h*(1/8) - strokeWidth},${h*(1/8) - strokeWidth} 0 1,0 0,${h*(1/4)}
              M ${w*(6/12)},${h*(2/8)}
              L ${w*(6/12)},${h*(6/8)}
              L ${w*(1/12)},${h}
              M ${w*(6/12)},${h*(6/8)}
              L ${w*(11/12)},${h}
              M ${strokeWidth},${h*(4/8)}
              L ${w-strokeWidth},${h*(4/8)}
            `}
            fill="none"
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const actor = {
  name: "角色",
  icon: require("./image/actor.png"),
  node: {
    shape: "custom-react-actor",
    data: {
      label: "",
    },
    ports: [],
  },
};

export default actor;
