import { computed, type Ref } from 'vue'
import { useZoneEditorStore } from '@/stores/zoneEditor'
import { useGamePointerHandlers } from '@/composables/useGamePointerHandlers'
import { useZoneEditorPointerHandlers } from '@/composables/useZoneEditorPointerHandlers'

export function usePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilemaps.TilemapLayer, waypoint: Ref<{ visible: boolean; x: number; y: number }>, camera: Ref<Phaser.Cameras.Scene2D.Camera>, isDragging: Ref<boolean>) {
  const zoneEditorStore = useZoneEditorStore()
  const isZoneEditorActive = computed(() => zoneEditorStore.active)

  const gameHandlers = useGamePointerHandlers(scene, layer, waypoint, camera)
  const zoneEditorHandlers = useZoneEditorPointerHandlers(scene, layer, waypoint, camera, isDragging)

  const setupPointerHandlers = () => {
    if (isZoneEditorActive.value) {
      zoneEditorHandlers.setupPointerHandlers()
    } else {
      gameHandlers.setupPointerHandlers()
    }
  }

  const cleanupPointerHandlers = () => {
    if (isZoneEditorActive.value) {
      zoneEditorHandlers.cleanupPointerHandlers()
    } else {
      gameHandlers.cleanupPointerHandlers()
    }
  }

  return { setupPointerHandlers, cleanupPointerHandlers }
}
