import { CssBaseline, ThemeProvider } from "@mui/material";
import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment";
import { ruRU } from '@mui/x-date-pickers/locales';
import LoadingSkeleton from "@ui_kit/LoadingSkeleton";
import { handleComponentError } from "@utils/handleComponentError";
import moment from "moment";
import { SnackbarProvider } from 'notistack';
import { Suspense } from "react";
import { ErrorBoundary } from "react-error-boundary";
import { SWRConfig } from "swr";
import { ApologyPage } from "./pages/ViewPublicationPage/ApologyPage";
import { ViewPage } from "./pages/ViewPublicationPage/ViewPublicationPage";
import lightTheme from "./utils/themes/light";


moment.locale("ru");
const localeText = ruRU.components.MuiLocalizationProvider.defaultProps.localeText;

export default function QuizAnswerer() {

    return (
        <SWRConfig value={{
            revalidateOnFocus: false,
            shouldRetryOnError: false,
        }}>
            <LocalizationProvider dateAdapter={AdapterMoment} adapterLocale="ru" localeText={localeText}>
                <ThemeProvider theme={lightTheme}>
                    <SnackbarProvider
                        preventDuplicate={true}
                        style={{ backgroundColor: lightTheme.palette.brightPurple.main }}
                    >
                        <CssBaseline />
                        <ErrorBoundary
                            fallback={<ApologyPage message="Что-то пошло не так" />}
                            onError={handleComponentError}
                        >
                            <Suspense fallback={<LoadingSkeleton />}>
                                <ViewPage />
                            </Suspense>
                        </ErrorBoundary>
                    </SnackbarProvider>
                </ThemeProvider>
            </LocalizationProvider>
        </SWRConfig>
    );
} 
