<template>
  <PlacedMapObject v-for="placedMapObject in items" :tilemap="tilemap" :placedMapObject />
</template>

<script setup lang="ts">
import type { PlacedMapObject as PlacedMapObjectT } from '@/application/types'
import PlacedMapObject from '@/components/game/map/partials/PlacedMapObject.vue'
import { MapStorage } from '@/storage/storages'
import { useMapStore } from '@/stores/mapStore'
import { onMounted, ref } from 'vue'

defineProps<{
  tilemap: Phaser.Tilemaps.Tilemap
}>()

const mapStore = useMapStore()
const mapStorage = new MapStorage()
const items = ref<PlacedMapObjectT[]>([])

onMounted(async () => {
  if (!mapStore.mapId) return

  const map = await mapStorage.get(mapStore.mapId)
  if (!map) return

  items.value = map.placedMapObjects
})
</script>
