import { Component, OnInit, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { tap } from 'rxjs/operators';
import { UserOpenidService } from 'src/app/core/service/openid/user.service';

@Component({
    selector: 'invigilate-finance-form-array',
    templateUrl: './invigilate-finance-form-array.component.html',
    styleUrls: ['./invigilate-finance-form-array.component.scss'],
    // changeDetection: ChangeDetectionStrategy.OnPush
})
export class InvigilateFinanceFormArrayComponent implements OnInit {
    @Input() form: FormGroup
    @Output() remove = new EventEmitter()
    @Input() user: any = [];
    constructor(

    ) { }

    ngOnInit(): void {

    }

    setDisplayName(x){
        this.form.get('invigilator_name').setValue(x.display_name)
        this.form.get('invigilator_uid').setValue(x.user_uid)
    }

    onRemove(){
        this.remove.emit()
    }

    calculateTotal(){
        const otherCost = parseInt(this.form.get('other_cost').value == null? 0: this.form.get('other_cost').value)
        const amount = parseInt(this.form.get('amount').value == null? 0: this.form.get('amount').value)
        const sum = (otherCost+amount).toString()
        this.form.get('total_amount').setValue(sum)
    }

}
