// Utilities
import { defineStore } from 'pinia'
import { computed, reactive, watch } from 'vue'

let prefs = localStorage.getItem('prefs')
prefs = reactive(prefs ? JSON.parse(prefs) : {
  xr: {
    depthSense: true
  },
  ui:{
    lang: 'bg',
    theme: 'light'
  }
})

let snackbar = reactive({
  show: false,
  text: '',
  color: 'info',
  timeout: 3000,
})

watch(prefs, (newPrefs) => {
  localStorage.setItem('prefs', JSON.stringify(newPrefs))
}, { deep: true })

export const useAppStore = defineStore('app', {
  state: () => ({ prefs, snackbar }),
})
