import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {ProfileComponent} from "@app/_views/profile/profile.component";
import {UserDetailComponent} from "@app/_views/user/user-detail/user-detail.component";
import {userGuard} from "@app/_guards/user.guard";
import {adminGuard} from "@app/_guards/admin.guard";
import {UsersComponent} from "@app/_views/user/users.component";
import {TwoColumnComponent} from "@app/_components/layout/two-column/two-column.component";
import {DashboardComponent} from "@app/_views/dashboard/dashboard.component";
import {BaseDataComponent} from "@app/_views/base-data/base-data.component";
import {LocationDetailComponent} from "@app/_views/location/location-detail/location-detail.component";
import {ZoneDetailComponent} from "@app/_views/zone/zone-detail/zone-detail.component";
import {VesselDetailComponent} from "@app/_views/vessel/vessel-detail/vessel-detail.component";
import {
    ShippingCompanyDetailComponent
} from "@app/_views/shipping-company/shipping-company-detail/shipping-company-detail.component";
import {TripComponent} from "@app/_views/trip/trip.component";
import {TripDetailComponent} from "@app/_views/trip/trip-detail/trip-detail.component";
import {UserTripComponent} from "@app/_views/user-trip/user-trip.component";
import {UserTripDetailComponent} from "@app/_views/user-trip/user-trip-detail/user-trip-detail.component";

const accountModule = () => import('@app/_views/account/account.module').then(x => x.AccountModule);

export const ROUTE_DASHBOARD = 'dashboard';
export const ROUTE_BASE_DATA = 'base-data';
export const ROUTE_LOCATIONS = 'locations';
export const ROUTE_SHIPPING_COMPANIES = 'shipping-companies';
export const ROUTE_TRIPS = 'trips';
export const ROUTE_USER_TRIPS = 'user-trips';
export const ROUTE_PROFILE = 'profile';
export const ROUTE_USERS = 'users';
export const ROUTE_VESSELS = 'vessels';
export const ROUTE_ZONES = 'zones';

const routes: Routes = [
    {
        path: 'account',
        loadChildren:
        accountModule
    },
    {
        path: ROUTE_DASHBOARD,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: '', component: DashboardComponent},
        ]
    },
    {
        path: ROUTE_BASE_DATA,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: '', component: BaseDataComponent},
        ]
    },
    {
        path: ROUTE_LOCATIONS,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: ':id', component: LocationDetailComponent},
        ]
    },
    {
        path: ROUTE_TRIPS,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: '', component: TripComponent},
        ]
    },
    {
        path: ROUTE_TRIPS,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: ':id', component: TripDetailComponent},
        ]
    },
    {
        path: ROUTE_USER_TRIPS,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: '', component: UserTripComponent},
        ]
    },
    {
        path: ROUTE_USER_TRIPS,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: ':id', component: UserTripDetailComponent},
        ]
    },
    {
        path: ROUTE_ZONES,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: ':id', component: ZoneDetailComponent},
        ]
    },
    {
        path: ROUTE_VESSELS,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: ':id', component: VesselDetailComponent},
        ]
    },
    {
        path: ROUTE_SHIPPING_COMPANIES,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: ':id', component: ShippingCompanyDetailComponent},
        ]
    },
    {
        path: ROUTE_PROFILE,
        component: TwoColumnComponent,
        canActivate: [adminGuard],
        children: [
            {path: '', component: ProfileComponent},
        ]
    },
    {
        path: ROUTE_USERS,
        component: TwoColumnComponent,
        canActivate: [userGuard, adminGuard],
        children: [
            {path: '', component: UsersComponent},
            {path: ':id', component: UserDetailComponent},
        ]
    },
    // otherwise redirect to home
    {
        path: '**',
        redirectTo: ROUTE_DASHBOARD
    }
];

@NgModule({
    imports: [RouterModule.forRoot(routes, {scrollPositionRestoration: 'enabled'})],
    exports: [RouterModule]
})
export class AppRoutingModule {
}
