/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {HomeComponent} from "./home/home.component";
import {LoginComponent} from "./login/components/login/login.component";
import {SetupComponent} from "./login/components/setup/setup.component";
import {StreampipesComponent} from "./core/components/streampipes/streampipes.component";
import {StandaloneDashboardComponent} from "./dashboard/components/standalone/standalone-dashboard.component";
import {AuthCanActivateChildrenGuard} from "./_guards/auth.can-activate-children.guard";
import {ConfiguredCanActivateGuard} from "./_guards/configured.can-activate.guard";
import {StartupComponent} from "./login/components/startup/startup.component";
import {AlreadyConfiguredCanActivateGuard} from "./_guards/already-configured.can-activate.guard";
import {InfoComponent} from "./info/info.component";
import {NotificationsComponent} from "./notifications/notifications.component";
import {ProfileComponent} from "./profile/profile.component";
import {ApidocsComponent} from "./apidocs/apidocs.component";
import { PageName } from './_enums/page-name.enum';
import { PageAuthGuard } from './_guards/page-auth.can-active.guard';
import { RegisterComponent } from './login/components/register/register.component';
import { RestorePasswordComponent } from './login/components/restore-password/restore-password.component';
import { RegistrationAllowedCanActivateGuard } from './_guards/registration-allowed.can-activate.guard';
import { RestorePasswordAllowedCanActivateGuard } from './_guards/restore-password-allowed.can-activate.guard';
import { SetNewPasswordComponent } from './login/components/set-new-password/set-new-password.component';
import { ActivateAccountComponent } from './login/components/activate-account/activate-account.component';

{{#modulesActive}}
{{#componentImport}}
import { {{{ng5_component}}} } from '{{{ng5_componentPath}}}';
{{/componentImport}}
{{/modulesActive}}

const routes: Routes = [
  { path: 'apidocs', component: ApidocsComponent, canActivate: [ConfiguredCanActivateGuard]},
  { path: 'login', component: LoginComponent, canActivate: [ConfiguredCanActivateGuard],
  data: {animation: 'LoginPage'}},
  { path: 'register', component: RegisterComponent, canActivate: [RegistrationAllowedCanActivateGuard] },
  { path: 'activate-account', component: ActivateAccountComponent, canActivate: [RegistrationAllowedCanActivateGuard] },
  { path: 'restore-password', component: RestorePasswordComponent, canActivate: [RestorePasswordAllowedCanActivateGuard] },
  { path: 'set-new-password', component: SetNewPasswordComponent, canActivate: [RestorePasswordAllowedCanActivateGuard] },
  { path: 'startup', component: StartupComponent },
  { path: 'standalone/:dashboardId', component: StandaloneDashboardComponent },
  { path: '', component: StreampipesComponent, children: [
      { path: '', component: HomeComponent, canActivate: [ConfiguredCanActivateGuard] },
      {{#modulesActive}}
      {{#componentImport}}
      { path: '{{{link}}}', component: {{{ng5_component}}}, data: { authPageNames: [{{{pageNames}}}]}},
      {{/componentImport}}
      {{^componentImport}}
      { path: '', data: { authPageNames: [{{{pageNames}}}]}, loadChildren: () => import('{{{path}}}').then(m => m.{{{ng5_moduleName}}})},
      {{/componentImport}}
      {{/modulesActive}}

      { path: 'notifications', component: NotificationsComponent },
      { path: 'info', component: InfoComponent },
      { path: 'profile', component: ProfileComponent},
    ], canActivateChild: [AuthCanActivateChildrenGuard, PageAuthGuard] }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {useHash: true})],
  exports: [RouterModule],
  providers: [
      AuthCanActivateChildrenGuard,
      AlreadyConfiguredCanActivateGuard,
      ConfiguredCanActivateGuard,
      PageAuthGuard,
      RegistrationAllowedCanActivateGuard,
      RestorePasswordAllowedCanActivateGuard,
  ]
})
export class AppRoutingModule { }
