import { getItem, setItem } from "@/utils/cache";
import Define from "@/utils/dict/Define";
import { listOptionBrand } from '@/api/toy/brand'

const toy = {
  state: {
    brandList:getItem(Define.CACHE_BRAND_LIST) || [],
  },

  mutations: {
    SET_BRAND_LIST: (state, list) => {
      state.brandList = list
      setItem(Define.CACHE_BRAND_LIST, list)
    },
   },

  actions: {
    GetBrandList({ commit }) {
      return new Promise((resolve, reject) => {
        listOptionBrand().then(({ data }) => {
          commit('SET_BRAND_LIST', data)
          resolve(data)
        }).catch(err => {
          reject(err)
        })
      })
    }
  }
}


export default toy
