import { Component, OnInit, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { RouterModule, ActivatedRoute, Router } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; import { ApiService } from '../../services/api'; import { LanguageService } from '../../services/language'; import { ThemeService } from '../../services/theme'; import { LangSwitcher } from '../lang-switcher/lang-switcher'; @Component({ selector: 'app-reset-password', standalone: true, imports: [FormsModule, RouterModule, TranslateModule, LangSwitcher], templateUrl: './reset-password.html', }) export class ResetPassword implements OnInit { password = ''; confirmPassword = ''; showPassword = signal(false); showConfirmPassword = signal(false); loading = signal(false); success = signal(false); error = signal(''); private token = ''; constructor( private api: ApiService, private route: ActivatedRoute, private router: Router, private langService: LanguageService, public themeService: ThemeService, ) { this.langService.init(); } ngOnInit(): void { this.token = this.route.snapshot.queryParamMap.get('token') ?? ''; if (!this.token) { this.error.set('auth.errors.token_missing'); } } submit(): void { this.error.set(''); if (!this.password || !this.confirmPassword) { this.error.set('auth.errors.fields_required'); return; } if (this.password !== this.confirmPassword) { this.error.set('auth.errors.passwords_mismatch'); return; } if (this.password.length < 8) { this.error.set('auth.errors.password_too_short'); return; } this.loading.set(true); this.api.confirmPasswordReset(this.token, this.password).subscribe({ next: () => { this.success.set(true); this.loading.set(false); setTimeout(() => this.router.navigate(['/login']), 3000); }, error: () => { this.error.set('auth.errors.reset_failed'); this.loading.set(false); }, }); } }