import { Handle, Position } from "@xyflow/react";
import type { NodeProps } from "@xyflow/react";

import type { DiagramNode } from "../graph";

export function BpmnMessageEventNode({ data }: NodeProps) {
  const d = data as unknown as DiagramNode & { label: string };

  return (
    <div className="bpmn-event-node">
      <svg width={36} height={36} viewBox="0 0 36 36">
        <circle
          cx={18}
          cy={18}
          r={17}
          fill="none"
          style={{ stroke: "var(--bpmn-message-event)", strokeWidth: 2 }}
        />
        <circle
          cx={18}
          cy={18}
          r={13}
          fill="none"
          style={{ stroke: "var(--bpmn-message-event)", strokeWidth: 1 }}
        />
        <rect
          x={10}
          y={13}
          width={16}
          height={11}
          fill="none"
          rx={1}
          style={{ stroke: "var(--bpmn-message-event)", strokeWidth: 1.2 }}
        />
        <polyline
          points="10,13 18,19 26,13"
          fill="none"
          style={{ stroke: "var(--bpmn-message-event)", strokeWidth: 1.2 }}
        />
      </svg>
      {d.label && <div className="bpmn-event-label">{d.label}</div>}
      <Handle type="target" position={Position.Top} style={{ opacity: 0 }} />
      <Handle
        type="target"
        position={Position.Left}
        id="left"
        style={{ opacity: 0 }}
      />
      <Handle type="source" position={Position.Bottom} style={{ opacity: 0 }} />
      <Handle
        type="source"
        position={Position.Right}
        id="right"
        style={{ opacity: 0 }}
      />
    </div>
  );
}
