import { create } from 'zustand';
import { PreferencesState } from '../interfaces/preferences';

export const usePrefStore = create<PreferencesState>(() => ({
    darkMode: false
}));

const getDarkMode = () => {
    const darkMode = localStorage.getItem('darkMode')
    usePrefStore.setState(() => ({ darkMode: darkMode?.toLowerCase() === "true" ? true : false }))
    return darkMode
}

const setDarkMode = (darkMode: boolean) => {
    localStorage.setItem('darkMode', JSON.stringify(darkMode))
    usePrefStore.setState(() => ({ darkMode: darkMode }))
}

export {
    getDarkMode,
    setDarkMode
}