import type { MapObject, Map as MapT } from '@/application/types'
import { defineStore } from 'pinia'

export type TeleportSettings = {
  toMapId: string
  toPositionX: number
  toPositionY: number
  toRotation: number
}

export const useMapEditorStore = defineStore('mapEditor', {
  state: () => {
    return {
      active: true,
      tool: 'move',
      drawMode: 'tile',
      selectedTile: '',
      selectedMapObject: null as MapObject | null,
      shouldClearTiles: false,
      teleportSettings: {
        toMapId: '',
        toPositionX: 0,
        toPositionY: 0,
        toRotation: 0
      } as TeleportSettings
    }
  },
  actions: {
    setTool(tool: string) {
      this.tool = tool
    },
    setDrawMode(mode: string) {
      this.drawMode = mode
    },
    setSelectedTile(tile: string) {
      this.selectedTile = tile
    },
    setSelectedMapObject(object: MapObject) {
      this.selectedMapObject = object
    },
    setTeleportSettings(teleportSettings: TeleportSettings) {
      this.teleportSettings = teleportSettings
    },
    triggerClearTiles() {
      this.shouldClearTiles = true
    },
    resetClearTilesFlag() {
      this.shouldClearTiles = false
    },
    reset() {
      this.tool = 'move'
      this.drawMode = 'tile'
      this.selectedTile = ''
      this.selectedMapObject = null
      this.shouldClearTiles = false
    }
  }
})
