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

import {LoginComponent} from './login/login.component';
import {HomeComponent} from './home/home.component';
import {CartComponent} from './cart/cart.component';
import {SpecialsComponent} from './specials/specials.component';
import {SearchComponent} from './search/search.component';
import {PasswordComponent} from './password/password.component';
import {ProductsComponent} from './products/products.component';
import {ProductComponent} from './products/product.component';
import {CategoriesComponent} from './categories/categories.component';
import {ListsComponent} from './lists/lists.component';
import {ListComponent} from './lists/list.component';
import {AppConfig} from './config/app.config';
import {Error404Component} from './core/error404/error-404.component';
import {AuthGuard} from './core/guards/auth.guard';

const routes: Routes = [
    {path: '', redirectTo: '/', pathMatch: 'full'},
    {path: '', component: LoginComponent},
    {path: AppConfig.routes.home, component: HomeComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.cart, component: CartComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.specials, component: SpecialsComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.password, component: PasswordComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.search, component: SearchComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.lists, component: ListsComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.list + '/:id', component: ListComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.categories, component: CategoriesComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.categories + '/:categoryID', component: CategoriesComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.categories + '/:categoryID/:typeID', component: CategoriesComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.products, component: ProductsComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.product + '/:id', component: ProductComponent, canActivate: [AuthGuard]},
    {path: AppConfig.routes.error404, component: Error404Component, canActivate: [AuthGuard]},

    // otherwise redirect to 404
    {path: '**', redirectTo: '/' + AppConfig.routes.error404}
];

@NgModule({
    imports: [
        RouterModule.forRoot(routes)
    ],
    exports: [
        RouterModule
    ]
})

export class AppRoutingModule {
}
