import { Component, Injector, ViewChild, ViewEncapsulation, OnInit, DoCheck, Input } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { OrderServiceProxy, OrderListDto } from '@shared/service-proxies/service-proxies';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { finalize } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
@Component({
    templateUrl: './order-detail.component.html',
    encapsulation: ViewEncapsulation.None,
    animations: [appModuleAnimation()],
    styleUrls: ['./order-detail.component.less']
})
export class OrderDetailComponent extends AppComponentBase implements OnInit{

    
    zoom: number = 12;
    // initial center position for the map
    lat: number = 34.044971;
    lng: number = -118.291243;
    map: any;

    @ViewChild('dataTable', {static: true}) dataTable: Table;
    @ViewChild('paginator', {static: true}) paginator: Paginator;
    
    //Filters
    filterText = '';
    id: any;
    orderDetails: OrderListDto[] = [];
    constructor(
        injector: Injector,
        private _orderAppService: OrderServiceProxy,
        private _router: Router,
        private route: ActivatedRoute
    ) {
        super(injector);
    }


    ngOnInit(){
        

        this.route.paramMap.subscribe(params => {
            this.id = params.get("id")
            console.log(this.id);
        })


         this._orderAppService.getOrderDetail(
         this.id
         ).pipe(finalize(() => this.spinnerService.hide())).subscribe(result => {
            this.orderDetails.push(result);
            this.lat = result.pickupDetail.contact.address.geocode.latitude;
            this.lng = result.pickupDetail.contact.address.geocode.longitude;
            console.log(this.orderDetails);
            
        });
    }

    mapReady(event: any) {
        this.map = event;
            
    }

   

}
