import "@/styles/globals.css";
import "react-toastify/dist/ReactToastify.css";
import type {AppProps} from "next/app";

import "primereact/resources/themes/lara-light-indigo/theme.css";
import "primereact/resources/primereact.min.css";
import "primeicons/primeicons.css";
import "react-datepicker/dist/react-datepicker.css";
import {useRouter} from "next/router";
import {useEffect} from "react";
import useExamStore from "@/stores/examStore";
import usePreferencesStore from "@/stores/preferencesStore";
import axios from "axios";

export default function App({Component, pageProps}: AppProps) {
	const {reset} = useExamStore((state) => state);
	const setIsSidebarMinimized = usePreferencesStore((state) => state.setSidebarMinimized);

	const router = useRouter();

	useEffect(() => {
		if (router.pathname !== "/exercises") reset();
	}, [router.pathname, reset]);

	useEffect(() => {
		if (localStorage.getItem("isSidebarMinimized")) {
			if (localStorage.getItem("isSidebarMinimized") === "true") {
				setIsSidebarMinimized(true);
			} else {
				setIsSidebarMinimized(false);
			}
		}
	}, [setIsSidebarMinimized]);

	return <Component {...pageProps} />;
}
