import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApiService as ApiService } from '../../services/login-api';
import { RaidData } from '../../../../../../backend/Types/Types';
import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';

@Component({
  selector: 'archive',
  templateUrl: './raid.component.html',
})
export class FrontcraftArchiveComponent implements OnInit{

    canSignup = false
    isSignedup = false
    canManage = false
    isTier = false
    mySignup

    raid: RaidData = <any>{
      participants:{
          Druid: [],
          Hunter: [],
          Mage: [],
          Paladin: [],
          Priest: [],
          Rogue: [],
          Shaman: [],
          Warlock: [],
          Warrior: [],
      },
      tokens:{},
      tanks:[],
      healers: []
    }
    tokens = {}
    displayedtokens = {}
    search = ""
    
    constructor(
      private api: ApiService,
      private route: ActivatedRoute,
    ){
    }

    async ngOnInit(){
      this.refresh()
    }

    refresh = async () => {
      const param = this.route.snapshot.paramMap.get('id');

      const raidManager = this.api.get('RaidManager')
      const raiddata = await raidManager.getArchiveRaid(parseInt(param))
      this.raid = raiddata
      this.tokens = raiddata.tokens;

      [
        ...raiddata.tanks, 
        ...raiddata.healers, 
        ...Object.values(raiddata.participants).flat()
      ].forEach(p => {
        p['color'] = getClassColor(p.class)
      })

      this.changeSearch()
    }

    changeSearch = () => {
      this.tokens = this.raid.tokens;
      this.displayedtokens = this.raid.tokens;
    }
}