import { ref } from 'vue'

import type { NodeTooltipData, NodeTooltipInfo } from '@/types/traceTooltip'

export function useNodeHoverTooltip(offsetX: number = 10, offsetY: number = 10) {
  const hoveredNodeInfo = ref<NodeTooltipInfo | null>(null)

  function setNodeHover(data: NodeTooltipData, x: number, y: number) {
    hoveredNodeInfo.value = {
      ...data,
      x: x + offsetX,
      y: y + offsetY,
    }
  }

  function clearNodeHover() {
    hoveredNodeInfo.value = null
  }

  return {
    hoveredNodeInfo,
    setNodeHover,
    clearNodeHover,
  }
}
