import '../stores/index.mjs';
import { useRoute } from 'vue-router';
import { useUserInfo } from '../stores/userInfo.mjs';

function getlimit(value) {
  const stores = useUserInfo();
  const matched = stores.userInfos.limits.find((v) => v.permission === value);
  if (matched) return matched.limit;
  return null;
}
function getRules(field, msg) {
  const stores = useUserInfo();
  const route = useRoute();
  const item = stores.userInfos.formDes.find((item2) => item2.path === route.path);
  let rels = [];
  if (item && item.formDes.length > 0) {
    const xitem = item.formDes.find((v) => v.field === field);
    if (xitem) {
      if (xitem.isRequired == 1)
        rels.push({ required: true, message: msg, trigger: "blur" });
      if (xitem.isFromValid == 1)
        rels.push({ pattern: /^[1-9]\d*$/, message: msg, trigger: "blur" });
    }
  }
  return rels;
}
function getFormItemProp(field) {
  const stores = useUserInfo();
  const route = useRoute();
  const item = stores.userInfos.formDes.find((item2) => item2.path === route.path);
  if (item && item.formDes.length > 0) {
    const xitem = item.formDes.find((v) => v.field === field);
    if (xitem) return xitem.isRequired == 1 || xitem.isFromValid > 0 ? field : "";
  }
  return "";
}
function getFormItemLabel(field, defaultValue) {
  const stores = useUserInfo();
  const route = useRoute();
  const item = stores.userInfos.formDes.find((item2) => item2.path === route.path);
  if (item && item.formDes.length > 0) {
    const xitem = item.formDes.find((v) => v.field === field);
    if (xitem) return xitem.title && xitem.title != "" ? xitem.title : defaultValue;
  }
  return defaultValue;
}
function showTabelColumn(field) {
  const stores = useUserInfo();
  const route = useRoute();
  const item = stores.userInfos.formDes.find((item2) => item2.path === route.path);
  if (item && item.formDes.length > 0) {
    const xitem = item.formDes.find((v) => v.field === field);
    if (xitem) {
      if (xitem.isTable == 1)
        return true;
      else if (xitem.isTable == 0)
        return false;
    }
  }
  return true;
}

export { getFormItemLabel, getFormItemProp, getRules, getlimit, showTabelColumn };
