import "../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                       */
/* empty css                                                             */
/* empty css                                                            */
/* empty css                                                           */
/* empty css                                                            */
import { computed, ref, createElementBlock, openBlock, Fragment, createVNode, unref, isRef, withCtx, createElementVNode, createTextVNode } from "vue";
import { Setting as setting_default } from "../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import FormulaEditor from "../packages/formulaEditor/index.vue2.mjs";
import { getEditConfigDataFields, getEditConfigData } from "../packages/utils/common.mjs";
import { ElInput } from "../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElButton } from "../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElDialog } from "../../../node_modules/element-plus/es/components/dialog/index.mjs";
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 = computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const dialogVisible = ref(false);
    const formulaEditor = ref(null);
    const internalFormulaConf = ref({
      text: "",
      marks: []
    });
    const internalFieldList = computed(() => {
      if (props.fieldList && props.fieldList.length > 0) {
        return filteredFields(props.fieldList);
      }
      const fields = getEditConfigDataFields() || [];
      const hiddenFields = 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 = ElButton;
      const _component_el_input = ElInput;
      const _component_el_dialog = ElDialog;
      return openBlock(), createElementBlock(Fragment, null, [
        createVNode(_component_el_input, {
          modelValue: unref(modelValue),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(modelValue) ? modelValue.value = $event : null),
          placeholder: "配置公式",
          readonly: ""
        }, {
          append: withCtx(() => [
            createVNode(_component_el_button, {
              icon: unref(setting_default),
              onClick: openDialog
            }, null, 8, ["icon"])
          ]),
          _: 1
        }, 8, ["modelValue"]),
        createVNode(_component_el_dialog, {
          modelValue: unref(dialogVisible),
          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isRef(dialogVisible) ? dialogVisible.value = $event : null),
          width: "800px",
          title: __props.title,
          draggable: "",
          overflow: "",
          "append-to-body": "",
          class: "fec-dev-designer-dialog"
        }, {
          footer: withCtx(() => [
            createElementVNode("div", _hoisted_1, [
              createVNode(_component_el_button, {
                onClick: _cache[1] || (_cache[1] = ($event) => dialogVisible.value = false),
                size: "default"
              }, {
                default: withCtx(() => _cache[3] || (_cache[3] = [
                  createTextVNode("取消")
                ])),
                _: 1
              }),
              createVNode(_component_el_button, {
                type: "primary",
                onClick: onConfirm,
                size: "default"
              }, {
                default: withCtx(() => _cache[4] || (_cache[4] = [
                  createTextVNode("确定")
                ])),
                _: 1
              })
            ])
          ]),
          default: withCtx(() => [
            createVNode(unref(FormulaEditor), {
              ref_key: "formulaEditor",
              ref: formulaEditor,
              formulaConf: unref(internalFormulaConf),
              fieldList: unref(internalFieldList)
            }, null, 8, ["formulaConf", "fieldList"])
          ]),
          _: 1
        }, 8, ["modelValue", "title"])
      ], 64);
    };
  }
};
export {
  _sfc_main as default
};
