
import { Component, Input } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {StringUtils} from '../../utils/string-utils.class';

@Component({
  selector: 'feedback',
  template: `
  <div id="feedback" class="" (click) = "initialize()">
    <a [href]="feedbackQuestionaire ? feedbackQuestionaire : ('mailto:' + feedbackmail +'?Subject=' + subject + '&body=' + body)"
       [target]="feedbackQuestionaire ? '_blank' : '_top'" type="button" class="">
  		<img src="data:image/svg+xml;base64,[encoded data, 5928 characters]" 
           alt="Feedback" title="Feedback Button" height="70px" loading="lazy">
  	</a>
  </div>


`
})
export class FeedbackComponent {
  @Input()feedbackQuestionaire:string = "";
  @Input()feedbackmail:string = "someone@example.com";
  @Input()portalName:string = "Explore";
  public subject:string;
  public body:string = "Send from page";

  sub:any;
  constructor(private  route: ActivatedRoute) {}

  ngOnInit() {
    // this.feedbackmail = OpenaireProperties.getFeedbackMail();
    this.subject = "[Feedback - OpenAIRE "+this.portalName+"]";
    this.initialize();
    this.sub =  this.route.queryParams.subscribe(params => {
      this.initialize();
    });
  }
  ngOnDestroy(){
    this.sub.unsubscribe();
  }
  initialize(){
    var referrer = null;
    if (typeof location !== 'undefined') {
        referrer = location.href;
       }

    this.body = "[Please write your message here] \n\n\nOpenAIRE " + this.portalName + " \nSent from "+((referrer)?referrer:" [referrer not available]")+ "  \n(please don't delete this part of the message)";
    this.body = StringUtils.URIEncode(this.body);
    // this.subject = StringUtils.URIEncode(this.subject);

  }



}
