// // 工具库lodash https://lodash.com/docs/4.17.4
// import _ from 'lodash'

const APP_STORAGE = 'app_storage'

function getCache() {
    let cache = localStorage.getItem(APP_STORAGE)
    if (cache === null) {
        cache = {}
    } else {
        cache = JSON.parse(localStorage.getItem(APP_STORAGE))
    }
    return cache
}

export default {
    API_LOGIN_DOCTOR: 'api_login_doctor',
    IMEI: 'IMEI',
    setItem(key, value) {
        let cache = null

        if (!key) {
            console.error(key + ' is not allowed for storage key!')
            return
        }

        cache = getCache()
        cache[key] = value
        localStorage.setItem(APP_STORAGE, JSON.stringify(cache))
    },
    getItem(key) {
        let cache = null
        if (!key) {
            console.error(key + ' is not allowed for storage key!')
            return
        }
        cache = getCache()

        return cache[key]
    },
    getAll() {
        localStorage.getItem(APP_STORAGE)
    },
    removeItem(key) {
        let cache = null
        if (!key) {
            console.error(key + ' is not allowed for storage key!')
            return
        }
        cache = getCache()
        delete cache[key]
    },
    removeAll() {
        localStorage.removeItem(APP_STORAGE)
    }
}
