import { Injectable } from '@angular/core';
import { DrawingBag, MD2HeroInfo, MD2Icon, MobInfo, TreasureItem, TreasureType } from '../../games/massive-darkness2/massive-darkness2.model';
import { FileService } from '../file.service';
import { MD2GameInfo } from './md2.service';
import { MD2MobInfo } from '../../games/massive-darkness2/massive-darkness2.db.model';

@Injectable({
  providedIn: 'root'
})
export class MD2StateService {

  private _highestPlayerLevel: number = 1;
  private _playerAmount: number = 2;

  public info: MD2GameInfo;
  public playerHero: MD2HeroInfo;
  public mobInfos: MD2MobInfo[] = [];
  public mobDeck: DrawingBag<MobInfo>;
  public roamingMobDeck: DrawingBag<MobInfo>;
  public treasureBag: DrawingBag<TreasureItem> = new DrawingBag<TreasureItem>();

  constructor(
    public fileService: FileService,
  ) { }

  public iconHtml(icon: MD2Icon, cssClass = '') {


    if (icon == MD2Icon.Fire) {
      cssClass += ' g-color-google-plus ';
    }
    if (icon == MD2Icon.Frost || icon == MD2Icon.Mana) {
      cssClass += ' g-color-aqua ';
    }
    if (icon < MD2Icon.RedDice) {
      return `<span md2-icon='${String.fromCharCode(65 + icon)}' class='MD2Icon ${cssClass}'>${String.fromCharCode(65 + icon)}</span>`
    } else if (icon < MD2Icon.TreasureToken) {
      return `<span md2-icon='${String.fromCharCode(65 + icon)}' class='MD2Icon dice ${MD2Icon[icon].replace('Dice', '')} ${cssClass}'></span>`;
    } else {
      if (!cssClass) {
        cssClass = 'g-height-25 mr-1';
      }
      //image based icons
      switch (icon) {

        case MD2Icon.HP_Color:
          return this.imgHtml('HeartIcon.png', cssClass);
        case MD2Icon.Mana_Color:
          return this.imgHtml('ManaIcon.png', cssClass);
        case MD2Icon.CorruptToken:
          return this.imgHtml('Tokens/CorruptToken.png', cssClass);
        case MD2Icon.TimeToken:
          return this.imgHtml('Tokens/TimeToken.png', cssClass);
        case MD2Icon.FireToken:
          return this.imgHtml('Tokens/FireToken.png', cssClass);
        case MD2Icon.FrozenToken:
          return this.imgHtml('Tokens/FrozenToken.png', cssClass);
        case MD2Icon.TreasureToken:
          return this.imgHtml('TreasureToken/Cover.png', cssClass);
        case MD2Icon.TreasureToken_Common:
          return this.imgHtml('TreasureToken/Common.png', cssClass);
        case MD2Icon.TreasureToken_Rare:
          return this.imgHtml('TreasureToken/Rare.png', cssClass);
        case MD2Icon.TreasureToken_Epic:
          return this.imgHtml('TreasureToken/Epic.png', cssClass);
        case MD2Icon.TreasureToken_Legendary:
          return this.imgHtml('TreasureToken/Legendary.png', cssClass);
      }
    }
  }

  public imgHtml(imgPath: string, cssClass = 'g-height-25 mr-1') {
    return `<img src='${this.imgUrl(imgPath)}' class='${cssClass}'>`;
  }

  public imgUrl(imgPath: string) {
    return this.fileService.ImageUrl('MD2/' + imgPath);
  }
  public treasureImage(type: TreasureType) {
    return this.imgUrl(`TreasureToken/${TreasureType[type]}.png`);
  }
  public treasureImageHtml(type: TreasureType) {
    return this.imgHtml(`TreasureToken/${TreasureType[type]}.png`, 'g-height-40 mr-1');
  }
}
