import { RouterModule, Routes } from '@angular/router';
import { ConfigurableOptionListComponent } from './configurable-option-list/configurable-option-list.component';
import { ConfigurableOptionListResolver } from '@fleio-api/billing/configurable-options/configurable-option-list.resolver';
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 { ConfigurableOptionCreateComponent } from './configurable-option-create/configurable-option-create.component';
import { ConfigurableOptionCreateOptionsResolver } from '@fleio-api/billing/configurable-options/configurable-option-create-options.resolver';
import { ConfigurableOptionResolver } from '@fleio-api/billing/configurable-options/configurable-option.resolver';
import { ConfigurableOptionEditComponent } from './configurable-option-edit/configurable-option-edit.component';
import { NgModule } from '@angular/core';
import {
  ConfigurableOptionDetailsComponent
} from './configurable-option-details/configurable-option-details.component';
import {
  ConfigurableOptionPermissionsResolver
} from '@fleio-api/billing/configurable-options/configurable-option-permissions.resolver';

const routes: Routes = [
  {
    path: '',
    component: ConfigurableOptionListComponent,
    resolve: {
      configurableOptions: ConfigurableOptionListResolver,
    },
    canActivate: [AuthGuard],
    data: {
      config: {
        feature: 'billing',
        search: {
          show: true,
          placeholder: $localize`Search configurable options ...`,
        },
        subheader: {
          objectList(data): FleioObjectsList<IBaseFleioObjectModel> {
            return data.configurableOptions;
          },
          objectName: $localize`configurable option`,
          objectNamePlural: $localize`configurable options`,
        },
        ordering: {
          default: {
            display: $localize`Created at`,
            field: 'created_at',
            direction: OrderingDirection.Descending,
          },
          options: [
            {
              display: $localize`Created at`,
              field: 'created_at',
            },
          ]
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: 'create',
    component: ConfigurableOptionCreateComponent,
    resolve: {
      createOptions: ConfigurableOptionCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: () => $localize`Create configurable option`,
      } as IRouteConfig,
    }
  },
  {
    path: ':id',
    component: ConfigurableOptionDetailsComponent,
    resolve: {
      configurableOption: ConfigurableOptionResolver,
      permissions: ConfigurableOptionPermissionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.configurableOption.name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id/edit',
    component: ConfigurableOptionEditComponent,
    resolve: {
      configurableOption: ConfigurableOptionResolver,
      createOptions: ConfigurableOptionCreateOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => $localize`Edit configurable option ${data.configurableOption.name}`,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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