import { Component, Input } from '@angular/core';
import { DecimalPipe } from '@angular/common';
import { MatCardModule } from '@angular/material/card';
import { MatChipsModule } from '@angular/material/chips';
import { MatIconModule } from '@angular/material/icon';

//import { Errors } from '@models';
//import { HWMember, HWGuildWarFortification, HWGuildWarHeroTeam, HWGuildWarTitanTeam } from '@models';
import { HWGuildWarFortification, HWMember } from '@models';

@Component({
    selector: 'app-fortification-card-content',
    templateUrl: './fortification-card-content.component.html',
    styleUrl: './fortification-card-content.component.scss',
    imports: [DecimalPipe, MatCardModule, MatChipsModule, MatIconModule],
})
export class FortificationCardContentComponent {
    public data: HWGuildWarFortification = {} as HWGuildWarFortification;
    public teamType: string = '';
    public guildMembers: HWMember[] = [];
    //public errorList: string[] = [];

    @Input() set fortification(data: HWGuildWarFortification) {
        this.data = data;
    }

    @Input() set type(value: string) {
        this.teamType = value;
    }

    @Input() set members(value: HWMember[]) {
        this.guildMembers = value;
    }

    getMemberNameById(id: string): string {
        let name = '';
        this.guildMembers.some((item) => {
            if (item.id === id) {
                name = item.name;
                return true;
            }
            return false;
        });
        return name;
    }

    getMemberHeroesPowerById(id: string): number {
        let power = 0;
        this.guildMembers.some((item) => {
            if (item.id === id) {
                power = item.heroes.power;
                return true;
            }
            return false;
        });
        return power;
    }

    getMemberTitansPowerById(id: string): number {
        let power = 0;
        this.guildMembers.some((item) => {
            if (item.id === id) {
                power = item.titans.power;
                return true;
            }
            return false;
        });
        return power;
    }
    /*
    @Input() set errors(errorList: Errors | null) {
        this.errorList = errorList
            ? Object.keys(errorList.errors || {}).map(
                (key) => `${key} ${errorList.errors[key]}`,
            )
            : [];
    }
    */
}
