import { Component, Input } from '@angular/core';
import { UnitRegistrationMembersAgeOutput } from '~/pages/unit/entities/output/unitRegistrationMembersAgeOutput';

@Component({
    moduleId: module.id,
    selector: 'UnitStatsMembersSum',
    templateUrl: './unit-stats-members-sum.component.html',
    styleUrls: ['./unit-stats-members-sum.component.scss']
})
export class UnitStatsMembersSumComponent {
    membersSumData: any;

    @Input() set unitRegistrationMembersAges(values: UnitRegistrationMembersAgeOutput[]) {
        if (values) {
            this.membersSumData = values.reduce((acc: any, curr) => {
                let addMembers = 0;
                let addFHMembers = 0;

                if (['RadneCasopis', 'Radne', 'Cestne', 'HostovaniCizi'].indexOf(curr.Row) !== -1) {
                    addMembers = +curr.Count;
                }

                if (['RadneCasopis', 'Radne', 'Cestne'].indexOf(curr.Row) !== -1) {
                    addFHMembers = +curr.Count;
                }

                acc.sumMembers += addMembers;
                acc.sumfHMembers += addFHMembers;

                return acc;
            }, { sumMembers: 0, sumfHMembers: 0 });
        } else {
            this.membersSumData = {};
        }
    }

}
