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:w, height: h } = size || { width: 0, height: 0 };
  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>
          <rect
            x={strokeWidth}
            y={strokeWidth}
            width={size?.width - strokeWidth * 2}
            height={size?.height - strokeWidth * 2}
            rx={4}
            ry={4}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`
              M ${Math.min(w/6,20)}, ${strokeWidth}
              L ${Math.min(w/6,20)}, ${h - strokeWidth}
              M ${w - Math.min(w/6,20)}, ${strokeWidth}
              L ${w - Math.min(w/6,20)}, ${h - strokeWidth}
            `}
            stroke={strokeColor}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const activeClass: CompoundedComponent = {
  name: "活动类",
  icon: require("./image/activeClass.png"),
  node: {
    shape: "custom-react-activeClass",
    data: {
      label: "",
    },
  },
};

export default activeClass;
