import defaultModuleSettings from "./defaults";
import {Action, rootReducer} from "./reducers";
import ExamEditorStore from "./types";
import {create} from "zustand";

const useExamEditorStore = create<
	ExamEditorStore & {
		dispatch: (action: Action) => void;
	}
>((set) => ({
	title: "",
	globalEdit: [],
	currentModule: "reading",
	speakingAvatars: [],
	modules: {
		reading: defaultModuleSettings("reading", 60),
		writing: defaultModuleSettings("writing", 60),
		speaking: defaultModuleSettings("speaking", 14),
		listening: defaultModuleSettings("listening", 30),
		level: defaultModuleSettings("level", 60),
	},
	dispatch: (action) => set((state) => rootReducer(state, action)),
}));

export default useExamEditorStore;
