import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ListViewEventData } from 'nativescript-ui-listview';
import { ModalDialogService, registerElement, RouterExtensions } from '@nativescript/angular';
import { EduEventMyActionsOutput } from '~/pages/event/entities/edu-event-search.types';
import { ActionBarAction } from '../../common/disappearing-scroll-action-bar/disappearing-scroll-action-bar.component';
import { SortSearchTag } from '~/pages/event/types/common.types';
import { ContentView } from '@nativescript/core/ui/page';
import { transitionOptions } from '~/constants/shared.constants';
import { ScrollTopBarListComponent } from '../../common/scroll-top-bar-list/scroll-top-bar-list.component';
import icons from '~/constants/icons';

registerElement("EduEventMyListView", () => { return ContentView });


interface ListType extends EduEventMyActionsOutput {
    extended: boolean;
}
@Component({
    selector: 'EduEventMyListView',
    moduleId: module.id,
    templateUrl: './edu-event-my-list.component.html',
    styleUrls: ['./_edu-event-my-list.component.scss'],
    providers: [ModalDialogService],

})
export class EduEventMyListViewComponent extends ScrollTopBarListComponent<ListType> {
    @Input()
    actionList: ActionBarAction[];
    @Input()
    isSearchSortDirty: boolean
    @Input()
    tags: SortSearchTag[];
    @Input()
    title: string

    @Output()
    onAction = new EventEmitter()
    @Output()
    resetSortSearchAction = new EventEmitter()
    @Output()
    refreshData = new EventEmitter();

    currentDate = new Date();
    icons = icons;

    constructor(
        private routerExtensions: RouterExtensions,
    ) {
        super();
    }

    onDetailTap(id: number) {
        setTimeout(() => {
            this.routerExtensions.navigate(['event/educationDetail/',
                id], { transition: transitionOptions });
        }, 10);
    }

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

    onShowRegistration(event: EduEventMyActionsOutput) {
        setTimeout(() => {
            this.routerExtensions.navigate(['event/educationCourseEnroll/',
                event.ID, event.ID_EventEducationCourse], { transition: transitionOptions });
        }, 10);
    }


    isDateGreaterThanDate(a: string, b: Date) {
        const d = new Date(a)
        return d > b;
    }

    onPullToRefreshInitiated(args: ListViewEventData) {
        this.refreshData.emit();
        setTimeout(() => {
            const listView = args.object;
            listView.notifyPullToRefreshFinished();
        }, 100);
    }

    onResetSortSearchAction() {
        this.resetSortSearchAction.emit()
    }
}
