import {Component, inject, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';

@Component({
  selector: 'app-redirect',
  imports: [],
  templateUrl: './redirect.component.html',
  styleUrl: './redirect.component.scss'
})
export class RedirectComponent implements OnInit {
  private router: Router = inject(Router)
  private route: ActivatedRoute = inject(ActivatedRoute)
  private map: Record<string, string> = {
    'worlddl': 'https://www.mediafire.com/folder/zblzjurjleq6i/Altitude_servers_1.17.1',
    'grove-dl': 'https://www.mediafire.com/folder/bd6ej1i7if0y6',
  };

  private getRedirectTarget(key: string): string | null {
    const value = this.map[key];
    return value ?? null;
  }

  ngOnInit(): void {
    const type = this.route.snapshot.paramMap.get('type');

    if (type) {
      const target = this.getRedirectTarget(type);
      if (target) {
        window.location.href = target;
      } else {
        this.router.navigate(['/']).then();
      }
    } else {
      this.router.navigate(['/']).then();
    }
  }
}
