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";
import lightTheme from "./utils/themes/light";


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

interface Props {
    widget?: boolean;
}

export default function App({ widget = false }: Props) {

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