'use strict';

require('../stores/index.js');
var vueRouter = require('vue-router');
var userInfo = require('../stores/userInfo.js');

function getlimit(value) {
  const stores = userInfo.useUserInfo();
  const matched = stores.userInfos.limits.find((v) => v.permission === value);
  if (matched) return matched.limit;
  return null;
}
function getRules(field, msg) {
  var _a, _b, _c, _d;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  const ItemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.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) === field);
  let rels = [];
  if (ItemField) {
    if (ItemField.isRequired == 1)
      rels.push({ required: true, message: msg, trigger: "blur" });
    if (ItemField.isFromValid == 1)
      rels.push({ pattern: /^[1-9]\d*$/, message: msg, trigger: "blur" });
  }
  return rels;
}
function getFormItemProp(field) {
  var _a, _b, _c, _d;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  const ItemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.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) === field);
  if (ItemField) {
    return ItemField.isRequired == 1 || ItemField.isFromValid > 0 ? field : "";
  }
  return "";
}
function getFormItemLabel(field, defaultValue) {
  var _a, _b, _c, _d;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  const ItemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.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) === field);
  if (ItemField) {
    return ItemField.title && ItemField.title != "" ? ItemField.title : defaultValue;
  }
  return defaultValue;
}
function showTabelColumn(field) {
  var _a, _b, _c, _d;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  const ItemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.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) === field);
  if (ItemField) {
    if (ItemField.isTable == 1)
      return true;
    else if (ItemField.isTable == 0)
      return false;
  }
  return true;
}
function getSubFormFields(flag) {
  var _a, _b, _c;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  return ((_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.path)) == null ? void 0 : _a.formData) == null ? void 0 : _b.find((pack) => pack.flag === flag)) == null ? void 0 : _c.formData.filter((item) => (item == null ? void 0 : item.isAddUpdate) === 1).map((item) => ({ field: item.field, width: typeof item.width === "number" ? item.width : 0 }))) || [];
}
function getShowColumn(flag, field) {
  var _a, _b, _c, _d;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  const ItemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.path)) == null ? void 0 : _a.formData) == null ? void 0 : _b.find((pack) => pack.flag === flag)) == null ? void 0 : _c.formData) == null ? void 0 : _d.find((item) => (item == null ? void 0 : item.field) === field);
  if (ItemField) {
    if (ItemField.isAddUpdate == 1)
      return true;
    else if (ItemField.isAddUpdate == 0)
      return false;
  }
  return true;
}
function getShowColumnWidth(flag, field, defaultValue = "", isJson = false) {
  var _a, _b, _c, _d;
  const stores = userInfo.useUserInfo();
  const route = vueRouter.useRoute();
  const ItemField = (_d = (_c = (_b = (_a = (stores.userInfos.formDes || []).find((f) => f.path === route.path)) == null ? void 0 : _a.formData) == null ? void 0 : _b.find((pack) => pack.flag === flag)) == null ? void 0 : _c.formData) == null ? void 0 : _d.find((item) => (item == null ? void 0 : item.field) === field);
  let width = defaultValue;
  if (ItemField) {
    if (ItemField.width) {
      width = ItemField.width + ItemField.widthUnit;
    }
  }
  return isJson ? width != "" ? { width } : "" : width;
}

exports.getFormItemLabel = getFormItemLabel;
exports.getFormItemProp = getFormItemProp;
exports.getRules = getRules;
exports.getShowColumn = getShowColumn;
exports.getShowColumnWidth = getShowColumnWidth;
exports.getSubFormFields = getSubFormFields;
exports.getlimit = getlimit;
exports.showTabelColumn = showTabelColumn;
