import { ExtraOptions, RouterModule, Routes } from '@angular/router';
import { NgModule } from '@angular/core';
import {
  NbAuthComponent,
  NbLogoutComponent,
  NbRegisterComponent,
  NbRequestPasswordComponent,
  NbResetPasswordComponent,
} from '@nebular/auth';
import { AuthGuardService } from './services/auth.guard.service';
import { LoginComponent } from './login/login.component';
import { Role } from './entity/Auth';

export const routes: Routes = [
  {
    path: 'invitation',
    loadChildren: () => import('./invitation/invitation.module')
      .then(m => m.InvitationModule),
  },
  {
    path: 'auth',
    component: NbAuthComponent,
    children: [
      {
        path: '',
        component: LoginComponent,
      },
      {
        path: 'login',
        component: LoginComponent,
      },
      {
        path: 'googleLoginCallback',
        component: LoginComponent,
      },
      {
        path: 'lineLogin',
        component: LoginComponent,
      },
      {
        path: 'register',
        component: NbRegisterComponent,
      },
      {
        path: 'logout',
        component: NbLogoutComponent,
      },
      {
        path: 'request-password',
        component: NbRequestPasswordComponent,
      },
      {
        path: 'reset-password',
        component: NbResetPasswordComponent,

      },
    ],
  },
  {
    path: 'Admin', loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule),
    canActivateChild: [AuthGuardService],
    data: {
      roles: Role.Admin | Role.Pastor
    }
    //canActivateChild:[AuthGuardService]
  },
  {
    path: 'games', loadChildren: () => import('./games/games.module').then(m => m.GamesModule),
    canActivateChild: [AuthGuardService],
    data: {
      roles: Role.All
    }
  },
  {
    path: 'myapp', loadChildren: () => import('./cell-group/cell-group.module').then(m => m.CellGroupModule),
    canActivateChild: [AuthGuardService],
    data: {
      roles: Role.All
    }
  },
  { path: 'home', loadChildren: () => import('./home/home.module').then(m => m.HomeModule) },
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  //{ path: 'Invitation', loadChildren: () => import('./invitation/invitation.module').then(m => m.InvitationModule) },
  { path: '**', redirectTo: 'home' },
];

const config: ExtraOptions = {
  useHash: false,
};

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