import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getCookie, setCookie } from '../lib/cookie'

export const useUiStore = defineStore('ui', () => {
  const isRetroMode = ref(getCookie('retro-mode') === '1')
  const menuOpen = ref(false)

  function toggleRetroMode() {
    isRetroMode.value = !isRetroMode.value
    setCookie('retro-mode', isRetroMode.value ? '1' : '0')
    window.scrollTo({ top: 0, behavior: 'instant' })
  }

  function toggleMenu() {
    menuOpen.value = !menuOpen.value
  }

  function closeMenu() {
    menuOpen.value = false
  }

  return { isRetroMode, menuOpen, toggleRetroMode, toggleMenu, closeMenu }
})
