import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { Tile, Object, Sprite, CharacterType, CharacterHair, Item } from '@/types'

export const useAssetManagerStore = defineStore('assetManager', () => {
  const tileList = ref<Tile[]>([])
  const selectedTile = ref<Tile | null>(null)

  const objectList = ref<Object[]>([])
  const selectedObject = ref<Object | null>(null)

  const spriteList = ref<Sprite[]>([])
  const selectedSprite = ref<Sprite | null>(null)

  const characterTypeList = ref<CharacterType[]>([])
  const selectedCharacterType = ref<CharacterType | null>(null)

  const characterHairList = ref<CharacterHair[]>([])
  const selectedCharacterHair = ref<CharacterHair | null>(null)

  const itemList = ref<Item[]>([])
  const selectedItem = ref<Item | null>(null)

  function setTileList(tiles: Tile[]) {
    tileList.value = tiles
  }

  function setSelectedTile(tile: Tile | null) {
    selectedTile.value = tile
  }

  function setObjectList(objects: Object[]) {
    objectList.value = objects
  }

  function setSelectedObject(object: Object | null) {
    selectedObject.value = object
  }

  function setSpriteList(sprites: Sprite[]) {
    spriteList.value = sprites
  }

  function setSelectedSprite(sprite: Sprite | null) {
    selectedSprite.value = sprite
  }

  function setCharacterTypeList(characterTypes: CharacterType[]) {
    characterTypeList.value = characterTypes
  }

  function setSelectedCharacterType(characterType: CharacterType | null) {
    selectedCharacterType.value = characterType
  }

  function setCharacterHairList(characterHair: CharacterHair[]) {
    characterHairList.value = characterHair
  }

  function setSelectedCharacterHair(characterHair: CharacterHair | null) {
    selectedCharacterHair.value = characterHair
  }

  function setItemList(items: Item[]) {
    itemList.value = items
  }

  function setSelectedItem(item: Item | null) {
    selectedItem.value = item
  }

  return {
    tileList,
    selectedTile,
    objectList,
    selectedObject,
    spriteList,
    selectedSprite,
    characterTypeList,
    selectedCharacterType,
    characterHairList,
    selectedCharacterHair,
    itemList,
    selectedItem,
    setTileList,
    setSelectedTile,
    setObjectList,
    setCharacterTypeList,
    setSelectedObject,
    setSpriteList,
    setSelectedSprite,
    setSelectedCharacterType,
    setCharacterHairList,
    setSelectedCharacterHair,
    setItemList,
    setSelectedItem
  }
})
