import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ListViewEventData } from 'nativescript-ui-listview';
import { ModalDialogService, registerElement } from '@nativescript/angular';
import { CongEventOutput } from '~/pages/event/entities/cong-event-search.types';
import { CongEventSearch } from '~/pages/event/state-mgmt/cong/cong-event-search-list.state';
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 { ScrollTopBarListComponent } from './../../common/scroll-top-bar-list/scroll-top-bar-list.component';
import { personDetailIcon, unitDetailIcon } from '~/constants/icons';

registerElement("CongEventListView", () => { return ContentView });
interface ListType extends CongEventOutput {
    extended: boolean;
}
@Component({
    selector: 'CongEventListView',
    moduleId: module.id,
    templateUrl: './cong-event-list.component.html',
    styleUrls: ['./_cong-event-list.component.scss'],
    providers: [ModalDialogService],

})
export class CongEventListComponent extends ScrollTopBarListComponent<ListType> {

    @Input()
    isSearchSortDirty: boolean
    @Input()
    tags: SortSearchTag[];
    @Input()
    searchParams: CongEventSearch;
    @Input()
    actionList: ActionBarAction[];

    @Output()
    resetSortSearchAction = new EventEmitter()
    @Output()
    showEvent = new EventEmitter<CongEventOutput>();
    @Output()
    refreshData = new EventEmitter();
    @Output()
    showUnit = new EventEmitter();
    @Output()
    onAction = new EventEmitter()

    currentDate = new Date();
    personDetailIcon = personDetailIcon;
    unitDetailIcon = unitDetailIcon;


    onDetailTap(id: number) {
        this.showEvent.emit(this.items.find(e => e.ID === id));
    }
    onUnitDetail(unitId: number) {
        this.showUnit.emit(unitId);
    }

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


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