import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { AnonymousGuard, AuthAdminGuard, AuthenticatedGuard } from './auth/auth.guard';
import { PageLogin } from './pages/login/login.page';
import { PageNotFound } from './pages/notfound/notfound.page';
import { PageProfile } from './pages/profile/profile.page';

import { PageManagement } from './pages/management/management.page';
import { PagePassword } from './pages/password/password.page';
import { PageTurnover } from './pages/turnover/turnover.page';
import { PageTurnoversManage } from './pages/turnovers/manage/manage.page';
import { PageTurnovers } from './pages/turnovers/turnovers.page';
import { PageUnavailable } from './pages/unavailable/unavailable.page';
import { PageUsers } from './pages/users/users.page';
import { UiMain } from './ui/main/main.ui';


const routes: Routes = [
  { path: 'login', component: PageLogin, canActivate: [AnonymousGuard] },
  {
    path: '', component: UiMain, children: [
      { path: '', component: PageTurnovers, canActivate: [AuthenticatedGuard] },
      { path: 'password', component: PagePassword, canActivate: [AuthenticatedGuard] },
      { path: 'profile', component: PageProfile, canActivate: [AuthenticatedGuard] },
      { path: 'create', component: PageTurnover, canActivate: [AuthenticatedGuard] },
      { path: 't/:id', component: PageTurnover, canActivate: [AuthenticatedGuard] },
      { path: 't', component: PageTurnoversManage, canActivate: [AuthAdminGuard] },
      { path: 'm', component: PageManagement, canActivate: [AuthAdminGuard] },
      { path: 'u', component: PageUsers, canActivate: [AuthAdminGuard] },
      { path: 'u/:username', component: PageProfile, canActivate: [AuthAdminGuard] },
      { path: 'unavailable', component: PageUnavailable },
      { path: '**', component: PageNotFound, pathMatch: 'full', canActivate: [AuthenticatedGuard] }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload' })],
  exports: [RouterModule]
})
export class AppRoutingModule { }
