import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { first } from 'rxjs/operators';
import { MD2Service } from '../../../../services/MD2/md2.service';
import { StateService } from '../../../../services/state.service';
import { StringUtils } from '../../../../utilities/string-utils';
import { MD2Icon, MobInfo, MobDlgType, MobType } from '../../massive-darkness2.model';
import { MD2ComponentBase } from '../../MD2Base';
import { SpawnMobDlgComponent } from '../spawn-mob-dlg/spawn-mob-dlg.component';

@Component({
  selector: 'md2-mob-stand-info',
  templateUrl: './mob-stand-info.component.html',
  styleUrls: ['./mob-stand-info.component.scss']
})
export class MobStandInfoComponent extends MD2ComponentBase implements OnInit {

  MD2Icon = MD2Icon;
  private _mob: MobInfo;
  public get mob(): MobInfo {
    return this._mob;
  }

  @Input() public set mob(v: MobInfo) {
    if (this._mob != v) {
      this._mob = v;

    }
  }

  @Input() mode: MobDlgType = MobDlgType.PreView;
  public get hideWeaponInfo(): boolean {
    return this.mode == MobDlgType.Spawn;
  }


  constructor(
    public md2Service: MD2Service,
    protected stateService: StateService,
    protected route: ActivatedRoute,
    protected cdRef: ChangeDetectorRef,
  ) {
    super(md2Service, stateService, route, cdRef);
  }

  ngOnInit(): void {
  }

  public getMobImageUrl(mob: MobInfo): string {
    if (StringUtils.isNullOrWhitespace(mob.leaderImgUrl)) {
      return mob.imageUrl;
    } else {
      return mob.leaderImgUrl;
    }
  }


  showMobImage(mob: MobInfo) {
    this.md2Service.dlgService.open(SpawnMobDlgComponent, { context: { title: `${mob.description}`, mode: MobDlgType.PreView, mob: mob } })
      .onClose.pipe(first()).subscribe(result => {

      });
  }

  public get isMob(): boolean {
    return this.mob.type == MobType.Mob;
  }

}
