import { RouterModule, Routes } from '@angular/router';
import { RegistrarListComponent } from './registrar-list/registrar-list.component';
import { DomainRegistrarListResolver } from '../../../../shared/fleio-api/plugins/domains/domain-registrar-list.resolver';
import { AuthGuard } from '../../../../shared/auth/auth.guard';
import { FleioObjectsList } from '../../../../shared/fleio-api/fleio-objects-list';
import { IBaseFleioObjectModel } from '../../../../shared/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 { RegistrarCreateComponent } from './registrar-create/registrar-create.component';
import { DomainRegistrarResolver } from '../../../../shared/fleio-api/plugins/domains/domain-registrar.resolver';
import { RegistrarDetailsComponent } from './registrar-details/registrar-details.component';
import { RegistrarEditComponent } from './registrar-edit/registrar-edit.component';
import { NgModule } from '@angular/core';

const routes: Routes = [
  {
    path: '',
    component: RegistrarListComponent,
    resolve: {
      registrars: DomainRegistrarListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'plugins.domains',
        search: {
          show: true,
          placeholder: $localize`Search registrars ...`,
        },
        subheader: {
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.todos;
          },
          objectName: $localize`domain registrar`,
          objectNamePlural: $localize`domain registrars`,
        },
        ordering: {
          default: {
            display: $localize`Created at`,
            field: 'created_at',
            direction: OrderingDirection.Descending,
          },
          options: [
            {
              display: $localize`Created at`,
              field: 'created_at',
            },
            {
              display: $localize`Name`,
              field: 'name',
            },
          ]
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always'
  },
  {
    path: 'create',
    component: RegistrarCreateComponent,
    resolve: {
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create registrar`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: RegistrarDetailsComponent,
    resolve: {
      registrar: DomainRegistrarResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.registrar.name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/edit',
    component: RegistrarEditComponent,
    resolve: {
      registrar: DomainRegistrarResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit registrar ${data.registrar.display_name}`,
      } as IRouteConfig,
    }
  },
];

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