import {
  ApplicationRef,
  Component,
  ComponentFactoryResolver,
  Injector,
  NgZone,
  OnInit,
  ViewChild
} from '@angular/core';
import {AuthService} from '../../../public/services/auth.service';
import {latLng, Layer, tileLayer} from 'leaflet';
import {} from '@types/googlemaps';
import {GeneralComponent} from '../../../public/baseComponent/general/general.component';
import {AddressComponent} from './address/address.component';
import {Dialog} from '../../../public/dialog';
import {Router} from '@angular/router';

declare let google: any;

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss'],
})
export class MapComponent extends GeneralComponent implements OnInit {
  lat;
  lng;
  map: google.maps.Map;
  @ViewChild('map1') map1;
  //
  // /**
  //  * @param data etelaat dialog marbot be map
  //  */
  constructor(private aut: AuthService,
              protected dialog: Dialog,
  ) {
    super(null, dialog, AddressComponent); // todo in moshkel dare
  }


  ngOnInit() {
    this.aut.currentUser.subscribe(user => {
        if (user) {
          this.lat = user.attributes.lat;
          this.lng = user.attributes.lng;

          const mapProp = {
            center: new google.maps.LatLng(this.lat, this.lng),
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          this.map = new google.maps.Map(this.map1.nativeElement, mapProp);

          const marker = new google.maps.Marker({
            position: mapProp.center,
            title: 'bimar'
          });
          marker.setMap(this.map);
          marker.addListener('click', (e) => {
            this.opendialog();
          });
        }
      }
    );

  }


}




