import { AppHelper } from '@k-settings/app-helper'
import { UserGuard } from '@k-core/guards/guard.User'

interface ILazy {
    path: string;
    pathMatch?: string; // Should be introduced, so we can force the hand of whichever request we want and give a 404 page if requests are not met
    loadChildren: string;
    canActivate?: any[];
    data?: IData;
}
interface IData {
    breadcrumb?: string;
    hasNumber?: boolean;
    isBase?: boolean;
    url?: string; // force a breadcrumbs path
}

const core_modules = '@k-core/modules/'
const page_modules = '' // NYI
const site_modules = '@k-sites/b2b/modules/'

export const Lazy: ILazy[] = [

    {
        path: AppHelper.login,
        loadChildren: core_modules + 'User/mod.User#UserModule'
    },
    {
        path: AppHelper.categories,
        loadChildren: site_modules + 'category/mod.category#B2B_CategoryModule',
        canActivate: [UserGuard],
        data: {
            breadcrumb: 'categories'
        }
    },
    {
        path: AppHelper.configurator,
        loadChildren: core_modules + 'configurator/mod.configurator#ConfiguratorModule',
        canActivate: [UserGuard],
        data: {
            breadcrumb: 'Konfigurator'
        }
    },
    {
        path: AppHelper.customProduct,
        loadChildren: core_modules +  'custom-product/mod.custom-product#CustomProductModule',
        canActivate: [UserGuard]
    },
    {
        path: AppHelper.product,
        loadChildren: '@k-core/modules/product/mod.product#ProductModule'
    },
    { 
        path: AppHelper.orderSearch,
        loadChildren: core_modules + 'search-orders/mod.search-orders#SearchOrdersModule',
        canActivate: [UserGuard]
    },
    {
        path: AppHelper.search,
        loadChildren: site_modules + 'search/mod.search#B2B_SearchModule',
        canActivate: [UserGuard]
    },
    {
        path: AppHelper.user,
        loadChildren: core_modules + 'userProfile/mod.userProfile#UserProfileModule',
        canActivate: [UserGuard]
    },
    {
        path: AppHelper.basket,
        loadChildren: core_modules + 'basket/mod.basket#BasketModule',
        canActivate: [UserGuard]
    },

    // Frontpage
    {
        path: '',
        loadChildren: site_modules + 'catalog/mod.catalog#CatalogModule',
        canActivate: [UserGuard]
    },

    // Make sure PageModule is loaded last, as it has a catch-all 404
    {
        path: ':page',
        loadChildren: core_modules + 'page/mod.page#PageModule',
        canActivate: [UserGuard],
        data: {
            breadcrumb: ''
        }
    }
]