import {NgModule} from '@angular/core'
import {PreloadAllModules, RouterModule, Routes} from '@angular/router'
import {AuthGuard, redirectUnauthorizedTo} from '@angular/fire/auth-guard'

const routes: Routes = [
  {
    path: 'login',
    loadChildren: () => import('./login/login.module').then(m => m.LoginPageModule),
  },
  {
    path: 'channel/:channelName',
    loadChildren: () => import('./channel/channel.module').then(m => m.ChannelPageModule),
    canActivate: [AuthGuard],
    data: {authGuardPipe: () => redirectUnauthorizedTo(['login'])},
  },
  {
    path: '',
    pathMatch: 'full',
    redirectTo: 'channel/General',
  },
  {
    path: 'new-channel',
    loadChildren: () => import('./new-channel/new-channel.module').then(m => m.NewChannelPageModule),
  },
]

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