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 };

  return (
    <>
      <div
        className="relative text-0 w-full h-full"
        ref={ref}
        style={{ opacity: opacity / 100 }}
      >
        <div className="absolute top-0 left-0 w-full h-30px">
          <CustomInput value={label} styles={text} node={node} />
        </div>
        
        <svg
          className="w-full h-full"
          viewBox={`0 0 ${width} ${height}`}
          xmlns="http://www.w3.org/2000/svg"
        >
          <defs>{defsContent}</defs>
          <rect
            x={strokeWidth}
            y={strokeWidth}
            width={width - strokeWidth * 2}
            height={30}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`
              M ${width/2},${30 + strokeWidth}
              L ${width/2},${height - strokeWidth}
            `}
            fill="none"
            stroke={strokeColor}
            strokeDasharray='2 2'
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const sequenceLifeLine: CompoundedComponent = {
  name: "生命线",
  icon: require("./image/sequenceLifeLine.png"),
  node: {
    shape: "custom-react-sequenceLifeLine",
    data: {
      label: "",
    },
  },
};

export default sequenceLifeLine;
