import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '@shared/auth/auth.guard';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { OrderingDirection } from '@shared/ui-api/interfaces/route-config/ordering-directions';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { NotificationListComponent } from './notification-list/notification-list.component';
import { UserNotificationsListResolver } from '@fleio-api/notifications/user-notifications-list-resolver';
import { NotificationDetailsComponent } from './notification-details/notification-details.component';
import { UserNotificationResolver } from '@fleio-api/notifications/user-notification.resolver';
import { UserNotificationsSettingsResolver } from '@fleio-api/notifications/user-notifications-settings.resolver';
import { FilterTypes } from '@shared/ui-api/interfaces/route-config/filter-types';

const routes: Routes = [
  {
    path: '',
    component: NotificationListComponent,
    resolve: {
      notifications: UserNotificationsListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'core',
        search: {
          show: false,
          placeholder: $localize`Search notifications ...`,
        },
        defaultDisplayList: true,
        subheader: {
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.configurations;
          },
          objectName: $localize`notification`,
          objectNamePlural: $localize`notifications`,
        },
        ordering: {
          default: {
            display: $localize`Generated at`,
            field: 'generated',
            direction: OrderingDirection.Descending,
          },
          options: [
            {
              display: $localize`Generated at`,
              field: 'generated',
            },
            {
              display: $localize`Status`,
              field: 'status',
            }
          ]
        },
        filterConfig: {
          availableOptions: [
            {
              display: $localize`Status`,
              field: 'status',
              type: FilterTypes.Choices,
            },
          ]
        }
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: ':id',
    component: NotificationDetailsComponent,
    resolve: {
      notification: UserNotificationResolver,
    },
    canActivate: [AuthGuard],
    runGuardsAndResolvers: 'always',
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.notification.title,
      } as IRouteConfig,
    }
  }
];

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