import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from '@shared/auth/login/login.component';
import { AuthGuard } from '@shared/auth/auth.guard';
import { PageNotFoundComponent } from '@shared/error-handling/page-not-found/page-not-found.component';
import { DisconnectedFromServerComponent } from '@shared/error-handling/disconnected-from-server/disconnected-from-server.component';
import { LogoutComponent } from '@shared/auth/logout/logout.component';
import { ForgotPasswordComponent } from '@shared/auth/forgot-password/forgot-password.component';
import { NewPasswordComponent } from '@shared/auth/new-password/new-password.component';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { Saml2SSOComponent } from '@shared/auth/saml2sso/saml2sso.component';

const routes: Routes = [
  {
    path: '',
    loadChildren: () => import('./dashboard/dashboard.module').then(mod => mod.DashboardModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'billing',
    loadChildren: () => import('./billing/billing.module').then(mod => mod.BillingModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'orders',
    loadChildren: () => import('./billing-orders/billing-orders.module').then(mod => mod.BillingOrdersModule),
    canActivate: [AuthGuard],
    data: {
      hideInBreadcrumbs: false,
      includeFirstSegment: true,
    },
  },
  {
    path: 'openstack',
    loadChildren: () => import('./openstack/openstack.module').then(mod => mod.OpenstackModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'clients-users',
    loadChildren: () => import('./clients-users/clients-users.module').then(mod => mod.ClientsUsersModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'user',
    loadChildren: () => import('./user/user.module').then(mod => mod.UserModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'utilities',
    loadChildren: () => import('./utils/utilities.module').then(mod => mod.UtilitiesModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'settings',
    loadChildren: () => import('./settings/settings.module').then(mod => mod.SettingsModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'servers',
    loadChildren: () => import('./servers/servers.module').then(mod => mod.ServersModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'sfa',
    loadChildren: () => import('./second-factor-auth/second-factor-auth.module').then(mod => mod.SecondFactorAuthModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'saml2sso',
    component: Saml2SSOComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`SAML 2 SSO`,
      } as IRouteConfig,
    }
  },
  {
    path: 'login',
    component: LoginComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Login`,
      } as IRouteConfig,
    }
  },
  {
    path: 'reset',
    component: ForgotPasswordComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Reset password`,
      } as IRouteConfig,
    }
  },
  {
    path: 'reset-password/:userid/:token',
    component: NewPasswordComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Reset password`,
      } as IRouteConfig,
    }
  },
  {
    path: 'logout',
    component: LogoutComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Logout`,
      } as IRouteConfig,
    }
  },
  {
    path: 'disconnected',
    component: DisconnectedFromServerComponent,
    data: {
      config: {
        getTitleDisplay: () => $localize`Disconnected from server`,
      } as IRouteConfig,
    }
  },
  {
    path: '',
    loadChildren: () => import('./plugins/plugins.module').then(mod => mod.PluginsModule),
    data: {
      hideInBreadcrumbs: false,
      includeFirstSegment: true,
    },
    canActivate: [AuthGuard],
  },
  {
    path: '**',
    component: PageNotFoundComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Not found`,
        removeWidthLimit: true,
      } as IRouteConfig,
    }
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class StaffRoutingModule { }
