import { NamedRoutes } from '@/core';
import { Routes } from '@angular/router';
import { PARTNER_CONSUMER_POSES_ROUTES } from './poses';

export type TComplexesRouteNames = 'complexes' | 'complex';

const baseUrl = (consumerId: string, businessId: string) =>
  `/partner/consumers/${consumerId}/business_activities/${businessId}/complexes`;

export const partnerConsumerComplexesNamedRoutes: NamedRoutes<TComplexesRouteNames> = {
  complexes: {
    path: 'complexes',
    loadComponent: () =>
      import('../../views/complexes/list.component').then((m) => m.PartnerUserComplexesComponent),
    meta: {
      title: 'شعب',
      pagePath: (consumerId: string, businessId: string) => baseUrl(consumerId, businessId),
    },
  },
  complex: {
    path: 'complexes/:complexId',
    loadComponent: () =>
      import('../../views/complexes/single.component').then((m) => m.PartnerUserComplexComponent),
    meta: {
      title: 'شعبه',
      pagePath: (consumerId: string, businessId: string, complexId: string) =>
        `${baseUrl(consumerId, businessId)}/${complexId}`,
    },
  },
};

export const PARTNER_CONSUMER_COMPLEXES_ROUTES: Routes = [
  partnerConsumerComplexesNamedRoutes.complexes,
  {
    path: partnerConsumerComplexesNamedRoutes.complex.path,
    loadComponent: () =>
      import('../../components/complexes/layout.component').then(
        (m) => m.PartnerConsumerComplexLayoutComponent,
      ),
    children: [
      {
        path: '',
        loadComponent: partnerConsumerComplexesNamedRoutes.complex.loadComponent,
      },
      ...PARTNER_CONSUMER_POSES_ROUTES,
    ],
  },
];
