import { AdminRoleGuard } from './../core/guards/admin-role.guard';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { RegisterComponent } from './register/register.component';
import { AuthMaterialModule } from './auth-material.module';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { LoginCardComponent } from './login/login-card/login-card.component';
import { LoginDialogComponent } from './login/login-dialog/login-dialog.component';
import { ProfileComponent } from './profile/profile.component';
import { ProfilesComponent } from './profiles/profiles.component';
import { UserRoleGuard } from '../core/guards/user-role.guard';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../shared/shared.module';

const authRoutes: Routes = [
  { path: 'login', component: LoginCardComponent },
  { path: 'register', component: RegisterComponent },
  { path: 'profile', component: ProfileComponent, canActivate: [UserRoleGuard] },
  { path: 'profile/:id', component: ProfileComponent, canActivate: [AdminRoleGuard] },
  { path: 'profiles', component: ProfilesComponent, canActivate: [AdminRoleGuard]},
  { path: '**', redirectTo: '/'}
];

@NgModule({
  declarations: [
    LoginCardComponent,
    LoginDialogComponent,
    RegisterComponent,
    ProfileComponent,
    ProfilesComponent
  ],
  entryComponents: [
    LoginDialogComponent
  ],
  imports: [
    CommonModule,
    SharedModule,
    ReactiveFormsModule,
    AuthMaterialModule,
    HttpClientModule,
    RouterModule.forChild(authRoutes),
  ]
})
export class AuthModule { }
