import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '@shared/auth/auth.guard';
import { OrderingDirection } from '@shared/ui-api/interfaces/route-config/ordering-directions';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { PredefinedReplyCategoryListResolver } from '@fleio-api/plugins/tickets/predefined-reply-category-list.resolver';
import { PredefinedRepliesListComponent } from './predefined-replies-list/predefined-replies-list.component';
import { PredefinedReplyCategoryCreateComponent } from './predefined-reply-category-create/predefined-reply-category-create.component';
import { PredefinedReplyCategoryEditComponent } from './predefined-reply-category-edit/predefined-reply-category-edit.component';
import { PredefinedReplyCategoryResolver } from '@fleio-api/plugins/tickets/predefined-reply-category.resolver';
import { PredefinedReplyCategoryDetailsComponent } from './predefined-reply-category-details/predefined-reply-category-details.component';
import { PredefinedReplyCreateComponent } from './predefined-reply-create/predefined-reply-create.component';
import { PredefinedReplyResolver } from '@fleio-api/plugins/tickets/predefined-reply.resolver';
import { PredefinedReplyEditComponent } from './predefined-reply-edit/predefined-reply-edit.component';
import { PredefinedRepliesPermissionsResolver } from '@fleio-api/plugins/tickets/predefined-replies-permissions.resolver';

const routes: Routes = [
  {
    path: '',
    component: PredefinedRepliesListComponent,
    resolve: {
      categories: PredefinedReplyCategoryListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'plugins.tickets',
        search: {
          show: true,
          placeholder: $localize`Search categories ...`,
        },
        ordering: {
          default: {
            field: 'name',
            display: $localize`Name`,
            direction: OrderingDirection.Ascending
          },
          options: [
            {
              field: 'id',
              display: $localize`ID`
            },
            {
              field: 'name',
              display: $localize`Name`
            },
            {
              field: 'created_at',
              display: $localize`Created at`
            },
          ],
        },
        subheader: {
          objectName: 'category',
          objectNamePlural: 'categories',
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.categories;
          }
        },
        getBreadCrumbDetail: () => $localize`Categories`,
        filterConfig: {
          availableOptions: [
          ],
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'create-category',
    component: PredefinedReplyCategoryCreateComponent,
    resolve: {
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Add predefined reply category`,
      } as IRouteConfig,
    },
  },
  {
    path: 'edit-category/:id',
    component: PredefinedReplyCategoryEditComponent,
    resolve: {
      category: PredefinedReplyCategoryResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.category.name}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'category/:id',
    component: PredefinedReplyCategoryDetailsComponent,
    resolve: {
      category: PredefinedReplyCategoryResolver,
      permissions: PredefinedRepliesPermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => `${data.category.name}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'category/:id/add-reply',
    component: PredefinedReplyCreateComponent,
    resolve: {
      category: PredefinedReplyCategoryResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Add predefined reply`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'category/:id/edit-reply/:replyId',
    component: PredefinedReplyEditComponent,
    resolve: {
      category: PredefinedReplyCategoryResolver,
      predefinedReply: PredefinedReplyResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit predefined reply ${data.predefinedReply.title}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
];

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