// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { AuthGuard } from './guards/AuthGuard';
import { PublicOrAuthGuard } from './guards/PublicOrAuthGuard';
import { ProfiloComponent } from './pages/profilo/profilo.page';
import { AppLayoutComponent } from './components/app-layout/app-layout.component';

const routes: Routes = [
	{
		path: '',
		component: AppLayoutComponent,
		children: [
			{
				path: 'servizi',
				loadChildren: () => import('./pages/home/home.module').then((m) => m.HomePageModule),
				// Servizi/Categorie richiedono il login anche su MyTown (solo la bacheca è pubblica).
				canActivate: [AuthGuard],
			},
			{
				path: 'home',
				redirectTo: 'servizi',
				pathMatch: 'full',
			},
			{
				path: 'notifications',
				loadChildren: () => import('./pages/notifications/notifications.module').then((m) => m.NotificationsPageModule),
				canActivate: [AuthGuard],
			},
			{
				path: 'messaging',
				loadChildren: () => import('./pages/messaging/messaging.module').then((m) => m.MessagingModule),
				canActivate: [AuthGuard],
			},
			{
				path: 'profile',
				component: ProfiloComponent,
				canActivate: [AuthGuard],
			},
			{
				path: 'bakeka',
				loadChildren: () => import('./pages/eventboard/eventboard.module').then((m) => m.EventboardModule),
				canActivate: [PublicOrAuthGuard],
			},
			{
				path: 'portale/:prt_id/company/:cmp_id/service',
				canActivate: [AuthGuard],
				children: [
					{
						path: 'calendario-appuntamenti',
						loadChildren: () => import('./pages/gestione-appuntamenti/gestione-appuntamenti.module').then((m) => m.GestioneAppuntamentiModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'biz-appointments',
						loadChildren: () => import('./pages/biz-appointments/biz-appointments.module').then((m) => m.BizAppointmentsModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'assemblee',
						loadChildren: () => import('./pages/assemblee/assemblee.module').then((m) => m.AssembleeModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'condounits',
						loadChildren: () => import('./pages/condo-units/condo-units.module').then((m) => m.CondoUnitsModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'cantieri',
						loadChildren: () => import('./pages/cantieri/cantieri.module').then((m) => m.CantieriModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'sopralluoghi-cmp',
						loadChildren: () => import('./pages/sopralluoghi-cmp/sopralluoghi-cmp.module').then((m) => m.SopralluoghiCmpModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'prenotazioni',
						loadChildren: () => import('./pages/gestione-prenotazioni/gestione-prenotazioni.module').then((m) => m.GestionePrenotazioniPageModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'onlineshop',
						loadChildren: () => import('./pages/onlineshop/onlineshop.module').then((m) => m.OnlineshopModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'workflow',
						loadChildren: () => import('./pages/workflow/workflow.module').then((m) => m.WorkflowModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'fotovoltaico',
						loadChildren: () => import('./pages/fotovoltaico/fotovoltaico.module').then((m) => m.FotovoltaicoModule),
						canActivate: [AuthGuard],
					},
					{
						path: 'turismo',
						loadChildren: () => import('./pages/turismo/turismo.module').then((m) => m.TurismoModule),
						canActivate: [AuthGuard],
					},
				],
			},
		],
	},
	{
		path: 'login',
		loadChildren: () => import('./pages/login/login.module').then((m) => m.LoginPageModule),
	},
];

@NgModule({
	imports: [RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })],
	exports: [RouterModule],
})
export class AppRoutingModule {}
