import { Component, OnInit, Input } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { WpServiceService } from '../wp-service.service';

@Component({
  selector: 'app-placedetail',
  templateUrl: './placedetail.page.html',
  styleUrls: ['./placedetail.page.scss'],
})
export class PlacedetailPage implements OnInit {

  data: any;
  placelist: any;

  constructor(private wpservice: WpServiceService, private route: ActivatedRoute, private router: Router) { }
  @Input() id: string;
  showDiss = false;


  ngOnInit() {
    if (this.id != undefined) {
      this.showDiss = true;
    }
    // console.log("showDiss ", this.showDiss);
    // let id = this.route.snapshot.paramMap.get('id') || this.id;
    // console.log("fetching ...");
    // this.wpservice.getPlaceDetail(id).subscribe(data => {
      // let post = JSON.parse(data.data);
      // console.log(" get data ", post);
      // post['media_url'] = post['_embedded']['wp:featuredmedia'][0]['media_details'].sizes['medium'].source_url;
      // this.data = post;
    let id = this.route.snapshot.paramMap.get('id') || this.id;
    console.log("fetching ...");
    this.wpservice.getPlaceDetail(id).subscribe((data) => {
      this.placelist = data;      
      console.log("load Place Detail ...");
      console.log(data);
    }, error => {
      console.log("errror ", error);
    });
  }

}
