import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CartComponent } from './cart/cart.component';
import { CartItemsListResolver } from '@fleio-api/billing/cart/cart-items-list.resolver';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { CartItemComponent } from '@shared/common-tabs/billing/orders/cart-item/cart-item.component';
import { CartItemResolver } from '@fleio-api/billing/cart/cart-item.resolver';
import { CartItemEditOptionsResolver } from '@fleio-api/billing/cart/cart-item-edit-options.resolver';
import { AuthGuard } from '@shared/auth/auth.guard';

const routes: Routes = [
  {
    path: '',
    component: CartComponent,
    canActivate: [AuthGuard],
    resolve: {
      cartItems: CartItemsListResolver,
    },
    data: {
      config: {
        feature: 'billing.order',
        getBreadCrumbDetail: () => $localize`Shopping cart`,
      } as IRouteConfig
    },
    runGuardsAndResolvers: 'always',
  },
  {
    path: ':id',
    component: CartItemComponent,
    resolve: {
      cartItem: CartItemResolver,
      orderOptions: CartItemEditOptionsResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => data.cartItem.name,
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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