import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CustomerCreateB2BComponent } from './customer-create/customer-create-b2b.component';
import { CustomerCreateBranchComponent } from './customer-create/customer-create-branch.component';
import { CustomerCreateGuestComponent } from './customer-create/customer-create-guest.component';
import { CustomerCreateOnlineComponent } from './customer-create/customer-create-online.component';
import { PayerCreateB2BComponent } from './customer-details/address/payer-create/payer-create-b2b.component';
import { PayerCreateB2CComponent } from './customer-details/address/payer-create/payer-create-b2c.component';
import { PayerEditB2BComponent } from './customer-details/address/payer-edit/payer-edit-b2b.component';
import { PayerEditB2CComponent } from './customer-details/address/payer-edit/payer-edit-b2c.component';
import { ShippingCreateB2BComponent } from './customer-details/address/shipping-create/shipping-create-b2b.component';
import { ShippingCreateB2CComponent } from './customer-details/address/shipping-create/shipping-create-b2c.component';
import { ShippingEditB2BComponent } from './customer-details/address/shipping-edit/shipping-edit-b2b.component';
import { ShippingEditB2CComponent } from './customer-details/address/shipping-edit/shipping-edit-b2c.component';
import { CustomerCardComponent } from './customer-details/customer-card/customer-card.component';
import { CustomerDataEditB2BComponent } from './customer-details/customer-data-edit/customer-data-edit-b2b.component';
import { CustomerDataEditB2CComponent } from './customer-details/customer-data-edit/customer-data-edit-b2c.component';
import { CustomerDetailsComponent } from './customer-details/customer-details.component';
import { CustomerCardGuard } from './customer-details/guards/customer-card.guard';
import { CustomerOrdersComponent } from './customer-details/customer-orders/customer-orders.component';
import { CustomerSearchComponent } from './customer-search/customer-search.component';
import { CustomerSearchMainComponent } from './customer-search/search-main/search-main.component';
import { CustomerSearchResultComponent } from './customer-search/search-results/search-results.component';
import { CustomerCreateGuard } from './guards/customer-create.guard';
import { PageCustomerComponent } from './page-customer.component';
import { CustomerOrderDetailsComponent } from './customer-details/customer-order-details/customer-order-details.component';

const routes: Routes = [
  {
    path: '',
    component: PageCustomerComponent,
    children: [
      {
        path: 'search',
        component: CustomerSearchComponent,
        children: [
          { path: '', component: CustomerSearchMainComponent },
          { path: 'result', component: CustomerSearchResultComponent },
          { path: ':customerId/details', component: null },
        ],
      },
      {
        path: 'create',
        canActivateChild: [CustomerCreateGuard],
        children: [
          { path: 'store', component: CustomerCreateBranchComponent },
          { path: 'webshop', component: CustomerCreateOnlineComponent },
          { path: 'b2b', component: CustomerCreateB2BComponent },
          { path: 'guest', component: CustomerCreateGuestComponent },
          { path: '', pathMatch: 'full', redirectTo: 'store' },
        ],
      },
      {
        path: ':customerId',
        component: CustomerDetailsComponent,
      },
      {
        path: ':customerId/card',
        canActivate: [CustomerCardGuard],
        component: CustomerCardComponent,
      },
      {
        path: ':customerId/orders',
        component: CustomerOrdersComponent,
      },
      {
        path: ':customerId/order/:orderId',
        component: CustomerOrderDetailsComponent,
      },
      {
        path: ':orderId',
        component: CustomerOrderDetailsComponent,
      },
      {
        path: ':customerId/edit/b2c',
        component: CustomerDataEditB2CComponent,
      },
      {
        path: ':customerId/edit/b2b',
        component: CustomerDataEditB2BComponent,
      },
      {
        path: ':customerId/payer/create/b2c',
        component: PayerCreateB2CComponent,
      },
      {
        path: ':customerId/payer/create/b2b',
        component: PayerCreateB2BComponent,
      },
      {
        path: ':customerId/shipping/create/b2c',
        component: ShippingCreateB2CComponent,
      },
      {
        path: ':customerId/shipping/create/b2b',
        component: ShippingCreateB2BComponent,
      },
      {
        path: ':customerId/payer/:payerId/edit/b2b',
        component: PayerEditB2BComponent,
      },
      {
        path: ':customerId/payer/:payerId/edit/b2c',
        component: PayerEditB2CComponent,
      },
      {
        path: ':customerId/shipping/:shippingAddressId/edit/b2b',
        component: ShippingEditB2BComponent,
      },
      {
        path: ':customerId/shipping/:shippingAddressId/edit/b2c',
        component: ShippingEditB2CComponent,
      },
      {
        path: '',
        pathMatch: 'full',
        redirectTo: 'search',
      },
    ],
  },
];

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