import { useGameControlsComposable } from '@/composables/controls/useGameControlsComposable'
import { useMapEditorControlsComposable } from '@/composables/controls/useMapEditorControlsComposable'
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
import { computed, type Ref } from 'vue'

export function useControlsComposable(scene: Phaser.Scene, layer: Phaser.Tilemaps.TilemapLayer, waypoint: Ref<{ visible: boolean; x: number; y: number }>) {
  const camera = scene.cameras.main
  const gameHandlers = useGameControlsComposable(scene, layer, waypoint, camera)
  const mapEditorHandlers = useMapEditorControlsComposable(scene, layer, waypoint, camera)

  const mapEditor = useMapEditorComposable()
  const currentHandlers = computed(() => (mapEditor.active.value ? mapEditorHandlers : gameHandlers))

  const setupControls = () => currentHandlers.value.setupControls()
  const cleanupControls = () => currentHandlers.value.cleanupControls()

  return { setupControls, cleanupControls, camera }
}
