import store from '@/store'

/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function JSPermission(value) {
  if (value && value instanceof Array && value.length > 0) {
    const btns = store.getters && store.getters.btns
    const permissionBtns = value
    const hasPermission = btns.some(btn => {
      return permissionBtns.includes(btn)
    })
    return hasPermission
  } else {
    console.error(`need Btns! Like v-permission="['admin','editor']"`)
    return false
  }
}
