import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
import { HealthProvider } from '../../providers/health/health';
import { SocialSharing } from '@ionic-native/social-sharing';
/**
 * Generated class for the NewsReaderPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-news-reader',
  templateUrl: 'news-reader.html',
})
export class NewsReaderPage {
  obj;
  imageURL;
  constructor(public navCtrl: NavController, public navParams: NavParams, private hp: HealthProvider, private vc: ViewController, private sc: SocialSharing) {
    this.imageURL = "http://www.sportgalaxy.xyz/";
    this.hp.getGalaxyNews(this.navParams.get('id'))
      .subscribe( data => {
        this.obj = data;  
      });
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad NewsReaderPage');
  }

  dismiss() {
    this.vc.dismiss();
  }
  share(sn: string){
    console.log("share ", sn);
    //if( sn == "facebook") {
      this.sc.share(this.obj.output.title_th, "Read this",  this.imageURL + this.obj.output.feature_url, this.imageURL + "/view/"+this.obj.output._id.$oid)
        .then(() => {
        }).catch((data) => { console.log(data); });
    //}
    /*if( sn == "twitter") {
      this.sc.shareViaTwitter(this.obj.output.title_th, this.imageURL + this.obj.output.feature_url, this.imageURL + "/view/"+this.obj.output._id.$oid)
        .then(() => {
        }).catch((data) => { console.log(data); });
    }*/
  }
}
