import { lazy } from 'react';
import { useEffect } from "react";

// project import
import Loadable from 'components/Loadable';
// import MinimalLayout from 'layout/MinimalLayout';
import MainLayout from 'layout/MainLayout';
import { Navigate } from 'react-router-dom';

// render - login
const AuthLogin = Loadable(lazy(() => import('pages/authentication/Login')));
const AuthRegister = Loadable(lazy(() => import('pages/authentication/RegisterCustom')));
const RegisterForm = Loadable(lazy(() => import('pages/authentication/Register')));
const BusRegisterForm = Loadable(lazy(() => import('pages/authentication/BusRegister')));
const IAmSmartRegister = Loadable(lazy(() => import('pages/authentication/IAmSmartRegister')));
const ErrorPage = Loadable(lazy(() => import('pages/extra-pages/ErrorPage')));
const PrivacyPolicyPage = Loadable(lazy(() => import('pages/extra-pages/PrivacyPolicyPage')));
const ImportantNoticePage = Loadable(lazy(() => import('pages/extra-pages/ImportantNoticePage')));
const UserMenuPub1Page = Loadable(lazy(() => import('pages/extra-pages/UserMenuPub1')));
const DatabaseHealthCheckPage = Loadable(lazy(() => import('pages/extra-pages/DatabaseHealthCheck')));


const ForgotPassword = Loadable(lazy(() => import('pages/authentication/ForgotPassword')));
const AfterForgotPasswordPage = Loadable(lazy(() => import('pages/authentication/ForgotPassword/AfterForgotPasswordPage')));
const ForgotPassword_Callback = Loadable(lazy(() => import('pages/authentication/ForgotPassword/AuthCallback')));
const ForgotPassword_Success = Loadable(lazy(() => import('pages/authentication/ForgotPassword/AuthCallback/ResetPasswordSuccess')));

const ForgotUsername = Loadable(lazy(() => import('pages/authentication/ForgotUsername')));
const AfterForgotUsernamePage = Loadable(lazy(() => import('pages/authentication/ForgotUsername/AfterForgotUsernamePage')));
const ForgotUsername_Callback = Loadable(lazy(() => import('pages/authentication/ForgotUsername/AuthCallback')));
const ForgotUsername_Success = Loadable(lazy(() => import('pages/authentication/ForgotUsername/AuthCallback/ResetPasswordSuccess')));

const IAmSmart_DirectLoginCallback = Loadable(lazy(() => import('pages/iAmSmart/DirectLoginCallback')));
//const IAmSmart_FallCallback = Loadable(lazy(() => import('pages/iAmSmart/FallCallback')));
const IAmSmart_FailCallback = Loadable(lazy(() => import('pages/iAmSmart/FailCallback')));
const FailCallback_VerifyMail = Loadable(lazy(() => import('pages/iAmSmart/FailCallback_VerifyMail')));
const IAmSmart_AuthCallback = Loadable(lazy(() => import('pages/iAmSmart/AuthCallback')));
const IAmSmart_RegistryCallback = Loadable(lazy(() => import('pages/iAmSmart/RegistryCallback')));
const IAmSmart_PleaseLoginCallback = Loadable(lazy(() => import('pages/iAmSmart/PleaseLoginCallback')));

//TODO: this page for testing only, please remove at prod
const VerifyPage = Loadable(lazy(() => import('pages/authentication/Verify')));
const Testfps = Loadable(lazy(() => import('pages/Payment/FPS/FPSTest')));
const Payment_FPS_CallBack = Loadable(lazy(() => import('pages/Payment/FPS/fpscallback')));
// ==============================|| AUTH ROUTING ||============================== //

function ExternalRedirect({ to, replace = true }) {
  useEffect(() => {
    if (replace) window.location.replace(to);
    else window.location.href = to;
  }, [to, replace]);

  return null;
}

const LoginRoutes = {
  path: '/',
  element: <MainLayout />,
  children: [
    {
      path: 'login',
      element: <AuthLogin />
    },
    {
      path: 'register',
      element: <AuthRegister />
    },
    {
      path: 'registerFrom',
      element: <RegisterForm />
    },
    {
      path: 'registerFromOrganization',
      element: <BusRegisterForm />
    },
    {
      path: 'iAmSmartRegisterFrom',
      element: <IAmSmartRegister />
    },
    {
      path: 'error',
      element: <ErrorPage/>
    },
    {
      path: 'privacyPolicy',
      element: <PrivacyPolicyPage/>
    },
    {
      path: 'importantNotice',
      element: <ImportantNoticePage/>
    },
    {
      path: 'aboutUs',
      element: <ExternalRedirect to="https://www.gld.gov.hk/zh-cn/our-services/printing/advertising-gov-gazette/" />
    },
    {	
      path: 'userGuide',	
      element: <Navigate to="/userGuidePub" replace />
    },    
    {
      path: 'userGuidePub',
      element: <UserMenuPub1Page/>
    },
    {	
      path: 'userguide-fi',	
      element: <Navigate to="/userGuidePub" replace />
    },
    {
      path: 'databaseHealthCheck',
      element: <DatabaseHealthCheckPage/>
    },
    {
      path: 'iamsmart/logincallback',
      element: <IAmSmart_DirectLoginCallback/>
    },
    {
      path: 'iamsmart/loginfallback',
      element: <IAmSmart_FailCallback/>
    },
    {
      path: 'iamsmart/notverify',
      element: <FailCallback_VerifyMail/>
    },
    {
      path: 'iamsmart/authcallback',
      element: <IAmSmart_AuthCallback/>
    },
    {
      path: 'iamsmart/registrycallback',
      element: <IAmSmart_RegistryCallback/>
    },
    {
      path: 'iamsmart/pleaseLogin',
      element: <IAmSmart_PleaseLoginCallback/>
    },
    {
      path: 'iamsmart/loginFail',
      element: <IAmSmart_FailCallback/>
    },
    {
      path: 'verify/:verifyCode/:email',
      element: <VerifyPage/>
    },
    {
      path: 'testfps',
      element: <Testfps/>
    },
    {
      path: 'testfpscallback',
      element: <Payment_FPS_CallBack/>
    },
    {
      path: 'forgot/password',
      element: <ForgotPassword/>
    },
    {
      path: 'forgot/password/sent',
      element: <AfterForgotPasswordPage/>
    },
    {
      path: 'forgot/password/verify/:verifyCode/:email',
      element: <ForgotPassword_Callback/>
    },
    {
      path: 'forgot/password/success',
      element: <ForgotPassword_Success/>
    },
    {
      path: 'forgot/username',
      element: <ForgotUsername/>
    },
    {
      path: 'forgot/username/sent',
      element: <AfterForgotUsernamePage/>
    },
    {
      path: 'forgot/username/verify/:verifyCode/:email',
      element: <ForgotUsername_Callback/>
    },
    {
      path: 'forgot/username/success',
      element: <ForgotUsername_Success/>
    },
  ]
};

export default LoginRoutes;
