import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { WelcomeComponent } from "./components/welcome/welcome.component";
import { LoginComponent } from "./components/login/login.component";
import { RegisterComponent } from "./components/register/register.component";
import { ResourcePageComponent } from "./components/resource-page/resource-page.component";
import { ChatLayoutComponent } from "./components/resource-page/chat-layout/chat-layout.component";
import { DriveWindowComponent } from "./components/resource-page/drive-window/drive-window.component";
import { SettingsComponent } from "./components/settings/settings.component";
import { SearchViewComponent } from "./components/search-view/search-view.component";
import { DownloadManagerComponent } from "./components/download-manager/download-manager.component";
import { ActionQueueComponent } from "./components/action-queue/action-queue.component";
import { NanoLicenseComponent } from "./components/nano-license/nano-license.component";
import { NanoLicenseBuyComponent } from "./components/nano-license-buy/nano-license-buy.component";
import { RoomDetailsComponent } from "./components/resource-page/room-details/room-details.component";
import { NanoManagerComponent } from "./components/nano-manager/nano-manager.component";
import { TimedOffersComponent } from "./components/timed-offers/timed-offers.component";
import { AccountSettingsComponent } from "./components/account-settings/account-settings.component";
import { RegisterConfirmComponent } from "./components/register-confirm/register-confirm.component";
import { AboutComponent } from "./components/about/about.component";
import { PendingChangesGuard } from "./shared/guards/pending-changes.guard";
import { ContactListComponent } from "./components/contact-list/contact-list.component";
import { AccountRecoveryComponent } from "./components/account-recovery/account-recovery.component";
import { AccountRecoveryConfirmComponent } from "./components/account-recovery-confirm/account-recovery-confirm.component";
import { LogoutPromptGuard } from "./shared/guards/logout-prompt.guard";
import { IsLoggedInGuard } from "./shared/guards/is-logged-in.guard";
import { MainPageGuard } from "./shared/guards/main-page.guard";
import { RegisterConfirmGuard } from "./shared/guards/register-confirm.guard"
import { AdvancedSettingsComponent } from "./components/advanced-settings/advanced-settings.component";
import { SaleCodeManagerComponent } from "./components/sale-code-manager/sale-code-manager.component";
import { SimplepayBackComponent } from "./components/simplepay-back/simplepay-back.component";
import { SessionHandlerComponent } from "./components/session-handler/session-handler.component";
import { AggregateStatsComponent } from "./components/aggregate-stats/aggregate-stats.component";

export const routes: Routes = [
  { path: "login", component: LoginComponent, canActivate: [IsLoggedInGuard] },
  { path: "logout", children: [], canActivate: [LogoutPromptGuard] },
  { path: "settings", component: SettingsComponent },
  { path: "register", component: RegisterComponent, canActivate: [IsLoggedInGuard] },
  { path: "register-confirm", component: RegisterConfirmComponent, canActivate: [RegisterConfirmGuard] },
  { path: "advanced-settings", component: AdvancedSettingsComponent },
  { path: "register", component: RegisterComponent },
  { path: "register-confirm", component: RegisterConfirmComponent },
  { path: "download", component: DownloadManagerComponent },
  { path: "action-queue", component: ActionQueueComponent },
  { path: "search/:resourceId" /*#query*/, component: SearchViewComponent },
  { path: "licenses", component: NanoLicenseComponent, canActivate: [IsLoggedInGuard] },
  { path: "license-buy", component: NanoLicenseBuyComponent, canActivate: [IsLoggedInGuard] },
  { path: "simplepay-back", component: SimplepayBackComponent },
  { path: "nano-manager", component: NanoManagerComponent, canActivate: [IsLoggedInGuard] },
  { path: "sale-code-manager", component: SaleCodeManagerComponent, canActivate: [IsLoggedInGuard] },
  { path: "account", component: AccountSettingsComponent, canActivate: [IsLoggedInGuard] },
  { path: "about", component: AboutComponent },
  { path: "contact-list", component: ContactListComponent, canActivate: [IsLoggedInGuard] },
  { path: "offers", component: TimedOffersComponent, canActivate: [IsLoggedInGuard] },
  { path: "account-recovery", component: AccountRecoveryComponent },
  { path: "account-recovery-confirm", component: AccountRecoveryConfirmComponent },
  { path: "session-handler", component: SessionHandlerComponent, canActivate: [IsLoggedInGuard] },
  { path: "nano-metrics", component: AggregateStatsComponent, canActivate: [IsLoggedInGuard] },
  {
    path: "room/:id",
    component: ResourcePageComponent,
    children: [
      { path: "chat/:type", component: ChatLayoutComponent },
      { path: "drive" /*#path*/, component: DriveWindowComponent },
      { path: "details", component: RoomDetailsComponent, canDeactivate: [PendingChangesGuard] },
    ],
  },
  { path: "", component: WelcomeComponent, canActivate: [MainPageGuard], runGuardsAndResolvers: "always" },
];

@NgModule({
  imports: [RouterModule.forRoot(routes, { relativeLinkResolution: "legacy", onSameUrlNavigation : "reload" })],
  exports: [RouterModule],
  providers: [],
})
export class AppRoutingModule {}
