"use strict";
const stores_dict = require("../stores/dict.js");
const utils_request = require("../utils/request.js");
const common_vendor = require("../common/vendor.js");
function useDict(...args) {
  const res = common_vendor.ref({});
  return (() => {
    args.forEach((dictType, index) => {
      res.value[dictType] = [];
      const dicts = stores_dict.useDictStore().getDict(dictType);
      if (dicts) {
        res.value[dictType] = dicts;
      } else {
        utils_request.request({
          url: "/sys/sys-dict/list2",
          data: {
            paterCode: dictType
          }
        }).then((resp) => {
          console.log("resp", resp);
          res.value[dictType] = resp.map((p) => ({
            label: p.msg,
            value: p.value,
            code: p.code,
            elTagType: p.cssClass,
            elTagClass: p.cssClass
          }));
          stores_dict.useDictStore().setDict(dictType, res.value[dictType]);
        });
      }
    });
    console.log("res.value", res.value);
    return common_vendor.toRefs(res.value);
  })();
}
function getDictByValue(dict, value) {
  let re = dict.find((e) => e.value == value);
  return re ? re : {};
}
function getDictByCode(dict, code) {
  let re = dict.find((e) => e.code == code);
  return re ? re : {};
}
exports.getDictByCode = getDictByCode;
exports.getDictByValue = getDictByValue;
exports.useDict = useDict;
