import {Module} from "@/interfaces";
import {Exam, UserSolution} from "@/interfaces/exam";
import {create} from "zustand";

export interface PreferencesState {
	isSidebarMinimized: boolean;
	toggleSidebarMinimized: () => void;
	setSidebarMinimized: (isMinimized: boolean) => void;
}

export const initialState = {
	isSidebarMinimized: true,
};

const usePreferencesStore = create<PreferencesState>((set) => ({
	...initialState,
	setSidebarMinimized: (isMinimized: boolean) =>
		set(() => {
			localStorage.setItem("isSidebarMinimized", isMinimized.toString());

			return {isSidebarMinimized: isMinimized};
		}),
	toggleSidebarMinimized: () =>
		set((state) => {
			localStorage.setItem("isSidebarMinimized", (!state.isSidebarMinimized).toString());

			return {isSidebarMinimized: !state.isSidebarMinimized};
		}),
	reset: () => set(() => initialState),
}));

export default usePreferencesStore;
