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

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

const baseUrl = (businessId: string) => `/consumer/business_activities/${businessId}/complexes`;

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

export const CONSUMER_COMPLEXES_ROUTES: Routes = [
  consumerComplexesNamedRoutes.complexes,
  {
    path: consumerComplexesNamedRoutes.complex.path,
    loadComponent: () =>
      import('../../components/complexes/layout.component').then(
        (m) => m.ConsumerComplexLayoutComponent,
      ),
    children: [
      {
        ...consumerComplexesNamedRoutes.complex,
        path: '',
      },
      ...CONSUMER_POSES_ROUTES,
    ],
  },
];
