"use client"

import { create } from "zustand"
import { persist } from "zustand/middleware"
import { debouncedPersistJSONStorage } from "@/lib/stores/debounced-json-storage"
import type { MailThemeMode } from "@/lib/mail-settings/types"

export const DEMO_THEME_STORAGE_KEY = "ultimail-demo-theme"

type DemoThemeState = {
  themeMode: MailThemeMode
  setThemeMode: (mode: MailThemeMode) => void
}

export const useDemoThemeStore = create<DemoThemeState>()(
  persist(
    (set) => ({
      themeMode: "system",
      setThemeMode: (themeMode) => set({ themeMode }),
    }),
    {
      name: DEMO_THEME_STORAGE_KEY,
      storage: debouncedPersistJSONStorage,
      partialize: (s) => ({ themeMode: s.themeMode }),
    }
  )
)
