import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '@core/security/auth.guard';
import { LayoutComponent } from './core/layout/layout.component';
import { MyProfileComponent } from './user/my-profile/my-profile.component';
import { MyProfileResolverService } from './user/my-profile/my-profile-resolver';

const routes: Routes = [
  {
    path: 'login',
    loadChildren: () =>
      import('./login/login.module').then((m) => m.LoginModule),
  },
  {
    path: '',
    component: LayoutComponent,
    resolve: { profile: MyProfileResolverService },
    children: [
      {
        path: 'my-profile',
        component: MyProfileComponent,
        canActivate: [AuthGuard],
      },{
        path: '',
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./dashboard/dashboard.module').then((m) => m.DashboardModule),
      },
    
      {
        path: 'actions',
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./action/action.module').then((m) => m.ActionModule),
      },
      {
        path: 'pages',
        canLoad: [AuthGuard],
        data: {
          claimType: [
            'page_list',
            // 'role_edit',
            // 'role_add',
            // 'user_role_edit',
          ],
        },
        loadChildren: () =>
          import('./page/page.module').then((m) => m.PageModule),
      },
      {
        path: 'screen-operation',
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./page-action/page-action.module').then(
            (m) => m.PageActionModule
          ),
      },
      {
        path: 'roles',
        data: {
          claimType: [
            'role_list',
            'role_edit',
            'role_add',
            'user_role_edit',
          ],
        },
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./role/role.module').then((m) => m.RoleModule),
      },
      {
        path: 'users',
        data: {
          claimType: [
            'user_list',
            'user_edit',
            'user_add',
            'user_permission_edit',
          ],
        },
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./user/user.module').then((m) => m.UserModule),
      },
      {
        path: 'sessions',
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./session/session.module').then((m) => m.SessionModule),
      },
      {
        path: 'login-audit',
        data: { claimType: 'login_audit_list' },
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./login-audit/login-audit.module').then(
            (m) => m.LoginAuditModule
          ),
      },
      {
        path: 'logs',
        data: {
          claimType: 'system_logs_list'
        },
        loadChildren: () =>
          import('./n-log/n-log.module').then((m) => m.NLogModule),
      },
      {
        path: 'notifications',
        canLoad: [AuthGuard],
        loadChildren: () =>
          import('./notification/notification.module').then(
            (m) => m.NotificationModule
          ),
      },
      {
        path: 'reminders',
        data: {
          claimType: [
            'reminder_list',
            'reminder_add',
            'reminder_edit',
            'reminder_delete'
          ],
        },
        loadChildren: () =>
          import('./reminder/reminder.module').then((m) => m.ReminderModule),
      },
      {
        path: 'email-smtp',
        data: {
          claimType: [
            'email_smtp_list',
           'email_smtp_edit',
            // 'email_edit_smtp_setting',
            // 'email_create_smtp_setting',
          ],
        },
        loadChildren: () =>
          import('./email-smtp-setting/email-smtp-setting.module').then(
            (m) => m.EmailSmtpSettingModule
          ),
      },
      {
        path: 'email-template',
        data: {
          claimType: ['email_template_list'],
        },
        loadChildren: () =>
          import('./email-template/email-template.module').then(
            (m) => m.EmailTemplateModule
          ),
      },
      {
        path: 'email-send',
        data: {
          claimType: ['send_email_list'],
        },
        loadChildren: () =>
          import('./email-send/email-send.module').then(
            (m) => m.EmailSendModule
          ),
      },   {
        path: 'app-Settings',
        data: {
          claimType: ['app_settings_list'],
        },
        loadChildren: () =>
          import('./app-settings/app-settings.module').then(
            (m) => m.AppSettingsModule
          ),
      },
      {
        path: 'company-profile',
        canActivate: [AuthGuard],
        data: { claimType: 'company_profile_edit' },
        loadComponent: () =>
          import('./company-profile/company-profile.component').then(
            (m) => m.CompanyProfileComponent
          ),
      },
      {
        path: 'page-helper',
        data: { claimType: 'page_helper_list' },
        loadChildren: () =>
          import('./page-helper/page-helper.module').then(
            (m) => m.PageHelperModule
          ),
      },
      {
        path: '**',
        redirectTo: '/',
      },
    ],
  },
];

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