import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ListViewEventData } from 'nativescript-ui-listview';
import { WarehouseItemReservationAllOutput } from '../../entities/output/warehouseItemReservationAllOutput';

@Component({
    selector: 'MaterialReservationList',
    moduleId: module.id,
    templateUrl: './material-reservation-list-view.component.html',
    styleUrls: ['./material-reservation-list-view.component.scss']
})

export class MaterialReservationListComponent {
    @Input() reservations: WarehouseItemReservationAllOutput[];
    @Output() phoneTap = new EventEmitter<string>();
    @Output() emailTap = new EventEmitter<string>();

    templateSelector(item: any, index: number, items: any): string {
        return item.expanded ? 'expanded' : 'default';
    }

    onPhoneTap(item: WarehouseItemReservationAllOutput) {
        this.phoneTap.emit(item.Phone);
    }

    onEmailTap(item: WarehouseItemReservationAllOutput) {
        this.emailTap.emit(item.Email);
    }

    onTapItem(event: ListViewEventData) {
        this.reservations[event.index].expanded = !this.reservations[event.index].expanded;
    }

    get downIcon() {
        return String.fromCharCode(0xf107);
    }

    get rightIcon() {
        return String.fromCharCode(0xf105);
    }
}
