import { Box, 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 moment from "moment";
import { SnackbarProvider } from 'notistack';
import { SWRConfig } from "swr";
import { ViewPage } from "./pages/ViewPublicationPage/ViewPublicationPage";
import lightTheme from "./utils/themes/light";


const defaultQuizId = "ef836ff8-35b1-4031-9acf-af5766bac2b2";

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

interface Props {
    widget?: boolean;
    quizId?: string;
}

export default function App({ widget = false, quizId }: Props) {
    quizId ??= defaultQuizId;

    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 />
                        {widget ? (
                            <Box sx={{
                                width: "100%",
                                height: "100%",
                            }}>
                                <ViewPage quizId={quizId} />
                            </Box>
                        ) : (
                            <Box sx={{
                                height: "100dvh",
                            }}>
                                <ViewPage quizId={quizId} />
                            </Box>
                        )}
                    </SnackbarProvider>
                </ThemeProvider>
            </LocalizationProvider>
        </SWRConfig>
    );
}
