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

import { DefaultLayoutComponent } from '@app/layouts/components/default.layout.component';
import { NoNaviLayoutComponent } from '@app/layouts/components/no-navi.layout.component';

import { AppAuthenticationGuard } from '@app/guards/app-authentication.guard';
import { AppSessionResolver } from './resolvers/app-session.resolver';

const routes: Routes = [
  {
    path: '',
    redirectTo: '/group/(content:index)',
    pathMatch: 'full'
  },
  {
    path: 'account',
    component: NoNaviLayoutComponent,
    loadChildren: () =>
      import('./pages/account/account.page.module').then(
        (m) => m.AppAccountPageModule
      )
  },
  {
    path: 'common',
    component: NoNaviLayoutComponent,
    loadChildren: () =>
      import('./pages/common/common.page.module').then(
        (m) => m.AppCommonPageModule
      )
  },
  {
    path: '',
    component: DefaultLayoutComponent,
    canActivate: [AppAuthenticationGuard],
    resolve: {
      authentication: AppSessionResolver
    },
    children: [
      {
        path: 'organization',
        loadChildren: () =>
          import('./pages/organization/organization.page.module').then(
            (m) => m.AppOrganizationPageModule
          )
      },
      {
        path: 'group',
        loadChildren: () =>
          import('./pages/group/group.page.module').then(
            (m) => m.AppGroupPageModule
          )
      },
      {
        path: 'chat',
        loadChildren: () =>
          import('./pages/chat/chat.page.module').then(
            (m) => m.AppChatPageModule
          )
      },
      {
        path: 'call',
        loadChildren: () =>
          import('./pages/call/call.page.module').then(
            (m) => m.AppCallPageModule
          )
      },
      {
        path: 'message',
        loadChildren: () =>
          import('./pages/message/message.page.module').then(
            (m) => m.AppMessagePageModule
          )
      }
    ]
  },
  {
    path: '**',
    redirectTo: '/common/e404'
  }
];

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