import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DashboardComponent } from './dashboard/dashboard.component';
import { ExternalBillingUrlResolver } from '@fleio-api/core/model/external-billing-url-resolver.service';
import { AuthGuard } from '@shared/auth/auth.guard';
import { ConfirmEmailComponent } from './confirm-email/confirm-email.component';
import { AgreeWithTermsOfServiceComponent } from './agree-with-terms-of-service/agree-with-terms-of-service.component';
import { ActiveTosResolver } from '@fleio-api/core/active-tos.resolver';
import { RecurringPaymentOptionsComponent } from './recurring-payment-options/recurring-payment-options.component';
import { RecurringPaymentOptionsResolver } from '@fleio-api/billing/gateways/recurring-payment-options.resolver';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { RequireClientDataResolver } from '@fleio-api/billing/require-client-data.resolver';
import { ConfirmEmailResolver } from '@fleio-api/client-user/user/confirm-email.resolver';

const routes: Routes = [
  {
    path: '',
    component: DashboardComponent,
    canActivate: [AuthGuard],
    resolve: {
      requireClientData: RequireClientDataResolver, // do not load dashboard if client data was not completed
      externalBillingUrlResponse: ExternalBillingUrlResolver,
    }
  },
  {
    path: 'recurring-payment-options',
    canActivate: [AuthGuard],
    component: RecurringPaymentOptionsComponent,
    runGuardsAndResolvers: 'always',
    resolve: {
      recurring_payment_options: RecurringPaymentOptionsResolver,
    },
    data: {
      hideInBreadcrumbs: false,
      includeFirstSegment: true,
      config: {
        getBreadCrumbDetail: () => $localize`Payment options`,
      } as IRouteConfig
    },
  },
  {
    path: 'confirm-email',
    canActivate: [AuthGuard],
    component: ConfirmEmailComponent,
    resolve: {
      confirmEmail: ConfirmEmailResolver,
    },
    data: {
      hideInBreadcrumbs: false,
      includeFirstSegment: true,
      config: {
        getBreadCrumbDetail: () => $localize`Confirm email`,
      } as IRouteConfig
    }
  },
  {
    path: 'confirm-email/:token',
    canActivate: [AuthGuard],
    component: ConfirmEmailComponent,
    resolve: {
    }
  },
  {
    path: 'terms-of-service',
    canActivate: [AuthGuard],
    component: AgreeWithTermsOfServiceComponent,
    resolve: {
      tos: ActiveTosResolver
    }
  },
];

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