import React, {Suspense, lazy} from 'react';
import {Routes, Route, Navigate, Link} from "react-router-dom";
import {ToastContainer} from "react-toastify";
import ApplicationPage from "./pages/ApplicationPage";
import ServicePage from "./pages/ServicePage";
import ServicesPage from "./pages/ServicesPage";
import Invitations from "./components/Faker/Invitations";
import Buttons from "./components/UI/Z_DesignSystem/Buttons";
import Layout from "./components/UI/Z_DesignSystem/Layout";
import Selects from "./components/UI/Z_DesignSystem/Selects";
import Form from "./components/UI/Z_DesignSystem/Form";
import CalendarTrials from "./components/Widgets/CalendarWidget/CalendarTrials";
import SVGLibrary from "./components/UI/Z_DesignSystem/SVG Library";
import Typographies from "./components/UI/Z_DesignSystem/Typographies";
import Grid from "./components/UI/Z_DesignSystem/Grid";
import UnderConstruction from './components/UI/UnderConstruction/UnderConstruction';
import SettingsCategoryPage from "./pages/SettingsCategoryPage";
import SettingPage from "./pages/SettingPage";
import SettingsCategory from "./components/Settings/SettingsCategory";

const LoginPage = lazy(() => import("./pages/LoginPage"));
const NotFound404Page = lazy(() => import("./pages/NotFound404Page"));
const HomePage = lazy(() => import("./pages/HomePage"));
const AuthProtection = lazy(() => import("./components/Protection/AuthProtection"));
const UnAuthProtection = lazy(() => import("./components/Protection/UnAuthProtection"));
const MainLayout = lazy(() => import("./components/Layouts/MainLayout"));
const DuaPage = lazy(() => import("./pages/DuaPage"));
const LdapReqPage = lazy(() => import("./pages/LdapReqPage"));
const ActivateDuaPage = lazy(() => import("./pages/ActivateDuaPage"));
const NoAuthPages = lazy(() => import("./components/Layouts/NoauthLayout"));
const NewsPage = lazy(() => import("./pages/NewsPage"));
const MessagesPage = lazy(() => import("./pages/MessagesPage"));
const ApplicationsPage = lazy(() => import("./pages/ApplicationsPage"));
const SettingsPage = lazy(() => import("./pages/SettingsPage"));
const ProfileSettingsPage = lazy(() => import("./pages/ProfileSettingsPage"));
const DPassInvitationUserFormPage = lazy(() => import("./pages/DPassInvitationUserFormPage"));
const AvatarManagementPage = lazy(() => import("./pages/AvatarManagementPage"));
const SecondaryPasswordPage = lazy(() => import("./pages/SecondaryPasswordPage"));
const AuthorizationsPage = lazy(() => import("./pages/AuthorizationsPage"));
const DUASignaturesPage = lazy(() => import("./pages/DUASignaturesPage"));
const DUASettingsPage = lazy(() => import("./pages/DUASettingsPage"));


