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';

const routes: Routes = [
  {
    path: 'reload',
    loadChildren: './reload/libReload.module#LibReloadModule',
    resolve: {envSpecific: EnvironmentSpecificResolver}
  },
  {
    path: 'user-info',
    loadChildren: './login/libUser.module#LibUserModule',
    resolve: {envSpecific: EnvironmentSpecificResolver}
  },
  {
    path: 'error',
    component: OpenaireErrorPageComponent,
    resolve: {envSpecific: EnvironmentSpecificResolver},
    data: {hasSidebar: false}
  },
  {
    path: 'admin',
    loadChildren: './home/home.module#HomeModule',
    resolve: {envSpecific: EnvironmentSpecificResolver}
  },
  {
    path: 'admin/:stakeholder',
    loadChildren: './stakeholder/stakeholder.module#StakeholderModule',
    resolve: {envSpecific: EnvironmentSpecificResolver}
  },
  {
    path: 'admin/:stakeholder/:topic',
    loadChildren: './topic/topic.module#TopicModule',
    resolve: {envSpecific: EnvironmentSpecificResolver}
  },
  {
    path: '',
    loadChildren: './monitor/monitor.module#MonitorModule',
    resolve: {envSpecific: EnvironmentSpecificResolver},
  },
  {
    path: '**',
    pathMatch: 'full',
    component: OpenaireErrorPageComponent,
    resolve: {envSpecific: EnvironmentSpecificResolver},
    data: {hasSidebar: false}
  }
];

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