import { defineStore } from "pinia";

export const useGlobalStore = defineStore("globalStore", {
  state: () => ({
    isLoading: false,
    isDrawerVisible: false,
    locale: localStorage.getItem("locale") ?? "en",
  }),
  getters: {
    getIsLoading: (state) => state.isLoading,
    getIsDrawerVisible: (state) => state.isDrawerVisible,
    getCurrentLocale: (state) => state.locale,
  },
  actions: {
    changeLoadingStatus(value) {
      this.isLoading = value;
    },
    changeDrawerVisibility() {
      this.isDrawerVisible = !this.isDrawerVisible;
    },
    changeCurrentLocale(newLocale) {
      this.locale = newLocale;
      localStorage.setItem("locale", newLocale);
    },
  },
});
