// project import
import Routes from 'routes';
import ThemeCustomization from 'themes';
import Locales from 'components/Locales';
// import RTLLayout from 'components/RTLLayout';
import ScrollTop from 'components/ScrollTop';
import Snackbar from 'components/@extended/Snackbar';
import Notistack from 'components/third-party/Notistack';
import { useNavigate } from 'react-router';
import { useEffect } from 'react';
import { generateToken, initFirebaseNotificationListener } from 'firebase_notification/notification';
import InternetStatus from 'components/updateNetworkStatus';
import useInactivityLogout from 'hooks/useInactivityLogout';

// auth-provider
// import { JWTProvider as AuthProvider } from 'contexts/JWTContext';

// ==============================|| APP - THEME, ROUTER, LOCAL  ||============================== //

const App = () => {
  const navigate = useNavigate();
  useEffect(() => {
    if (!localStorage.getItem('authname')) {
      navigate('/login');
    }
  }, [navigate]);

  const AppContent = () => {
    useInactivityLogout();

    useEffect(() => {
      generateToken();
      initFirebaseNotificationListener();
    }, []);

    return (
      <>
        <Routes />
        <Snackbar />
      </>
    );
  };

  return (
    <>
      <ThemeCustomization>
        <InternetStatus />
        {/* <RTLLayout> */}
        <Locales>
          <ScrollTop>
            {/* <AuthProvider> */}
            <>
              <Notistack>
                {/* <Routes />
                <Snackbar /> */}
                <AppContent />
              </Notistack>
            </>
            {/* </AuthProvider> */}
          </ScrollTop>
        </Locales>
        {/* </RTLLayout> */}
      </ThemeCustomization>
    </>
  );
};
export default App;
