import type {} from '@redux-devtools/extension';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';

interface GuestBookState {
  theme: 'dark' | 'light' | undefined;
  currentSession: [string | undefined, string | undefined];
  setTheme: (theme: GuestBookState['theme']) => void;
  setCurrentSession: (session: GuestBookState['currentSession']) => void;
}

const useGuestBookStore = create<GuestBookState>()(
  devtools(
    persist(
      (set) => ({
        theme: undefined,
        currentSession: [undefined, undefined],
        setTheme: (theme: GuestBookState['theme']) => set(() => ({ theme })),
        setCurrentSession: (session: GuestBookState['currentSession']) =>
          set(() => ({
            currentSession: session,
          })),
      }),
      {
        name: 'guestbook-storage',
      }
    )
  )
);

export default useGuestBookStore;
