"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                                                                          */
;/* empty css                                                                           */
const Vue = require("vue");
const common = require("../../../utils/common.js");
const FieldSetMapping = require("../../../../components/FieldSetMapping.vue2.js");
const OnlyFLowConfigButton = ;/* empty css                                                */
const FormulaEditorInput = require("../../../../components/FormulaEditorInput.vue.js");
const index$3 = require("../../../../api/index.js");
const DialogSelect = require("../../../../components/DialogSelect.vue.js");
const index = require("../../../../../../node_modules/element-plus/es/components/form/index.js");
const index$1 = require("../../../../../../node_modules/element-plus/es/components/radio/index.js");
const index$2 = require("../../../../../../node_modules/element-plus/es/components/input/index.js");
const _sfc_main = {
  __name: "Dialog",
  props: {
    formData: Object
  },
  setup(__props) {
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    const currDialog = Vue.ref({});
    const globalDialogs = Vue.ref([]);
    const loading = Vue.ref(false);
    const tableOptions = Vue.ref(null);
    const loadGlobalDialogs = async () => {
      loading.value = true;
      try {
        const response = await index$3.default.getAllTemplateDialog(ctx.$http);
        globalDialogs.value = [];
        for (let dialog of response) {
          globalDialogs.value.push({
            id: dialog.id,
            name: dialog.name,
            ...JSON.parse(dialog.config)
          });
        }
      } catch (error) {
        console.error("🚀 ~ 获取全局弹层数据失败:", error);
        globalDialogs.value = [];
      } finally {
        loading.value = false;
      }
    };
    Vue.watch(
      () => props.formData.dialogSource,
      async (newSource, oldSource) => {
        if (newSource === "global" && oldSource !== "global") {
          await loadGlobalDialogs();
        }
      },
      { immediate: true }
    );
    function handleDialogSourceChange() {
      props.formData.dialogId = null;
      currDialog.value = {};
      tableOptions.value = null;
    }
    const handleDialogChange = async (dialogId) => {
      if (!dialogId) {
        currDialog.value = {};
        tableOptions.value = null;
        return;
      }
      const selectedDialog = dialogOptions.value.find(
        (dialog) => dialog.id === dialogId
      );
      if (selectedDialog) {
        currDialog.value = { ...selectedDialog };
        if (currDialog.value.contentSource === "table" && currDialog.value.tableContent === "select") {
          const tableId = currDialog.value.subTableId;
          if (tableId) {
            try {
              const response = await index$3.default.getById(ctx.$http, tableId, false);
              tableOptions.value = JSON.parse(response.context);
              console.log("🚀 ~ 需要获取表格配置，表格ID:", tableId);
            } catch (error) {
              console.error("🚀 ~ 获取表格配置失败:", error);
            }
          }
        } else if (currDialog.value.contentSource === "form") {
          props.formData.subFormMode = currDialog.value.subFormMode;
        } else {
          tableOptions.value = null;
        }
      }
    };
    const dialogOptions = Vue.computed(() => {
      if (props.formData.dialogSource === "global") {
        return globalDialogs.value;
      } else {
        return common.getEditConfigData().dialogs || [];
      }
    });
    const tableFields = Vue.computed(() => {
      var _a, _b, _c, _d, _e, _f;
      if (((_a = currDialog.value) == null ? void 0 : _a.tableContent) === "custom") {
        return ((_c = (_b = currDialog.value) == null ? void 0 : _b.customTableConfig) == null ? void 0 : _c.fieldsData) || [];
      } else if (((_d = currDialog.value) == null ? void 0 : _d.tableContent) === "select") {
        return [
          ...((_e = tableOptions.value) == null ? void 0 : _e.fieldsData) || [],
          ...((_f = tableOptions.value) == null ? void 0 : _f.hiddenFields) || []
        ];
      }
      return [];
    });
    function handleOnlyFlowConfirm(data) {
      props.formData.callbackEventConfig = data;
    }
    return (_ctx, _cache) => {
      const _component_el_radio_button = index$1.ElRadioButton;
      const _component_el_radio_group = index$1.ElRadioGroup;
      const _component_el_form_item = index.ElFormItem;
      const _component_el_input = index$2.ElInput;
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        Vue.createVNode(_component_el_form_item, { label: "弹层来源" }, {
          default: Vue.withCtx(() => [
            Vue.createVNode(_component_el_radio_group, {
              modelValue: __props.formData.dialogSource,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => __props.formData.dialogSource = $event),
              onChange: handleDialogSourceChange
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_radio_button, { value: "global" }, {
                  default: Vue.withCtx(() => _cache[8] || (_cache[8] = [
                    Vue.createTextVNode("全局")
                  ])),
                  _: 1
                }),
                Vue.createVNode(_component_el_radio_button, { value: "custom" }, {
                  default: Vue.withCtx(() => _cache[9] || (_cache[9] = [
                    Vue.createTextVNode("自定义")
                  ])),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          _: 1
        }),
        Vue.createVNode(_component_el_form_item, { label: "选择弹层" }, {
          default: Vue.withCtx(() => [
            Vue.createVNode(DialogSelect.default, {
              modelValue: __props.formData.dialogId,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => __props.formData.dialogId = $event),
              size: "small",
              loading: loading.value,
              onChange: handleDialogChange,
              dialogOptions: dialogOptions.value,
              isGlobal: __props.formData.dialogSource == "global"
            }, null, 8, ["modelValue", "loading", "dialogOptions", "isGlobal"])
          ]),
          _: 1
        }),
        __props.formData.dialogSource == "global" && __props.formData.dialogId && currDialog.value.contentSource == "table" ? (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 0 }, [
          Vue.createVNode(_component_el_form_item, { label: "选择模式" }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(_component_el_radio_group, {
                modelValue: __props.formData.selectionMode,
                "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => __props.formData.selectionMode = $event)
              }, {
                default: Vue.withCtx(() => [
                  Vue.createVNode(_component_el_radio_button, { value: "none" }, {
                    default: Vue.withCtx(() => _cache[10] || (_cache[10] = [
                      Vue.createTextVNode("无")
                    ])),
                    _: 1
                  }),
                  Vue.createVNode(_component_el_radio_button, { value: "single" }, {
                    default: Vue.withCtx(() => _cache[11] || (_cache[11] = [
                      Vue.createTextVNode("单选")
                    ])),
                    _: 1
                  }),
                  Vue.createVNode(_component_el_radio_button, { value: "multiple" }, {
                    default: Vue.withCtx(() => _cache[12] || (_cache[12] = [
                      Vue.createTextVNode("多选")
                    ])),
                    _: 1
                  })
                ]),
                _: 1
              }, 8, ["modelValue"])
            ]),
            _: 1
          }),
          __props.formData.selectionMode != "none" ? (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 0 }, [
            Vue.createVNode(_component_el_form_item, { label: "选取后反显字段" }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_input, {
                  modelValue: __props.formData.displayFieldName,
                  "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => __props.formData.displayFieldName = $event)
                }, null, 8, ["modelValue"])
              ]),
              _: 1
            }),
            Vue.createVNode(_component_el_form_item, { label: "选取后反显格式" }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(Vue.unref(FormulaEditorInput.default), {
                  title: "反显格式配置",
                  formulaConf: __props.formData.displayFormat,
                  "onUpdate:formulaConf": _cache[4] || (_cache[4] = ($event) => __props.formData.displayFormat = $event),
                  modelValue: __props.formData.displayFormatText,
                  "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => __props.formData.displayFormatText = $event),
                  fieldList: tableFields.value
                }, null, 8, ["formulaConf", "modelValue", "fieldList"])
              ]),
              _: 1
            }),
            Vue.createVNode(_component_el_form_item, { label: "选取后表单赋值" }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(FieldSetMapping.default, {
                  modelValue: __props.formData.fieldMapping,
                  "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => __props.formData.fieldMapping = $event),
                  fieldLabel: "赋值表单字段",
                  valueLabel: "列表字段",
                  valueOptions: tableFields.value,
                  valueSelectMode: ""
                }, null, 8, ["modelValue", "valueOptions"])
              ]),
              _: 1
            })
          ], 64)) : Vue.createCommentVNode("", true),
          __props.formData.selectionMode != "none" ? (Vue.openBlock(), Vue.createBlock(_component_el_form_item, {
            key: 1,
            label: "回调事件配置"
          }, {
            default: Vue.withCtx(() => [
              Vue.createVNode(OnlyFLowConfigButton.default, {
                config: __props.formData.callbackEventConfig,
                onConfirm: handleOnlyFlowConfirm
              }, null, 8, ["config"])
            ]),
            _: 1
          })) : Vue.createCommentVNode("", true)
        ], 64)) : currDialog.value.contentSource == "form" ? (Vue.openBlock(), Vue.createBlock(_component_el_form_item, {
          key: 1,
          label: "表单模式"
        }, {
          default: Vue.withCtx(() => [
            Vue.createVNode(_component_el_radio_group, {
              modelValue: __props.formData.subFormMode,
              "onUpdate:modelValue": _cache[7] || (_cache[7] = ($event) => __props.formData.subFormMode = $event)
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_radio_button, { value: "edit" }, {
                  default: Vue.withCtx(() => _cache[13] || (_cache[13] = [
                    Vue.createTextVNode("编辑")
                  ])),
                  _: 1
                }),
                Vue.createVNode(_component_el_radio_button, { value: "query" }, {
                  default: Vue.withCtx(() => _cache[14] || (_cache[14] = [
                    Vue.createTextVNode("查看")
                  ])),
                  _: 1
                })
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          _: 1
        })) : Vue.createCommentVNode("", true)
      ], 64);
    };
  }
};
exports.default = _sfc_main;
