
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { GenEventDetailOutput } from '../../../entities/gen-event-detail.types';
import { RouterExtensions } from '@nativescript/angular';
import { transitionOptions } from '~/constants/shared.constants';
import * as dialogs from "@nativescript/core/ui/dialogs";
import { deleteIcon, editIcon } from '~/constants/icons';

@Component({
    selector: 'GenEventBaseDetail',
    moduleId: module.id,
    templateUrl: './gen-event-base-detail.component.html',
    // styleUrls: ['./_gen-event-base-detail.component.scss']
})
export class GenEventBaseDetailComponent {
    @Input()
    eventDetail: GenEventDetailOutput;
    @Input()
    isLoading: boolean = true;
    @Output() deleteItem = new EventEmitter<number>();

    constructor(private routerExtensions: RouterExtensions,
    ) {
    }

    openUnit(id: number) {
        setTimeout(() => {
            this.routerExtensions.navigate(['unit', id],
                { transition: transitionOptions });
        }, 10);
    }
    get editIcon() {
        return editIcon;
    }
    onEdit() {
        setTimeout(() => {
            this.routerExtensions.navigate(['event/generalUpdate/', this.eventDetail.ID], { transition: transitionOptions });
        }, 10);
    }
    get deleteIcon() {
        return deleteIcon;
    }
    onDelete() {
        const options = {
            title: "Smazáni akce",
            message: "Opravdu chcete tuto akci smazat?",
            okButtonText: "Ano",
            cancelButtonText: "Ne"
        };
        dialogs.confirm(options).then((result: boolean) => {
            if (result) {
                this.deleteItem.emit(this.eventDetail.ID);
            };
        });
    }
}