/**
 * Program: Show/Hide according to authority
 * Author: SDL
 * Description: Show/Hide according to authority
 */

/* eslint-disable no-unused-vars */
import SDLUtil from '@/utils/SDLUtil';
import router from '@/router';

export default {
  beforeMount(el, binding) {
    // permission list of page
    const { menuUserAuthList } = router.currentRoute.value.meta;

    const userInfo = SDLUtil.getLoginedUserInfo();
    if (!userInfo.systemAdminUser) {
      // If it is not an administrator
      if (typeof binding.value === 'string') {
        if (!menuUserAuthList.includes(binding.value.toUpperCase())) {
          el.style.display = 'none';
        }
      } else {
        const perms = binding.value;
        let authflag = false;
        Object.keys(perms).forEach(i => {
          if (menuUserAuthList.includes(perms[i].toUpperCase())) {
            authflag = true;
          }
        });
        if (!authflag) {
          el.style.display = 'none';
        }
      }
    }
  },
};
