// #docregion
import {OnInit} from '@angular/core';
// #docregion example
/* avoid */

export class ToastComponent implements OnInit {
  private defaults = {
    title: '',
    message: 'May the Force be with you',
  };
  message: string;
  title: string;
  private toastElement: any;

  ngOnInit() {
    this.toastElement = document.getElementById('toh-toast');
  }

  // private methods
  private hide() {
    this.toastElement.style.opacity = 0;
    setTimeout(() => (this.toastElement.style.zIndex = 0), 400);
  }

  activate(message = this.defaults.message, title = this.defaults.title) {
    this.title = title;
    this.message = message;
    this.show();
  }

  private show() {
    console.log(this.message);
    this.toastElement.style.opacity = 1;
    this.toastElement.style.zIndex = 9999;

    setTimeout(() => this.hide(), 2500);
  }
}
// #enddocregion example
