/**
 * Created through mkmodule
 */

import { NgModule }             from '@angular/core'
import { RouterModule, Routes } from '@angular/router'


import { ViewComponent } 			from '@k-core/modules/category/components/view/cmp.view'
import { CategoryOverviewView }     from '@k-core/modules/catalog/templates/category-overview/view.category-overview'


import { AppHelper }  from '@k-settings/app-helper'

// Guards
import { UserGuard } from '@k-core/guards/guard.User'


/**
 * Generates the possibility to have categories and subcategories in navigation, this only works in a single level of subcategory.
 * It can be expanded, but that will require further duplication of code. by cloning and nesting the `{path: 'category'}` element
 * it is possible to duplicate to an endless level.
 * 
 * This could be handled a bit by placing the function in a seperate variable and then iterate it into, but for the current scope
 * we will only introduce a single sub level.
 * 
 * The produced structure is something like:
 * 
 * `categories/:key`
 * `categories/:key/product/:key`
 * `categories/:key/category/:key`
 * `categories/:key/category/:key/product/:key`
 */
const routes: Routes = [  

	{
		path: '',
		pathMatch: 'full',
		loadChildren: '@k-core/modules/catalog/mod.catalog#CatalogModule'
	},

	{
		path: ':categorykey',
		pathMatch: 'prefix',

		children: [
			{
				path: ':productkey',
				pathMatch: 'full',
				loadChildren: '@k-core/modules/product/mod.product#ProductModule'
			},
			{
				path: AppHelper.category + '/:categorykey',
				pathMatch: 'full',
				component: ViewComponent
			},
			{
				path: AppHelper.category + '/:categorykey/' + AppHelper.product + '/:productkey',
				pathMatch: 'full',
				loadChildren: '@k-core/modules/product/mod.product#ProductModule'
			},
			// Catch root reference
			{
				path: '',
				pathMatch: 'full',
				component: ViewComponent,
				data: {
					breadcrumb: '',
					isBase: true
				},
			},
			// Catch any reference that doesnt match above and send it to error-message
			{
				path: '**',
				redirectTo: '/' + AppHelper.errorPage
			}
		]
			
		
	}
]


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

