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

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

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

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

export const SUPER_ADMIN_CONSUMER_COMPLEXES_ROUTES: Routes = [
  superAdminConsumerComplexesNamedRoutes.complexes,
  {
    path: superAdminConsumerComplexesNamedRoutes.complex.path,
    loadComponent: () =>
      import('../../components/complexes/layout.component').then(
        (m) => m.SuperAdminConsumerComplexLayoutComponent,
      ),
    children: [
      {
        path: '',
        loadComponent: superAdminConsumerComplexesNamedRoutes.complex.loadComponent,
      },
      ...SUPER_ADMIN_CONSUMER_POSES_ROUTES,
    ],
  },
];
