import { Component, Input, inject } from '@angular/core';
import { Spell } from 'src/interfaces/interfaces';
import { ModalService } from 'src/services/modal/modal.service';
import { UtilsService } from 'src/services/utils/utils.service';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'app-full-spellcard',
  templateUrl: './full-spellcard.component.html',
  styleUrl: './full-spellcard.component.scss',
})
export class FullSpellcardComponent {
  @Input() public spell!: Spell;
  @Input() public origin: string = 'dashboard';
  @Input() public alreadyInFavorites: boolean = false;
  @Input() public alreadyPrepared: boolean = false;

  private modalService = inject(ModalService);
  public utils = inject(UtilsService);
  public translate = inject(TranslateService);

  ngAfterViewInit(): void {
    console.log(this.origin);
    console.log(this.alreadyInFavorites);
    console.log(this.alreadyPrepared);
  }

  public setBackupImage(event: any): void {
    event.target.src = 'assets/images/spells/backup.jpg';
  }

  public delete(): void {
    this.modalService.handleModalClosing('delete');
  }

  public remove(): void {
    this.modalService.handleModalClosing('remove');
  }

  public update(): void {
    this.modalService.handleModalClosing('update');
  }

  public copy(): void {
    this.modalService.handleModalClosing('copy');
  }

  public addToFavorites(): void {
    this.alreadyInFavorites = true;
    this.modalService.sendMessage('addToFavorites');
  }

  public removeFromFavorites(): void {
    this.alreadyInFavorites = false;
    this.modalService.sendMessage('removeFromFavorites');
  }

  public addToPrepared(): void {
    this.alreadyPrepared = true;
    this.modalService.sendMessage('addToPrepared');
  }

  public removeFromPrepared(): void {
    this.alreadyPrepared = false;
    this.alreadyInFavorites = false;
    this.modalService.sendMessage('removeFromPrepared');
  }
}
