const storage = (Vue) => {
  Vue.prototype.$storage = (key, val) => {
    if (!window.sessionStorage) {
      console.error('Your browser does not support sessionStorage')
      return
    }

    if (!key) {
      return window.sessionStorage
    } else if (!val) {
      return window.sessionStorage.getItem(key)
    } else {
      window.sessionStorage.setItem(key, val)
      return true
    }
  }

  Vue.prototype.$rmStorage = (key) => {
    if (key) {
      window.sessionStorage.removeItem(key)
    } else {
      window.sessionStorage.clear()
    }
  }

  const localStorage = window.localStorage
  Vue.prototype.$localStorage = function(key, val) {
    if (!key) {
      return localStorage
    } else if (!val) {
      return localStorage.getItem(key)
    } else {
      localStorage.setItem(key, val)
      return true
    }
  }

  Vue.prototype.$rmLocalStorage = function(key) {
    if (key) {
      localStorage.removeItem(key)
    } else {
      localStorage.clear()
    }
  }
}

export default storage
