import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { DashboardComponent } from "./dashboard.component";
import { RouterModule, Routes } from "@angular/router";
import { SidenavComponent } from "./layouts/sidenav/sidenav.component";
import { TopbarComponent } from "./layouts/topbar/topbar.component";
import { HasRoleGuard } from "src/app/cores/guards/role.guard";
import { RekapitulasiComponent } from "./pages/rekapitulasi/rekapitulasi.component";

const routes: Routes = [
  {
    path: "",
    component: DashboardComponent,
    children: [
      {
        path: "",
        redirectTo: "home",
        pathMatch: "full",
      },
      {
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SADM", "PNGL", "SVEI"],
        },
        path: "home",
        loadChildren: () =>
          import("./pages/home/home.module").then((m) => m.HomeModule),
      },
      {
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SADM", "PNGL"],
        },
        path: "data-laporan",
        loadChildren: () =>
          import("./pages/laporan/laporan.module").then((m) => m.LaporanModule),
      },
      {
        path: "data-gudang",
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SADM"],
        },
        loadChildren: () =>
          import("./pages/gudang/gudang.module").then((m) => m.GudangModule),
      },
      {
        path: "jadwal-perbaikan",
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SADM", "PNGL"],
        },
        loadChildren: () =>
          import("./pages/perbaikan/perbaikan.module").then(
            (m) => m.PerbaikanModule
          ),
      },
      {
        path: "setting",
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SADM"],
        },
        loadChildren: () =>
          import("./pages/setting/setting.module").then((m) => m.SettingModule),
      },
      {
        path: "rekapitulasi",
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SADM"],
        },
        loadChildren: () =>
          import("./pages/rekapitulasi/rekapitulasi.module").then(
            (m) => m.RekapitulasiModule
          ),
      },
      {
        path: "surveyor",
        canActivate: [HasRoleGuard],
        data: {
          access_role: ["SVEI", "SADM"],
        },
        loadChildren: () =>
          import("./pages/surveyor/surveyor.module").then(
            (m) => m.SurveyorModule
          ),
      },
      {
        path: "**",
        loadChildren: () =>
          import("../error-not-found/error-not-found.module").then(
            (m) => m.ErrorNotFoundModule
          ),
      },
    ],
  },
];

@NgModule({
  declarations: [DashboardComponent],
  imports: [
    CommonModule,
    RouterModule.forChild(routes),
    SidenavComponent,
    TopbarComponent,
  ],
})
export class DashboardModule {}
