import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
import { NgFor } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import { Game } from 'app/model/Game';
import format from 'ajv/dist/vocabularies/format';

@Component({
  selector: 'app-homepage',
  standalone: true,
  imports: [NgFor],
  templateUrl: './home.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export default class HomeComponent implements OnInit {
  isDepositSuccessful = false;

  public route = inject(ActivatedRoute);
  public router = inject(Router);

  ngOnInit() {
    this.isDepositSuccessful = this.route.snapshot.queryParams['success'] == 'true';

    this.router.navigate([], { queryParams: {} });

    if (this.isDepositSuccessful) {
      this.openDepositConfirmationModal();
    }
  }

  featuredGames: Game[] = [
    {
      id: '1',
      name: 'Coinflip',
      image: '/coinflip.png',
      route: '/game/coinflip',
    },
    {
      id: '2',
      name: 'Blackjack',
      image: '/blackjack.webp',
      route: '/game/blackjack',
    },
    {
      id: '3',
      name: 'Slots',
      image: '/slots.webp',
      route: '/game/slots',
    },
    {
      id: '5',
      name: 'Dice',
      image: '/liars-dice.webp',
      route: '/game/dice',
    },
    {
      id: '6',
      name: 'Lootboxen',
      image: '/lootbox.webp',
      route: '/game/lootboxes',
    },
  ];

  openDepositConfirmationModal() {
    this.isDepositSuccessful = true;
  }

  navigateToGame(route: string) {
    this.router.navigate([route]);
  }

  protected readonly format = format;
}
