import { Routes } from '@angular/router';
import { LoginPasswordComponent } from './auth/login-password/login-password.component';
import { SignupPasswordComponent } from './auth/signup-password/signup-password.component';
import { UserProfileComponent } from './user-profile/user-profile.component';
import {
  canActivate,
  redirectLoggedInTo,
  redirectUnauthorizedTo,
} from '@angular/fire/auth-guard';
import { PendingScoreGuard } from './score/pending-score.guard';
import { ScoreTableComponent } from './score-table/score-table/score-table.component';
import { ResetPwComponent } from './auth/resetPw/resetPw.component';
import { EmailVerificationModalComponent } from './auth/email-verification-modal/email-verification-modal.component';
import { FinishSignupComponent } from './auth/finish-signup/finish-signup.component';
import { SignupComponent } from './auth/signup/signup.component';
import { LoginComponent } from './auth/login/login.component';

const redirectToHome = () => redirectLoggedInTo(['score-table']);

export const routes: Routes = [
  {
    path: 'score-table',
    component: ScoreTableComponent,
  },
  { path: 'login', component: LoginComponent, ...canActivate(redirectToHome) },
  {
    path: 'finish-signup',
    component: FinishSignupComponent,
  },
  {
    path: 'user-profile',
    component: UserProfileComponent,
    canActivate: [PendingScoreGuard],
  },
  {
    path: 'user-profile/:id',
    component: UserProfileComponent,
  },
  {
    path: 'reset-password',
    component: ResetPwComponent,
    ...canActivate(redirectToHome),
  },
  {
    path: 'email-verification',
    component: EmailVerificationModalComponent,
  },

  { path: '', redirectTo: '/score-table', pathMatch: 'full' },
];
