import { CompoundedComponent } from "@/types";
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},${h/6}
              A ${w/2} ${h/6} 0 0 1 ${w-strokeWidth},${h/6}
              L ${w-strokeWidth},${h-h/6}
              A ${w/2} ${h/6} 0 0 1 ${strokeWidth},${h-h/6}
              L ${strokeWidth},${h/6}
              Z
            `}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
          <path
            d={`
              M ${strokeWidth},${h/6}
              A ${w/2} ${h/6} 0 0 0 ${w-strokeWidth},${h/6}
            `}
            fill={fillContent}
            stroke={strokeColor}
            strokeDasharray={strokeDasharray}
            strokeWidth={strokeWidth}
          />
        </svg>
      </div>
    </>
  );
};

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

const horizontalDirectData: CompoundedComponent = {
  name: "数据库",
  icon: require("./image/horizontalDirectData.png"),
  node: {
    shape: "custom-react-horizontalDirectData",
    data: {
      label: "",
    },
  },
};

export default horizontalDirectData;
