import { NgModule } from '@angular/core';
import { RouterModule, Routes } 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 { RegisterComponent } from '@shared/auth/register/register.component';
import {
  TermsOfServicePreviewComponent
} from './dashboard/tabs/terms-of-service-preview/terms-of-service-preview.component';
import { SsoComponent } from '@shared/auth/sso/sso.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: 'clients-users',
    loadChildren: () => import('./clients-users/clients-users.module').then(mod => mod.ClientsUsersModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'invitations',
    loadChildren: () => import('./clients-users/invitations/invitations.module').then(mod => mod.InvitationsModule),
  },
  {
    path: 'openstack',
    loadChildren: () => import('./openstack/openstack.module').then(mod => mod.OpenstackModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'utilities',
    loadChildren: () => import('./utilities/utilities.module').then(mod => mod.UtilitiesModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'user',
    loadChildren: () => import('./user/user.module').then(mod => mod.UserModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'clients',
    loadChildren: () => import('./clients/clients.module').then(mod => mod.ClientsModule),
    canActivate: [AuthGuard],
    data: {
      hideInBreadcrumbs: false,
      includeFirstSegment: true,
    },
  },
  {
    path: 'sfa',
    loadChildren: () => import('./second-factor-auth/second-factor-auth.module').then(mod => mod.SecondFactorAuthModule),
    canActivate: [AuthGuard],
  },
  {
    path: 'terms-of-service-preview/:id',
    component: TermsOfServicePreviewComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Terms of service`,
      } as IRouteConfig,
    }
  },
  {
    path: 'signup',
    component: RegisterComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Signup`,
        feature: 'clients&users.signup',
      } as IRouteConfig,
    }
  },
  {
    path: 'signup/:email/:invitationId/:invitationToken',
    component: RegisterComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`Signup`,
        feature: 'clients&users.invitations',
      } as IRouteConfig,
    }
  },
  {
    path: 'sso',
    component: SsoComponent,
    canActivate: [AuthGuard],
    data: {
      config: {
        getTitleDisplay: () => $localize`SSO`,
      } as IRouteConfig,
    }
  },
  {
    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: 'login/:invitationId/:invitationToken',
    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 EnduserRoutingModule {
}
