import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AdminIframePageComponent } from './components/admin-portal/admin-iframe-page/admin-iframe-page.component';
import { AdminPortalLayoutComponent } from './components/admin-portal/admin-portal-layout/admin-portal-layout.component';
import { EditMessageTemplateComponent } from './components/admin-portal/edit-message-template/edit-message-template.component';
import { EditWorkflowTemplateComponent } from './components/admin-portal/edit-workflow-template/edit-workflow-template.component';
import { ListMessageTemplateComponent } from './components/admin-portal/list-message-template/list-message-template.component';
import { ListWorkFlowsComponent } from './components/admin-portal/list-work-flows/list-work-flows.component';
import { ApplicantPortalLayoutComponent } from './components/applicant-portal/applicant-portal-layout/applicant-portal-layout.component';
import { EditApplicantComponent } from './components/edit-applicant/edit-applicant.component';
import { MessageEngineComponent } from './components/message-engine/message-engine.component';
import { MyCareerUsersComponent } from './components/my-career/my-career-users/my-career-users.component';
import { ViewCareerUserComponent } from './components/my-career/view-career-user/view-career-user.component';
import { SearchApplicantsComponent } from './components/search-applicants/search-applicants.component';
import { AccessDeniedComponent } from './oneit/components/access-denied/access-denied.component';
import { FullLayoutComponent } from './oneit/components/full-layout/full-layout.component';
import { HomeComponent } from './oneit/components/home/home.component';
import { IframePageComponent } from './oneit/components/iframe-page/iframe-page.component';
import { AuthGuard } from './oneit/guards/auth.guard';

export const routes: Routes = [
    {
        path: '',
        redirectTo: 'home',
        pathMatch: 'full'
    },
    {
        path: '',
        component: FullLayoutComponent,
        data: {
            showDefaultHeader: true,
            showDefaultFooter: true,
            showMenu: true,
            showFeedback: true
        },
        children: [
            {
                path: 'access-denied',
                component: AccessDeniedComponent
            },
            {
                path: 'home',
                canActivate: [AuthGuard],
                component: HomeComponent
            },
            {
                path: 'iframe-page/:url',
                canActivate: [AuthGuard],
                component: IframePageComponent,
                runGuardsAndResolvers: 'always'
            },
            {
                path: 'list-message-templates/:global',
                component: ListMessageTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-message-template/:global',
                component: EditMessageTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-message-template/:global/:id',
                component: EditMessageTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'list-workflow-templates/:global',
                component: ListWorkFlowsComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-workflow-template/:global',
                component: EditWorkflowTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-workflow-template/:global/:id',
                component: EditWorkflowTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'search-applicant',
                canActivate: [AuthGuard],
                component: SearchApplicantsComponent,
                runGuardsAndResolvers: 'always'
            },
            {
                path: 'edit-applicant/:id',
                canActivate: [AuthGuard],
                component: EditApplicantComponent,
                runGuardsAndResolvers: 'always'
            }
        ]
    },
    {
        path: 'admin',
        component: AdminPortalLayoutComponent,
        canActivate: [AuthGuard],
        data: {
            privs: ['TL_AccessAdminPortal'],
            redirectPage: 'extensions/adminportal/sign_in.jsp'
        },
        children: [
            {
                path: 'iframe-page/:url',
                component: AdminIframePageComponent,
                runGuardsAndResolvers: 'always'
            },
            {
                path: 'edit-message-template',
                component: EditMessageTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-message-template/:id',
                component: EditMessageTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'list-message-templates',
                component: ListMessageTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'list-workflow-templates',
                component: ListWorkFlowsComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-workflow-template',
                component: EditWorkflowTemplateComponent,
                canActivate: [AuthGuard]
            },
            {
                path: 'edit-workflow-template/:id',
                component: EditWorkflowTemplateComponent,
                canActivate: [AuthGuard]
            }
        ]
    },
    {
        path: 'applicant/:job/job/:jobId',
        component: ApplicantPortalLayoutComponent,
        canActivate: [AuthGuard],
        data: {
            privs: ['TL_AccessApplicantPortal'],
            redirectPage: 'ApplicantPortal-ApplyJob.htm?cms.rm=SignIn&JobID=:jobId&JobAppID=:jobAppId'
        },
        children: [
            {
                path: 'home',
                component: HomeComponent
            },
            {
                path: 'message-engine',
                component: MessageEngineComponent
            }
        ]
    },
    {
        path: 'my-career',
        component: FullLayoutComponent,
        canActivate: [AuthGuard],
        data: {
            redirectPage: 'editor/index.jsp'
        },
        children: [
            {
                path: 'my-career-users',
                component: MyCareerUsersComponent
            },
            {
                path: 'view-career-user/:id',
                component: ViewCareerUserComponent
            }
        ]
    },
    {
        path: 'my-career-web',
        // @ts-ignore
        loadChildren: "./components/my-career-web/my-career-web.module#MyCareerWebModule"
    }
];

@NgModule({
    imports: [RouterModule.forRoot(routes, {useHash: true, onSameUrlNavigation: 'reload'})],
    exports: [RouterModule]
})
export class AppRoutingModule {
}
