import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';

@Injectable({
  providedIn: 'root'
})
export class ActivationService {
  private apiUrl = 'http://localhost/story/funtellocal/signup.php';

  constructor(private http: HttpClient, private router: Router) { }

  verifyAccount(token: string) {
    return this.http.get(`${this.apiUrl}?verify=1&token=${token}`).subscribe({
      next: (response: any) => {
        if (response.redirect) {
          this.router.navigateByUrl(response.redirect.split('/funtel')[1]);
        }
      },
      error: (error) => {
        this.router.navigate(['/activation-error']);
      }
    });
  }
}