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

import {EnvironmentSpecificResolver} from './openaireLibrary/utils/properties/environmentSpecificResolver';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';

import {OpenaireErrorPageComponent} from './error/errorPage.component';
import {AdminLoginGuard} from "./openaireLibrary/login/adminLoginGuard.guard";

const routes: Routes = [
  {
    path: 'reload',
    loadChildren: './reload/libReload.module#LibReloadModule',
    data: {hasSidebar: false, hasHeader: false}
  },
  {
    path: 'user-info',
    loadChildren: './login/libUser.module#LibUserModule',
    data: {hasSidebar: false, isFrontPage: true}
  },
  {
    path: 'error',
    component: OpenaireErrorPageComponent,
    data: {hasSidebar: false, isFrontPage: true}
  },
  {
    path: 'admin',
    loadChildren: './manageStakeholders/manageStakeholders.module#ManageStakeholdersModule',
    data: {hasAdminMenu: true}
  },
  {
    path: 'admin/admin-tools',
    loadChildren: './admin-tools/portal-admin-tools-routing.module#PortalAdminToolsRoutingModule',
    canActivate: [AdminLoginGuard],
    data: {hasAdminMenu: true}
  },
  {
    path: 'admin/monitor/admin-tools',
    loadChildren: './admin-tools/admin-tools-routing.module#AdminToolsRoutingModule',
    canActivate: [AdminLoginGuard],
    data: {hasAdminMenu: true, portal: 'monitor'}
  },
  {
    path: 'admin/:stakeholder',
    loadChildren: './admin-stakeholder/admin-stakeholder-routing.module#AdminStakeholderRoutingModule',
  },
  {path: 'theme', loadChildren: './openaireLibrary/utils/theme/theme.module#ThemeModule'},
  {
    path: '',
    loadChildren: './monitor/monitor.module#MonitorModule',
    data: {isFrontPage: true}
  },
  {
    path: '**',
    pathMatch: 'full',
    component: OpenaireErrorPageComponent,
    data: {hasSidebar: false, hasAdminMenu: false, isFrontPage: true}
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    preloadingStrategy: PreloadAllModules,
    scrollPositionRestoration: "top",
    onSameUrlNavigation: "reload",
    relativeLinkResolution: 'corrected'
  })],
  exports: [RouterModule],
  providers: [EnvironmentSpecificResolver, EnvironmentSpecificService]
})
export class AppRoutingModule {
}
