import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CustomLayoutComponent, NotFoundComponent } from '@xdf/layouts';
import { AuthGuard, LoginComponent } from '@xdf/security';
import { BytebotLayoutComponent } from './modules/bytebot-layout/bytebot-layout/bytebot-layout.component';
import { HomeComponent } from './views/home/home.component';

const routes: Routes = [
  // Remover para SSO
  { path: 'login', component: LoginComponent },
  // Main redirect
  { path: '', redirectTo: 'home', pathMatch: 'full', canActivate: [AuthGuard] },
  {
    path: '', component: CustomLayoutComponent,
    children: [
      { path: 'home', component: HomeComponent, data: { breadcrumb: 'Home' } },
      {
        path: 'security', data: { breadcrumb: 'Seguridad' }, canLoad: [AuthGuard],
        loadChildren: () => import('./modules/security/security.module').then(m => m.SecurityModule)
      },
      {
        path: 'settings', data: { breadcrumb: 'Ajustes Generales' }, canLoad: [AuthGuard],
        loadChildren: () => import('./modules/settings/settings.module').then(m => m.SettingsModule)
      },
      {
        path: 'configuration', data: { breadcrumb: 'Agentes' }, canLoad: [AuthGuard],
        loadChildren: () => import('./modules/agent/agent.module').then(m => m.AgentModule)
      },
      {
        path: 'dashboards', data: { breadcrumb: 'Dashboards' }, canLoad: [AuthGuard],
        loadChildren: () => import('./modules/dashboards/dashboards.module').then(m => m.DashboardsModule)
      },
      {
        path: 'configuration-concept',
        loadChildren: () => import('./modules/configuration-concept/configuration-concept.module').then(m => m.ConfigurationConceptModule)
      },
      {
        path: 'business-parameters',
        loadChildren: () => import('./modules/business-parameters/business-parameters.module').then(m => m.BusinessParametersModule)
      },
      {
        path: 'agente',
        loadChildren: () => import('./modules/agente/agente.module').then(m => m.AgenteModule)
      },
      {
        path: 'supervisor',
        loadChildren: () => import('./modules/supervisor/supervisor.module').then(m => m.SupervisorModule)
      }
    ],
    canActivate: [AuthGuard]
  },
  { path: 'notpermitted', component: NotFoundComponent },

  // Handle all other routes
  { path: '**', component: NotFoundComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    scrollPositionRestoration: 'enabled',
    anchorScrolling: 'enabled',
    onSameUrlNavigation: 'ignore'
  })],
  exports: [RouterModule]
})
export class AppRoutingModule { }
