"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const common = require("../packages/utils/common.js");
;/* empty css                          */
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
const _hoisted_1 = { class: "filter-config-display" };
const _sfc_main = {
  __name: "FilterConfigDisplay",
  props: {
    config: {
      type: Object,
      default: () => ({})
    }
  },
  setup(__props) {
    const operatorMap = {
      eq: "等于",
      ne: "不等于",
      gt: "大于",
      gte: "大于等于",
      lt: "小于",
      lte: "小于等于",
      contains: "包含",
      not_contains: "不包含",
      starts_with: "开头是",
      ends_with: "结尾是",
      is_null: "为空",
      is_not_null: "不为空",
      in: "在...中",
      not_in: "不在...中",
      range: "在范围内",
      in_any: "等于任意一个",
      ni_any: "不等于任意一个"
    };
    const formatFilterConfigStyled = (config, isRoot = true) => {
      var _a, _b, _c, _d;
      if (!config || !((_a = config.conditions) == null ? void 0 : _a.length) && !((_b = config.groups) == null ? void 0 : _b.length)) {
        return Vue.h("span", { class: "no-condition" }, "");
      }
      const parts = [];
      let firstCondition = true;
      if (isRoot) {
        parts.push(Vue.h("span", { class: "condition-keyword" }, "当"));
      }
      if ((_c = config.conditions) == null ? void 0 : _c.length) {
        config.conditions.forEach((condition) => {
          if (!firstCondition) {
            const connector = config.operator == "or" ? "或" : "且";
            parts.push(Vue.h("span", { class: "condition-connector-tag" }, connector));
          }
          parts.push(...formatConditionStyled(condition));
          firstCondition = false;
        });
      }
      if ((_d = config.groups) == null ? void 0 : _d.length) {
        config.groups.forEach((group) => {
          if (!firstCondition) {
            const connector = config.operator == "or" ? "或" : "且";
            parts.push(Vue.h("span", { class: "condition-connector-tag" }, connector));
          }
          parts.push(
            Vue.h("span", { class: "group-bracket" }, "("),
            formatFilterConfigStyled(group, false),
            Vue.h("span", { class: "group-bracket" }, ")")
          );
          firstCondition = false;
        });
      }
      return Vue.h("span", { class: "condition-wrapper" }, parts);
    };
    const formatConditionStyled = (condition) => {
      const parts = [];
      const fieldName = getFieldLabel(condition.field);
      parts.push(Vue.h("span", { class: "field-value" }, `「${fieldName}」`));
      const operator = operatorMap[condition.operator] || condition.operator;
      parts.push(Vue.h("span", { class: "operator-text" }, operator));
      let value = "";
      if (condition.operator == "is_null" || condition.operator == "is_not_null") {
        value = "";
      } else if (condition.isField) {
        if (Array.isArray(condition.value)) {
          const fieldNames = condition.value.map(
            (item) => `${getFieldLabel(item)}`
          );
          value = fieldNames.join(", ");
        } else {
          value = `${getFieldLabel(condition.value)}`;
        }
      } else {
        value = formatValue(condition.showText, condition.operator);
      }
      if (value || value == 0) {
        parts.push(Vue.h("span", { class: "field-value" }, value));
      }
      return parts;
    };
    const fieldsData = Vue.computed(() => {
      return common.getEditConfigDataFields();
    });
    const hiddenFieldsData = Vue.computed(() => {
      const editConfigData = common.getEditConfigData();
      return (editConfigData == null ? void 0 : editConfigData.hiddenFields) || [];
    });
    function getFieldLabel(fieldId) {
      if (fieldId && typeof fieldId == "object" && !Array.isArray(fieldId)) {
        return fieldId.label || fieldId.value;
      }
      let field = fieldsData.value.find((f) => f.id == fieldId);
      if (field) {
        return field.label;
      }
      field = hiddenFieldsData.value.find((f) => f.id == fieldId);
      if (field) {
        return field.label;
      }
      return fieldId;
    }
    const formatValue = (value, operator) => {
      if (value == null || value == void 0) {
        return "";
      }
      if (operator == "range" && Array.isArray(value) && value.length == 2) {
        return `${value[0]} ~ ${value[1]}`;
      }
      if ((operator == "in_any" || operator == "ni_any") && Array.isArray(value)) {
        return value.join(", ");
      }
      if (Array.isArray(value)) {
        return value.join(", ");
      }
      if (typeof value == "string" && value.length > 20) {
        return value.substring(0, 20) + "...";
      }
      return String(value);
    };
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        (Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(formatFilterConfigStyled(__props.config))))
      ]);
    };
  }
};
const FilterConfigDisplay = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-f50128c9"]]);
exports.default = FilterConfigDisplay;
