'use strict';

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

function authDirective(app) {
  app.directive("auth", {
    mounted(el, binding) {
      const stores = userInfo.useUserInfo();
      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 = arrayOperation.judgementSameArr(binding.value, stores.userInfos.authApiList);
      if (!flag) el.parentNode.removeChild(el);
    }
  });
  app.directive("hdtable", {
    mounted(el, binding) {
      var _a, _b, _c, _d;
      const stores = userInfo.useUserInfo();
      const config = typeof binding.value === "string" ? { path: binding.value, field: "" } : binding.value;
      const itemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === config.path)) == null ? void 0 : _a.formData) == null ? void 0 : _b.find((pack) => pack.flag === "main")) == null ? void 0 : _c.formData) == null ? void 0 : _d.find((item) => (item == null ? void 0 : item.field) === config.field);
      if (itemField && itemField.isTable == 0) el.parentNode.removeChild(el);
    }
  });
  app.directive("hpquery", {
    mounted(el, binding) {
      var _a, _b, _c, _d;
      const stores = userInfo.useUserInfo();
      const config = typeof binding.value === "string" ? { path: binding.value, field: "" } : binding.value;
      const itemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === config.path)) == null ? void 0 : _a.formData) == null ? void 0 : _b.find((pack) => pack.flag === "main")) == null ? void 0 : _c.formData) == null ? void 0 : _d.find((item) => (item == null ? void 0 : item.field) === config.field);
      if (itemField && itemField.isQuery == 0) el.parentNode.removeChild(el);
    }
  });
  app.directive("hpaddupdate", {
    mounted(el, binding) {
      var _a, _b, _c, _d;
      const stores = userInfo.useUserInfo();
      const config = typeof binding.value === "string" ? { path: binding.value, field: "", flag: "main" } : binding.value;
      const itemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === config.path)) == null ? void 0 : _a.formData) == null ? void 0 : _b.find((pack) => pack.flag === (config.flag || "main"))) == null ? void 0 : _c.formData) == null ? void 0 : _d.find((item) => (item == null ? void 0 : item.field) === config.field);
      if (itemField && itemField.isAddUpdate == 0) el.parentNode.removeChild(el);
    }
  });
}

exports.authDirective = authDirective;
