import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { NcAfterLoginGuard, NcBeforeLoginGuard, NcRoute } from '@ng-cortex/core';
import { of } from 'rxjs';

import { NcApplicationBridgeModule } from './nc-application-bridge/nc-application-bridge.module';
import { NcApplicationIndexModule } from './nc-application-index/nc-application-index.module';
import { NcApplicationLayoutModule } from './nc-application-layout/nc-application-layout.module';
import { NcApplicationLayoutComponent } from './nc-application-layout/nc-application-layout.component';
import { NcExceptionModule } from './nc-exception/nc-exception.module';
import { NcLoginModule } from './nc-login/nc-login.module';
import { NcPassportModule } from './nc-passport/nc-passport.module';
import { NcSystemMessageModule } from './nc-system-message/nc-system-message.module';
import { NcSystemMessageDetailModule } from './nc-system-message-detail/nc-system-message-detail.module';

/** 路由配置列表 */
const routes: NcRoute[] = [
    { path: '', redirectTo: '/apps', pathMatch: 'full' },
    { path: 'login', data: { name: '登录' }, loadChildren: () => of(NcLoginModule), canActivate: [NcBeforeLoginGuard] },
    {
        path: 'apps', component: NcApplicationLayoutComponent,
        children: [
            { path: '', data: { name: '首页', unrecord: true }, loadChildren: () => of(NcApplicationIndexModule) },
            { path: 'passport', data: { name: '个人中心', reused: true }, loadChildren: () => of(NcPassportModule) },
            { path: 'system-message', data: { name: '系统消息', reused: true }, loadChildren: () => of(NcSystemMessageModule) },
            { path: 'system-message-detail', data: { name: '系统消息明细', reused: true }, loadChildren: () => of(NcSystemMessageDetailModule) },
            { path: '403', data: { name: '无权限访问', extras: { status: '403', statusMessage: '对不起，您无权访问此页面。' } }, loadChildren: () => of(NcExceptionModule) },
            { path: '404', data: { name: '页面不存在', extras: { status: '404', statusMessage: '对不起，您访问的页面不存在。' } }, loadChildren: () => of(NcExceptionModule) },
            { path: '500', data: { name: '服务器错误', extras: { status: '500', statusMessage: '对不起，服务器出现错误。' } }, loadChildren: () => of(NcExceptionModule) },
            { path: '**', data: { name: '' }, loadChildren: () => of(NcApplicationBridgeModule) }
        ],
        canActivate: [NcAfterLoginGuard],
        canActivateChild: [NcAfterLoginGuard]
    },
    { path: '403', data: { name: '无权限访问', extras: { status: '403', statusMessage: '对不起，您无权访问此页面。', navigateTo: '/', navigateMessage: '返回首页' } }, loadChildren: () => of(NcExceptionModule) },
    { path: '404', data: { name: '页面不存在', extras: { status: '404', statusMessage: '对不起，您访问的页面不存在。', navigateTo: '/', navigateMessage: '返回首页' } }, loadChildren: () => of(NcExceptionModule) },
    { path: '500', data: { name: '服务器错误', extras: { status: '500', statusMessage: '对不起，服务器出现错误。', navigateTo: '/', navigateMessage: '返回首页' } }, loadChildren: () => of(NcExceptionModule) },
    { path: '**', redirectTo: '/404', pathMatch: 'full' }
];

/** 程序路由模块 */
@NgModule({
    imports: [
        RouterModule.forRoot(routes, { useHash: true }),
        NcApplicationLayoutModule
    ],
    exports: [RouterModule]
})
export class AppRoutingModule { }
