// useAppStore.js
import { defineStore } from 'pinia';
import Cookies from 'js-cookie';

export const useAppStore = defineStore('app', {
  state: () => ({
    sidebar: {
      opened: !+Cookies.get('sidebarStatus'),
      withoutAnimation: false,
    },
    device: 'desktop',
    language: Cookies.get('language') || 'en',
    size: Cookies.get('size') || 'medium',
  }),
  
  actions: {
    toggleSideBar() {
      this.sidebar.opened = !this.sidebar.opened;
      Cookies.set('sidebarStatus', this.sidebar.opened ? 0 : 1);
      this.sidebar.withoutAnimation = false;
    },
    
    closeSideBar(withoutAnimation) {
      this.sidebar.opened = false;
      Cookies.set('sidebarStatus', 1);
      this.sidebar.withoutAnimation = withoutAnimation;
    },
    
    toggleDevice(device) {
      this.device = device;
    },
    
    setLanguage(language) {
      this.language = language;
      Cookies.set('language', language);
    },
    
    setSize(size) {
      this.size = size;
      Cookies.set('size', size);
    },
  },
  persist: true
});