"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../node_modules/element-plus/es/index.js");
;/* empty css                                                       */
;/* empty css                                                             */
;/* empty css                                                            */
;/* empty css                                                           */
;/* empty css                                                            */
const Vue = require("vue");
const index$2 = require("../../../node_modules/@element-plus/icons-vue/dist/index.js");
const index$4 = ;/* empty css                                    */
const common = require("../packages/utils/common.js");
const index = require("../../../node_modules/element-plus/es/components/input/index.js");
const index$1 = require("../../../node_modules/element-plus/es/components/button/index.js");
const index$3 = require("../../../node_modules/element-plus/es/components/dialog/index.js");
const _hoisted_1 = { class: "dialog-footer" };
const _sfc_main = {
  __name: "FormulaEditorInput",
  props: {
    modelValue: {
      type: String,
      default: ""
    },
    title: {
      type: String,
      default: "配置公式"
    },
    // 公式配置
    formulaConf: {
      type: Object,
      default: () => ({
        text: "",
        marks: []
      })
    },
    // 字段列表（可选，不传则从表单中获取）
    fieldList: {
      type: Array,
      default: null
    }
  },
  emits: ["update:modelValue", "update:formulaConf"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const modelValue = Vue.computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const dialogVisible = Vue.ref(false);
    const formulaEditor = Vue.ref(null);
    const internalFormulaConf = Vue.ref({
      text: "",
      marks: []
    });
    const internalFieldList = Vue.computed(() => {
      if (props.fieldList && props.fieldList.length > 0) {
        return filteredFields(props.fieldList);
      }
      const fields = common.getEditConfigDataFields() || [];
      const hiddenFields = common.getEditConfigData().hiddenFields || [];
      const filtered = filteredFields(
        fields.map((item) => ({
          id: item == null ? void 0 : item.id,
          label: item == null ? void 0 : item.label,
          fieldType: item == null ? void 0 : item.fieldType,
          fieldName: item == null ? void 0 : item.fieldName
        }))
      );
      return [
        ...filtered,
        ...hiddenFields.map((item) => ({
          id: item == null ? void 0 : item.id,
          label: item == null ? void 0 : item.label,
          fieldType: "hidden",
          fieldName: item == null ? void 0 : item.fieldName
        }))
      ];
    });
    function filteredFields(fields) {
      const includeArr = [
        "text",
        "textarea",
        "number",
        "date",
        "select",
        "multipleSelection",
        "radio",
        "checkbox"
      ];
      return fields.filter((item) => includeArr.includes(item.fieldType));
    }
    function openDialog() {
      var _a, _b;
      internalFormulaConf.value = {
        text: ((_a = props.formulaConf) == null ? void 0 : _a.text) || "",
        marks: ((_b = props.formulaConf) == null ? void 0 : _b.marks) || []
      };
      dialogVisible.value = true;
    }
    function onConfirm() {
      const formulaData = formulaEditor.value.getData();
      const displayData = formulaEditor.value.getDisplayData();
      modelValue.value = displayData;
      emit("update:formulaConf", {
        text: formulaData.text,
        marks: formulaData.marks
      });
      dialogVisible.value = false;
    }
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_el_input = index.ElInput;
      const _component_el_dialog = index$3.ElDialog;
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        Vue.createVNode(_component_el_input, {
          modelValue: Vue.unref(modelValue),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.isRef(modelValue) ? modelValue.value = $event : null),
          placeholder: "配置公式",
          readonly: ""
        }, {
          append: Vue.withCtx(() => [
            Vue.createVNode(_component_el_button, {
              icon: Vue.unref(index$2.Setting),
              onClick: openDialog
            }, null, 8, ["icon"])
          ]),
          _: 1
        }, 8, ["modelValue"]),
        Vue.createVNode(_component_el_dialog, {
          modelValue: Vue.unref(dialogVisible),
          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => Vue.isRef(dialogVisible) ? dialogVisible.value = $event : null),
          width: "800px",
          title: __props.title,
          draggable: "",
          overflow: "",
          "append-to-body": "",
          class: "fec-dev-designer-dialog"
        }, {
          footer: Vue.withCtx(() => [
            Vue.createElementVNode("div", _hoisted_1, [
              Vue.createVNode(_component_el_button, {
                onClick: _cache[1] || (_cache[1] = ($event) => dialogVisible.value = false),
                size: "default"
              }, {
                default: Vue.withCtx(() => _cache[3] || (_cache[3] = [
                  Vue.createTextVNode("取消")
                ])),
                _: 1
              }),
              Vue.createVNode(_component_el_button, {
                type: "primary",
                onClick: onConfirm,
                size: "default"
              }, {
                default: Vue.withCtx(() => _cache[4] || (_cache[4] = [
                  Vue.createTextVNode("确定")
                ])),
                _: 1
              })
            ])
          ]),
          default: Vue.withCtx(() => [
            Vue.createVNode(Vue.unref(index$4.default), {
              ref_key: "formulaEditor",
              ref: formulaEditor,
              formulaConf: Vue.unref(internalFormulaConf),
              fieldList: Vue.unref(internalFieldList)
            }, null, 8, ["formulaConf", "fieldList"])
          ]),
          _: 1
        }, 8, ["modelValue", "title"])
      ], 64);
    };
  }
};
exports.default = _sfc_main;
