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

registerElement("UnitListView", () => { return ContentView });
interface ListType extends UnitAllOutput {
    extended: boolean;
}
@Component({
    selector: 'UnitListView',
    moduleId: module.id,
    templateUrl: './unit-list-view.component.html',
    styleUrls: ['./_unit-list-view.component.scss'],
    providers: [ModalDialogService],

})
export class UnitListViewComponent extends ScrollTopBarListComponent<ListType> {

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

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

    currentDate = new Date();

    constructor(private routerExtensions: RouterExtensions,
    ) {
        super()
    }
    onDetailTap(id: number) {
        setTimeout(() => {
            this.routerExtensions.navigate(['unit', id], { transition: transitionOptions });
        }, 10);
    }

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