import { create } from 'zustand'
import { persist } from 'zustand/middleware'

interface AppState {
  sidebarOpen: boolean
  mobileMenuOpen: boolean
  themeHue: string
  cmdKOpen: boolean
  toggleSidebar: () => void
  setMobileMenu: (open: boolean) => void
  setThemeHue: (hue: string) => void
  setCmdKOpen: (open: boolean) => void
}

export const useAppStore = create<AppState>()(
  persist(
    (set) => ({
      sidebarOpen: true,
      mobileMenuOpen: false,
      themeHue: '145', // Default emerald
      cmdKOpen: false,
      toggleSidebar: () => set(s => ({ sidebarOpen: !s.sidebarOpen })),
      setMobileMenu: (open) => set({ mobileMenuOpen: open }),
      setThemeHue: (hue) => set({ themeHue: hue }),
      setCmdKOpen: (open) => set({ cmdKOpen: open }),
    }),
    {
      name: 'app-storage',
      partialize: (state) => ({ themeHue: state.themeHue, sidebarOpen: state.sidebarOpen }),
    }
  )
)
