import '../stores/index.mjs';
import '../utils/index.mjs';
import { useUserInfo } from '../stores/userInfo.mjs';
import { judgementSameArr } from '../utils/array/index.mjs';

function authDirective(app) {
  app.directive("auth", {
    mounted(el, binding) {
      const stores = 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 = 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 = useUserInfo();
      const flag = judgementSameArr(binding.value, stores.userInfos.authApiList);
      if (!flag) el.parentNode.removeChild(el);
    }
  });
}

export { authDirective };
