<%#
 Copyright 2013-2026 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
import React, { Suspense } from 'react';
import { Route<% if (communicationSpringWebsocket) { %>, useLocation<% } %> } from 'react-router';
<%_ if (applicationTypeGateway && microfrontend) { _%>
import { importRemote } from '@module-federation/utilities';
<%_ } _%>

<%_ if (!authenticationTypeOauth2) { _%>
import Login from 'app/modules/login/login';
<%_ } _%>
<%_ if (authenticationTypeOauth2) { _%>
import LoginRedirect from 'app/modules/login/login-redirect';
<%_ } _%>
<%_ if (generateUserManagement) { _%>
import Register from 'app/modules/account/register/register';
import Activate from 'app/modules/account/activate/activate';
import PasswordResetInit from 'app/modules/account/password-reset/init/password-reset-init';
import PasswordResetFinish from 'app/modules/account/password-reset/finish/password-reset-finish';
<%_ } _%>
import Logout from 'app/modules/login/logout';
import Home from 'app/modules/home/home';
import EntitiesRoutes from 'app/entities/routes';
import PrivateRoute from 'app/shared/auth/private-route';
import ErrorBoundaryRoutes from 'app/shared/error/error-boundary-routes';
import PageNotFound from 'app/shared/error/page-not-found';
import { Authority } from 'app/shared/jhipster/constants';
<%_ if (communicationSpringWebsocket) { _%>
import { sendActivity } from 'app/config/websocket-middleware';
<%_ } _%>

const loading = <div>loading ...</div>;
<%_ if (generateUserManagement) { _%>

const Account = React.lazy(() => import(/* webpackChunkName: "account" */ 'app/modules/account'));
<%_ } _%>

const Admin = React.lazy(() => import(/* webpackChunkName: "administration" */ 'app/modules/administration'));
<%_ if (applicationTypeGateway && microfrontend) { _%>

  <%_ for (const remote of microfrontends) { _%>
const <%= remote.capitalizedBaseName %>Routes = React.lazy(() => importRemote<any>({
  url: `./services/<%= remote.lowercaseBaseName %>`,
  scope: '<%= remote.lowercaseBaseName %>',
  module: './entities-routes',
}).catch(() => import('app/shared/error/error-loading')));

  <%_ } _%>
<%_ } _%>
const AppRoutes = () => {
<%_ if (communicationSpringWebsocket) { _%>
  const pageLocation = useLocation();
  React.useEffect(() => {
    sendActivity(pageLocation.pathname);
  }, [pageLocation]);
<%_ } _%>
  return (
    <div className="view-routes">
      <Suspense fallback={loading}>
        <ErrorBoundaryRoutes>
          <Route index element={<Home />} />
<%_ if (!authenticationTypeOauth2) { _%>
          <Route path="login" element={<Login />} />
<%_ } _%>
          <Route path="logout" element={<Logout />} />
<%_ if (generateUserManagement) { _%>
          <Route path="account">
            <Route
              path="*"
              element={
                <PrivateRoute hasAnyAuthorities={[Authority.ADMIN, Authority.USER]}>
                  <Account />
                </PrivateRoute>
              }
            />
            <Route path="register" element={<Register />} />
            <Route path="activate" element={<Activate />} />
            <Route path="reset">
              <Route path="request" element={<PasswordResetInit />} />
              <Route path="finish" element={<PasswordResetFinish />} />
            </Route>
          </Route>
<%_ } _%>
          <Route
            path="admin/*"
            element={
              <PrivateRoute hasAnyAuthorities={[Authority.ADMIN]}>
                <Admin />
              </PrivateRoute>
            }
          />
<%_ if (authenticationTypeOauth2) { _%>
          <Route path="sign-in" element={<LoginRedirect />} />
<%_ } _%>
<%_ if (applicationTypeGateway && microfrontend) { _%>
  <%_ for (const remote of microfrontends) { _%>
          <Route
            path="<%= remote.lowercaseBaseName %>/*"
            element={
              <PrivateRoute hasAnyAuthorities={[Authority.USER]}>
                <<%= remote.capitalizedBaseName %>Routes />
              </PrivateRoute>
            }
          />
  <%_ } _%>
<%_ } _%>
          <Route
            path="<%= microfrontend && applicationTypeMicroservice ? lowercaseBaseName + '/' : '' %>*"
            element={
              <PrivateRoute hasAnyAuthorities={[Authority.USER]}>
                <EntitiesRoutes />
              </PrivateRoute>
            }
          />
          <Route path="*" element={<PageNotFound />} />
        </ErrorBoundaryRoutes>
      </Suspense>
    </div>
  );
};

export default AppRoutes;
