"use client";
import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFnsV3";
import { AppStore, persistor, store } from '../lib/store'
import { useRef } from "react";
import { Provider } from "react-redux";
import { StyledEngineProvider } from "@mui/material";
import { PersistGate } from "redux-persist/integration/react";
import { GuardedRoute } from "./RouteGuard";
import { I18nextProvider } from "react-i18next";
import i18n from "../lib/i18n";
export default function AppProvider({children}:{children: React.ReactNode}) {
    return (
        <I18nextProvider i18n={i18n}>
            <LocalizationProvider dateAdapter={AdapterDateFns}>  
                <Provider store={store}>
                    <PersistGate loading={null} persistor={persistor}>
                        <StyledEngineProvider injectFirst>
                            <GuardedRoute>
                                {children}
                            </GuardedRoute>
                        </StyledEngineProvider>
                    </PersistGate>
                </Provider>
            </LocalizationProvider>
        </I18nextProvider>
    )
}