import { Component, Injector, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ControllerRouteDetailServiceProxy} from '@shared/service-proxies/service-proxies';
import { AppSessionService } from '@shared/common/session/app-session.service';
import { Table } from "primeng/table";
import { LazyLoadEvent } from "primeng/primeng";
import { Paginator } from 'primeng/components/paginator/paginator';
import { finalize } from 'rxjs/operators';
import * as _ from 'lodash';
declare var $: any;
declare var jquery:any;
@Component({
    selector:'hf-route-detail',
    templateUrl: 'hf-route-detail.component.html',
    encapsulation: ViewEncapsulation.None,
    styleUrls: ['./route-detail.component.less'],
    animations: [appModuleAnimation()]
})

export class HFRouteDetailComponent extends AppComponentBase implements OnInit {

    routeId:number = null;
    filterText = '';
    @ViewChild("dataTable", {static: true}) dataTable:Table
    @ViewChild("paginator", {static: true}) paginator: Paginator
	constructor(
        injector: Injector,
        private id:ActivatedRoute,
        private _controllerRouteDetails: ControllerRouteDetailServiceProxy,
        private _appSessionService :AppSessionService,
        
    ) {
        super(injector);
    }

    ngOnInit(){

        this.id.paramMap.subscribe(params => {
            this.routeId = Number(params.get('id'));
        });
    }

    getRouteDetails(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }

        this.spinnerService.show();

        this._controllerRouteDetails
        .getControllerRouteDetailList(
            undefined,
            this.routeId,
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event))
        .pipe(finalize(() => this.spinnerService.hide() ))
        .subscribe(result => {
            this.primengTableHelper.totalRecordsCount = result.totalCount;
            this.primengTableHelper.records = result.items;
        });
    }

    toggleMoreInfo(event){
        var element = event.currentTarget.nextSibling;
        var selector = document.querySelectorAll('.more-info-container.active');
        var hover = document.querySelectorAll('.more-btn.hover');

        if(element.classList.contains('active')){
            event.currentTarget.classList.remove('hover');
            element.classList.remove('active');
        } else {
            if(selector.length > 0){
                selector[0].classList.remove('active');
                hover[0].classList.remove('hover');
                // event.currentTarget.classList.remove('hover');
            } 
            element.classList.add('active');
            event.currentTarget.classList.add('hover');
        }

    }

    onShown(){
        
    }


}