import {NgModule} from "@angular/core";
import {RouterModule, Routes} from "@angular/router";
import {HomeComponent} from "./component/home.component";
import {
  AuthenticationGuard,
  HistoryLocationGuard,
  TaskPageRouteResolver,
  ConfirmExitGuard
} from "@webbpm/base-package";
import {DYNAMIC_ROUTING} from "../../page.routing";
import {TaskComponent} from "./../app/component/task.component";
import {TaskNotFoundComponent} from "./../app/component/task-not-found.component";

const webbpmRoutes: Routes = [
  {
    path: '',
    component: HomeComponent,
    canActivate: [AuthenticationGuard, ConfirmExitGuard],
    pathMatch: 'full',
  },
  {
    path: 'process/:processInstanceId/task/:taskId',
    component: TaskComponent,
    children: DYNAMIC_ROUTING,
    canActivate: [HistoryLocationGuard],
    resolve: {
      taskPage: TaskPageRouteResolver
    },
    runGuardsAndResolvers: "always"
  },
  {
    path: 'process/task-not-found',
    component: TaskNotFoundComponent,
    canActivate: [AuthenticationGuard]
  },
  {
    path: '**',
    redirectTo: '',
  }
];

@NgModule({
  imports: [RouterModule.forRoot(webbpmRoutes, {
    useHash: true,
    onSameUrlNavigation: "reload"
  })],
  exports: [RouterModule]
})
export class WebbpmRoutingModule {

}
