import { Component, Input } from "@angular/core";
import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";

/**
 * Generated class for the ProfileHeaderComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: "profile-header",
  templateUrl: "profile-header.html"
})
export class ProfileHeaderComponent {
  @Input()
  user: any;

  constructor(private twitter: TwitterApiProvider) {}

  get banner() {
    if (this.user.profile_banner_url) {
      return this.user.profile_banner_url + "/1500x500";
    } else {
      return this.user.profile_background_image_url_https;
    }
  }

  async follow(userId) {
    await this.twitter.createFriendship(userId);
    this.user.following = true;
  }

  async unfollow(userId) {
    await this.twitter.destroyFriendship(userId);
    this.user.following = false;
  }
}
