import { RouterModule, Routes } from '@angular/router';
import { IRouteConfig } from '@shared/ui-api/interfaces/route-config/route-config';
import { NgModule } from '@angular/core';
import { InvitationDetailsComponent } from './invitation-details/invitation-details.component';
import { InvitationResolver } from '@fleio-api/client-user/invitations/invitation.resolver';

const routes: Routes = [
  {
    path: ':id',
    component: InvitationDetailsComponent,
    resolve: {
      invitation: InvitationResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => {
          if (data.invitation.token_invalid) {
            return $localize`Invitation`;
          } else {
            return $localize`Invitation for client ${data.invitation.name}`;
          }
        },
      } as IRouteConfig,
    },
  },
  {
    path: ':id/:token',
    component: InvitationDetailsComponent,
    resolve: {
      invitation: InvitationResolver,
    },
    data: {
      config: {
        getBreadCrumbDetail: (data) => {
          if (data.invitation.token_invalid) {
            return $localize`Invitation`;
          } else {
            return $localize`Invitation for client ${data.invitation.name}`;
          }
        },
      } as IRouteConfig,
    },
    runGuardsAndResolvers: 'always',
  },
];

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