import { CompositeRouteGuard, IqserPermissionsGuard, IqserRoutes } from '@iqser/common-ui';
import { RedRoleGuard } from '@users/red-role.guard';
import { BaseAccountScreenComponent } from './base-account-screen/base-account-screen-component';
import { PreferencesComponent } from './screens/preferences/preferences.component';
import { Roles } from '@users/roles';
import { IqserAuthGuard } from '@iqser/common-ui/lib/users';
import { PendingChangesGuard } from '@guards/can-deactivate.guard';
import { NotificationPreferencesService } from './services/notification-preferences.service';

export default [
    { path: '', redirectTo: 'user-profile', pathMatch: 'full' },
    {
        path: 'user-profile',
        component: BaseAccountScreenComponent,
        canActivate: [CompositeRouteGuard],
        data: {
            routeGuards: [IqserAuthGuard, RedRoleGuard],
        },
        loadChildren: () => import('./screens/user-profile/user-profile.routes'),
    },
    {
        path: 'notifications',
        component: BaseAccountScreenComponent,
        canActivate: [CompositeRouteGuard, IqserPermissionsGuard],
        canDeactivate: [PendingChangesGuard],
        data: {
            routeGuards: [IqserAuthGuard, RedRoleGuard],
            permissions: {
                allow: [Roles.notifications.write, 'RED_USER'],
                redirectTo: '/',
            },
        },
        providers: [NotificationPreferencesService],
        loadChildren: () => import('./screens/notifications/notifications.routes'),
    },
    {
        path: 'preferences',
        component: BaseAccountScreenComponent,
        canActivate: [CompositeRouteGuard],
        data: {
            routeGuards: [IqserAuthGuard, RedRoleGuard],
            screen: 'preferences',
        },
        children: [
            {
                path: '',
                component: PreferencesComponent,
            },
        ],
    },
    {
        path: 'warnings-preferences',
        component: BaseAccountScreenComponent,
        canActivate: [CompositeRouteGuard],
        data: {
            routeGuards: [IqserAuthGuard, RedRoleGuard],
            screen: 'warnings-preferences',
        },
        children: [
            {
                path: '',
                component: PreferencesComponent,
            },
        ],
    },
] satisfies IqserRoutes;
