import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MD2MobService } from '../../../../services/MD2/md2-mob.service';
import { MD2Service } from '../../../../services/MD2/md2.service';
import { StateService } from '../../../../services/state.service';
import { MD2Icon, MobDlgType, MobInfo } from '../../massive-darkness2.model';
import { MD2ComponentBase } from '../../MD2Base';

@Component({
  selector: 'md2-mob-detail-info',
  templateUrl: './mob-detail-info.component.html',
  styleUrls: ['./mob-detail-info.component.scss']
})
export class MobDetailInfoComponent extends MD2ComponentBase implements OnInit {
  MobDlgType = MobDlgType;
  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;
  }

  public get hideCombatInfo(): boolean {
    return this.mode == MobDlgType.Dashboard;
  }


  showAttackingInfo: boolean = false;
  @Input("showAttackingInfo")
  public set input_showAttackingInfo(value) {
    this.showAttackingInfo = typeof value !== "undefined" && value !== false;
  }


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

  ngOnInit(): void {

    if (this.mob.attackInfos) {

    }
  }
  initWeaponInfo() {

    if (this.mob.attackInfos) {

    }
  }

  public get showAdjustment(): boolean {
    return [MobDlgType.Activating, MobDlgType.BeenAttacked, MobDlgType.Dashboard].includes(this.mode);
  }
  public get showTokenAdjustment(): boolean {
    return [MobDlgType.Activating, MobDlgType.BeenAttacked].includes(this.mode);
  }

  adjustMobHp(adjustAmount: number) {
    if (adjustAmount < 0) {
      this.mobService.attackMob(this.mob, 1);
    } else {
      this.mobService.healMob(this.mob, 1);
    }
    this.md2Service.refreshUI$.next();
  }

}