/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { Component, OnInit } from '@angular/core';
import { NotificationItem, NotificationService, NotificationTypes } from '@bci-web-core/core';

@Component({
  selector: 'bci-toast-demo',
  templateUrl: './toast-demo.component.html',
  styleUrls: ['./toast-demo.component.scss'],
})
export class ToastDemoComponent implements OnInit {
  text = 'Item has been saved.';
  detailedMessage = '';
  action = '';
  notificationType: NotificationTypes = NotificationTypes.Success;
  link = '';
  NotificationTypes = NotificationTypes;
  sessionNotifications: NotificationItem[];

  constructor(private notify: NotificationService) {}

  ngOnInit() {
    this.notify.getSessionNotifications().subscribe((notifications: NotificationItem[]) => {
      this.sessionNotifications = notifications.reverse();
    });
  }

  openNotification(): void {
    switch (this.notificationType) {
      case NotificationTypes.Information:
        this.notify.information(this.text, this.action, undefined, this.detailedMessage, this.link);
        break;
      case NotificationTypes.Error:
        this.notify.error(this.text, this.action, undefined, this.detailedMessage, this.link);
        break;
      case NotificationTypes.Warning:
        this.notify.warning(this.text, this.action, undefined, this.detailedMessage, this.link);
        break;
      case NotificationTypes.Success:
        this.notify.success(this.text, this.action, undefined, this.detailedMessage, this.link);
        break;
    }
  }
}
