
import { Component, Input } from '@angular/core';
import { RouterExtensions } from '@nativescript/angular';
import { transitionOptions } from '~/constants/shared.constants';
import { CampEventDetailOutput } from '../../../entities/camp-event-detail.types';
import { PhoneContactService } from '~/core/services/phone-contact.service';
import { UnitDetailOutput } from '~/pages/unit/entities/output/unitDetailOutput';
import { editIcon } from '~/constants/icons';
import canEditEvent, { AuthEventType } from '~/pages/event/util/authorization';

@Component({
    selector: 'CampEventBaseDetail',
    moduleId: module.id,
    templateUrl: './camp-event-base-detail.component.html',
    styleUrls: ['./_camp-event-base-detail.component.scss'],
})
export class CampEventBaseDetailComponent {
    @Input()
    eventDetail: CampEventDetailOutput;
    @Input()
    isLoading: boolean = true;
    @Input()
    units: UnitDetailOutput[]
    constructor(
        private routerExtensions: RouterExtensions,
        private phoneContactSrv: PhoneContactService,
    ) {
    }

    openUnit(id: number) {
        setTimeout(() => {
            this.routerExtensions.navigate(['unit', id], { transition: transitionOptions });
        }, 10);
    }

    onEdit() {
        setTimeout(() => {
            this.routerExtensions.navigate(['event/campUpdate', this.eventDetail.ID],
                { transition: transitionOptions });
        }, 10);
    }
    isEditable() {
        return canEditEvent(this.eventDetail.ID_Unit, AuthEventType.CAMP) &&
            ['approvedLeader', 'approvedParent'].indexOf(this.eventDetail.ID_EventCampState) === -1
    }

    onCreateCall(phoneNumber: string) {
        this.phoneContactSrv.createCall(phoneNumber);
    }
    get editIcon() { return editIcon }

}