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

export type Density = 'compact' | 'regular';

interface PreferencesState {
  density: Density;
  setDensity: (density: Density) => void;
  toggleDensity: () => void;
}

export const usePreferencesStore = create<PreferencesState>()(
  persist(
    (set, get) => ({
      density: 'regular',
      setDensity: (density) => set({ density }),
      toggleDensity: () =>
        set({ density: get().density === 'compact' ? 'regular' : 'compact' }),
    }),
    { name: 'goodgo-preferences' },
  ),
);