function App() {
    return (
        <>
            <Suspense>

                <Routes>

                    <Route path="/" element={<Navigate to="/login"/>}/>

                    <Route element={<UnAuthProtection/>}>
                        <Route element={<NoAuthPages/>}>
                            <Route path="/login" element={<LoginPage/>}/>
                            <Route path="/ldapcheck" element={<LdapReqPage/>}/>
                            <Route path="/duacreate" element={<DuaPage/>}/>
                        </Route>
                    </Route>


                    <Route element={<AuthProtection/>}>
                        <Route element={<MainLayout/>}>
                            <Route>
                                {/*<Route path="/news" element={<NewsPage/>}/>*/}
                                <Route path="/dashboard" element={<HomePage/>}/>
                                <Route path="/messages" element={<MessagesPage/>}/>
                                {/*<Route path="/avatarmanagement" element={<Navigate to="/settings/avatarmanagement"/>}/>*/}
                                {/* <Route path="/personalfolder" element={"Προσωπικός φάκελος υπαλλήλου"}/> */}
                                <Route
                                    path="/services"
                                >
                                    {/*{content of applications page: the list of applications}*/}
                                    <Route
                                        path=""
                                        element={<ServicesPage/>}
                                    />
                                </Route>
                                <Route path="/settings">
                                    <Route path="" element={<SettingsPage/>}/>
                                    <Route
                                        path=":settings_cat"
                                        element={<SettingsCategoryPage/>}
                                    >
                                        <Route
                                            path=""
                                            element={<SettingsCategory/>}
                                        />

                                        <Route
                                            path=":setting"
                                            element={<SettingPage/>}
                                        />
                                    </Route>
                                    {/*<Route path="profile">*/}
                                    {/*    <Route path="" element={<ProfileSettingsPage/>}/>*/}
                                    {/*    <Route path="secondarypassword/*" element={<SecondaryPasswordPage/>}/>*/}
                                    {/*    <Route path="duasettings/*" element={<DUASettingsPage/>}/>*/}
                                    {/*    <Route path="avatarmanagement/*" element={<AvatarManagementPage/>}/>*/}
                                    {/*    <Route path="authorizations/" element={<AuthorizationsPage/>}/>*/}
                                    {/*    <Route path="duasignatures/" element={<DUASignaturesPage/>}/>*/}
                                    {/*</Route>*/}
                                    {/*<Route path="reminders" element={<UnderConstruction/>}/>*/}
                                    {/*<Route path="notifications" element={<UnderConstruction/>}/>*/}
                                </Route>

                                {/*first we have a route that renders the component with the content of that page and then we have te same route without component to use it with subroutes*/}
                                <Route
                                    path="/applications"
                                >
                                    {/*{content of applications page: the list of applications}*/}
                                    <Route
                                        path=""
                                        element={<ApplicationsPage/>}
                                    />
                                    {/* exmaple: applications/dpass redirects to applications/dpass/services*/}
                                    <Route
                                        path=":application"
                                        element={<Navigate to={'services'}/>}
                                    />
                                    {/*modules/services of single application*/}
                                    <Route
                                        path=":application/services"
                                    >
                                        {/*content of single application -list of modules/services of single application*/}
                                        <Route
                                            path=""
                                            element={<ApplicationPage/>}
                                        />
                                        {/*page of every module*/}
                                        <Route
                                            path=":service/*"
                                            element={<ServicePage/>}
                                        />
                                    </Route>
                                </Route>

                            </Route>
                        </Route>
                    </Route>

                    <Route path="*" element={<NotFound404Page/>}/>

                    {/*PAGES OUTSIDE OF AUTH REQUEST*/}

                    <Route element={<NoAuthPages/>}>
                        <Route
                            path="/activateDua"
                            element={<ActivateDuaPage/>}
                        />

                        {/* PUBLIC PAGE - DPASS INVITATION USER'S FORM   */}
                        <Route
                            path="/visitorInvitationForm"
                            element={<DPassInvitationUserFormPage/>}
                        />
                    </Route>


                    {
                        process.env.NODE_ENV !== "production" &&
                        <>
                            <Route
                                path="/design"
                                element={<Layout/>}
                            >
                                <Route
                                    path="buttons"
                                    element={<Buttons/>}
                                />
                                <Route
                                    path="selects"
                                    element={<Selects/>}
                                />
                                <Route
                                    path="form"
                                    element={<Form/>}
                                />
                                <Route
                                    path="typographies"
                                    element={<Typographies/>}
                                />
                                <Route
                                    path="calendar"
                                    element={<CalendarTrials/>}
                                />
                                <Route
                                    path="svg-library"
                                    element={<SVGLibrary/>}
                                />
                                <Route
                                    path="grid"
                                    element={<Grid/>}
                                />

                            </Route>


                            <Route path="/faker">
                                <Route
                                    path="invitations"
                                    element={<Invitations/>}/>
                            </Route>

                        </>

                    }


                </Routes>

            </Suspense>

            <ToastContainer/>
        </>
    );
}

export default App;
