import { createNode, msgBox } from '../helpers'

export default class AlertController {

  static showError () {
    this.displayDialog('Error occurred :(', 3000, 3)
  }

  /**
   *
   * @param msg
   * @param fadeOut
   * @param type
   * @param parent
   */
  static displayDialog (msg = 'Alert without message', fadeOut = 0, type = 0, parent = null) {
    const alertTypes = window.env.alertTypes
    const dialog = createNode('div', { class: `uk-alert-${alertTypes[type]} uk-padding-small` }, msg)
    parent instanceof Element ? parent.appendChild(alert) : msgBox.appendChild(dialog)

    if (fadeOut > 0) {
      setTimeout(() => {
        dialog.remove()
      }, fadeOut)
    }
  }

}