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

import { NcInternalAuthGuard, NcExternalAuthGuard } from '@ng-cortex/core';
import { NcRegisterComponent } from './nc-register/nc-register.component';
import { NcLoginComponent } from './nc-login/nc-login.component';
import { NcE403Component } from './nc-e403/nc-e403.component';
import { NcE404Component } from './nc-e404/nc-e404.component';
import { NcE500Component } from './nc-e500/nc-e500.component';
import { NcLayoutComponent } from './nc-layout/nc-layout.component';
import { NcHomeComponent } from './nc-home/nc-home.component';
import { NcAccountComponent } from './nc-account/nc-account.component';
import { NcBridgeComponent } from './nc-bridge/nc-bridge.component';

const routes: Routes = [
  {
    path: `register`,
    data: { title: `注册` },
    component: NcRegisterComponent,
    canActivate: [NcExternalAuthGuard]
  },
  {
    path: `login`,
    data: { title: `登录` },
    component: NcLoginComponent,
    canActivate: [NcExternalAuthGuard]
  },
  {
    path: `403`,
    data: { title: `无权限访问` },
    component: NcE403Component
  },
  {
    path: `404`,
    data: { title: `页面不存在` },
    component: NcE404Component
  },
  {
    path: `500`,
    data: { title: `服务器错误` },
    component: NcE500Component
  },
  {
    path: ``,
    component: NcLayoutComponent,
    children: [
      {
        path: ``,
        data: { title: `首页` },
        component: NcHomeComponent
      },
      {
        path: `account`,
        data: { title: `个人中心`, reuse: true },
        component: NcAccountComponent
      }
    ],
    canActivate: [NcInternalAuthGuard],
    canActivateChild: [NcInternalAuthGuard]
  },
  {
    path: `**`,
    data: { title: `加载中...` },
    component: NcBridgeComponent
  }
];

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