import { IUserCity } from '@/types/app-type'
import { defineStore } from 'pinia'
import { ref } from 'vue'

const initState = {
  cities: [],
}

export const useCityStore = defineStore(
  'city',
  () => {
    const userCity = ref<IUserCity>({ ...initState })

    const setCities = (val: Array<any>) => {
      userCity.value.cities = val
    }

    const clearUserCity = () => {
      userCity.value = { ...initState }
    }
    // 一般没有reset需求，不需要的可以删除
    const reset = () => {
      userCity.value = { ...initState }
    }

    return {
      userCity,
      clearUserCity,
      setCities,

      reset,
    }
  },
  {
    persist: true,
  },
)
