import Cookies from 'js-cookie'
import { getLanguage } from '@/i18n'

const state = {
  language: getLanguage()
}

const mutations = {
  /**
   * 设置语言
   * @param {Object} state - 状态对象
   * @param {string} language - 语言代码
   */
  SET_LANGUAGE: (state, language) => {
    state.language = language
    Cookies.set('language', language)
  }
}

const actions = {
  /**
   * 设置语言
   * @param {Object} context - 上下文对象
   * @param {string} language - 语言代码
   */
  setLanguage({ commit }, language) {
    commit('SET_LANGUAGE', language)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
} 