
// import * as M from 'materialize-css'
function Toastify (options) {
  // M.toast({ html: options.text, classes: options.classes })
}

export const Toast = {
  info: (msg) => {
    Toastify({
      text: msg,
      classes: 'info-toast'
    })
  },
  notice: (msg) => {
    Toastify({
      text: msg,
      classes: 'notice-toast'
    })
  },
  error: (msg) => {
    Toastify({
      text: msg,
      classes: 'error-toast'
    })
  }
}

export function validator (formData, fields) {
  const keys = Object.keys(formData)
  for (const key of keys) {
    if (fields.indexOf(key) !== -1) {
      if (!formData[key]) {
        Toast.error('Please Enter ' + key)
        return false
      }
    }
  }
  return true
}

export function serializeFormData (domId) {
  const formData = $('#' + domId).serializeArray()
  const obj = {}
  for (var item of formData) {
    var key = item.name
    var val = item.value
    obj[key] = val
  }
  console.log('form data', obj)
  return obj
}