import { defineStore } from "pinia";

const STORAGE_KEY = "user_language";

export const useLanguageStore = defineStore("language", {
  state: () => ({
    // 优先从 localStorage 获取，否则默认为中文
    locale: localStorage.getItem(STORAGE_KEY) || "zh",
  }),
  actions: {
    setLocale(newLocale) {
      this.locale = newLocale;
      // 将新设置存入 localStorage
      localStorage.setItem(STORAGE_KEY, newLocale);
    },
  },
});
