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

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

@Component({
    selector: 'app-guildwar-champions',
    imports: [DecimalPipe, MatCardModule, MatDividerModule, MatIconModule],
    templateUrl: './guildwar-champions.component.html',
    styleUrl: './guildwar-champions.component.scss',
})
export class GuildwarChampionsComponent implements OnInit {
    private _championsByPower: HWMember[] = [];
    public guildMembers: HWMember[] = [];
    public color: string = 'primary';
    public teamType: string = '';
    public title = 'Champions';
    public subtitle = 'by power';

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

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

    ngOnInit() {
        switch (this.teamType) {
            case 'heroes':
                this.color = 'navy';
                this.subtitle = 'heroes power';
                this.guildMembers.sort((a, b) => (a.heroes.power > b.heroes.power ? -1 : 1)); // Descending
                this._championsByPower = this.guildMembers.filter((member) => member.champion === true);
                break;
            case 'titans':
                this.color = 'purple';
                this.subtitle = 'titans power';
                this.guildMembers.sort((a, b) => (a.titans.power > b.titans.power ? -1 : 1)); // Descending
                this._championsByPower = this.guildMembers.filter((member) => member.champion === true);
                break;
            default:
                break;
        }
    }

    getChampionsByPower(): HWMember[] {
        return this._championsByPower;
    }
}
