'use strict';

require('../stores/index.js');
require('../utils/index.js');
var userInfo = require('../stores/userInfo.js');
var index = require('../utils/array/index.js');

function authDirective(app) {
  app.directive("auth", {
    mounted(el, binding) {
      const stores = userInfo.useUserInfo();
      if (!stores.userInfos.authApiList) {
        el.parentNode.removeChild(el);
      } else {
        if (!stores.userInfos.authApiList.some((v) => v === binding.value)) el.parentNode.removeChild(el);
      }
    }
  });
  app.directive("auths", {
    mounted(el, binding) {
      let flag = false;
      const stores = userInfo.useUserInfo();
      stores.userInfos.authApiList.map((val) => {
        binding.value.map((v) => {
          if (val === v) flag = true;
        });
      });
      if (!flag) el.parentNode.removeChild(el);
    }
  });
  app.directive("auth-all", {
    mounted(el, binding) {
      const stores = userInfo.useUserInfo();
      const flag = index.judgementSameArr(binding.value, stores.userInfos.authApiList);
      if (!flag) el.parentNode.removeChild(el);
    }
  });
}

exports.authDirective = authDirective;
