/* eslint-disable class-methods-use-this */
/* eslint-disable prefer-rest-params */
/* eslint-disable import/prefer-default-export */
import Vue from 'vue'
import eventBus from './utils/bus'
import SntToast from '../../components/SntToast/SntToast'
import { Service } from '../service'

export class Notification extends Service {
  constructor (preset) {
    super()
    this.globalOptions = preset[Notification.property]
  }

  open (options) {
    let message
    if (typeof options === 'string') message = options
    const defaultOptions = {
      message
    }
    const propsData = { ...defaultOptions, ...this.globalOptions, ...options }
    return new (Vue.extend(SntToast))({
      el: document.createElement('div'),
      propsData
    })
  }

  clear () {
    eventBus.emit('toast-clear')
  }

  success (message, options = {}) {
    return this.open({ message,
      type: 'success',
      icon: 'mdi-check-circle-outline',
      ...options
    })
  }

  error (message, options = {}) {
    return this.open({ message,
      type: 'error',
      icon: 'mdi-close-circle-outline',
      ...options
    })
  }

  info (message, options = {}) {
    return this.open({ message,
      type: 'info',
      icon: 'mdi-information-outline',
      ...options
    })
  }

  warning (message, options = {}) {
    return this.open({ message,
      type: 'warning',
      icon: 'mdi-alert-outline',
      ...options
    })
  }

  default (message, options = {}) {
    return this.open({ message,
      type: 'default',
      icon: 'mdi-bell',
      ...options
    })
  }
}

Notification.property = 'notification'
