"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                                                         */
;/* empty css                                                            */
;/* empty css                                                                  */
;/* empty css                                                            */
const Vue = require("vue");
const index$3 = require("../../../node_modules/@element-plus/icons-vue/dist/index.js");
const vueDraggablePlus = require("../../../node_modules/vue-draggable-plus/dist/vue-draggable-plus.js");
const DataSourceSelect = require("./DataSourceSelect.vue.js");
const FieldMapping = require("./FieldMapping.vue2.js");
const common = require("../packages/utils/common.js");
;/* empty css                   */
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../node_modules/element-plus/es/components/form/index.js");
const index$1 = require("../../../node_modules/element-plus/es/components/select/index.js");
const index$2 = require("../../../node_modules/element-plus/es/components/icon/index.js");
const index$4 = require("../../../node_modules/element-plus/es/components/input/index.js");
const _hoisted_1 = { class: "custom-options" };
const _hoisted_2 = { class: "option-header" };
const _hoisted_3 = { class: "drag-handle" };
const _hoisted_4 = ["onClick"];
const _hoisted_5 = { class: "data-source-fields" };
const _hoisted_6 = { class: "field-item" };
const _hoisted_7 = { class: "field-item" };
const _hoisted_8 = {
  class: "field-item",
  style: { "flex-direction": "column", "align-items": "start" }
};
const _sfc_main = {
  __name: "OptionConfig",
  props: {
    modelValue: {
      type: Object,
      default: () => ({
        optionSource: "dictionary",
        options: [
          {
            id: 1769067474103,
            label: "选项1",
            value: "1"
          },
          {
            id: 1769067474572,
            label: "选项2",
            value: "2"
          },
          {
            id: 1769067475160,
            label: "选项3",
            value: "3"
          }
        ],
        dataSourceValue: "",
        displayField: "",
        valueField: "",
        dictionaryValue: "",
        fieldMapping: []
      })
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    var _a, _b, _c, _d, _e, _f, _g;
    const props = __props;
    const emit = __emit;
    Vue.computed(() => {
      const displayFields = common.getEditConfigDataFields() || [];
      const editConfigData = common.getEditConfigData();
      const hiddenList = (editConfigData == null ? void 0 : editConfigData.hiddenFields) || [];
      return [...displayFields, ...hiddenList];
    });
    const optionSource = Vue.ref(((_a = props.modelValue) == null ? void 0 : _a.optionSource) || "custom");
    const options = Vue.ref(((_b = props.modelValue) == null ? void 0 : _b.options) || []);
    const dataSourceValue = Vue.ref(((_c = props.modelValue) == null ? void 0 : _c.dataSourceValue) || "");
    const displayField = Vue.ref(((_d = props.modelValue) == null ? void 0 : _d.displayField) || "");
    const valueField = Vue.ref(((_e = props.modelValue) == null ? void 0 : _e.valueField) || "");
    const dictionaryValue = Vue.ref(((_f = props.modelValue) == null ? void 0 : _f.dictionaryValue) || "");
    const fieldMapping = Vue.ref(((_g = props.modelValue) == null ? void 0 : _g.fieldMapping) || []);
    const isUpdatingFromProps = Vue.ref(false);
    Vue.watch(
      () => props.modelValue,
      (newVal) => {
        if (newVal && !isUpdatingFromProps.value) {
          optionSource.value = newVal.optionSource || "custom";
          options.value = newVal.options || [];
          dataSourceValue.value = newVal.dataSourceValue || "";
          displayField.value = newVal.displayField || "";
          valueField.value = newVal.valueField || "";
          dictionaryValue.value = newVal.dictionaryValue || "";
          fieldMapping.value = newVal.fieldMapping || [];
        }
      },
      { deep: true }
    );
    const updateParent = () => {
      isUpdatingFromProps.value = true;
      const data = {
        optionSource: optionSource.value,
        options: options.value,
        dataSourceValue: dataSourceValue.value,
        displayField: displayField.value,
        valueField: valueField.value,
        dictionaryValue: dictionaryValue.value,
        fieldMapping: fieldMapping.value
      };
      emit("update:modelValue", data);
      Vue.nextTick(() => {
        isUpdatingFromProps.value = false;
      });
    };
    Vue.watch(
      [
        optionSource,
        options,
        dataSourceValue,
        displayField,
        valueField,
        dictionaryValue,
        fieldMapping
      ],
      updateParent,
      { deep: true, immediate: true }
    );
    function handleAddOption() {
      options.value.push({
        id: Date.now(),
        label: "",
        value: ""
      });
    }
    function handleDeleteOption(index2) {
      options.value.splice(index2, 1);
    }
    return (_ctx, _cache) => {
      const _component_el_option = index$1.ElOption;
      const _component_el_select = index$1.ElSelect;
      const _component_el_form_item = index.ElFormItem;
      const _component_el_icon = index$2.ElIcon;
      const _component_el_input = index$4.ElInput;
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        Vue.createVNode(_component_el_form_item, {
          label: "选项来源",
          style: { "margin-bottom": "12px" }
        }, {
          default: Vue.withCtx(() => [
            Vue.createVNode(_component_el_select, {
              modelValue: Vue.unref(optionSource),
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.isRef(optionSource) ? optionSource.value = $event : null),
              placeholder: "请选择",
              teleported: false
            }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_option, {
                  label: "自定义",
                  value: "custom"
                }),
                Vue.createVNode(_component_el_option, {
                  label: "数据源",
                  value: "dataSource"
                }),
                Vue.createVNode(_component_el_option, {
                  label: "字典项",
                  value: "dictionary"
                })
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          _: 1
        }),
        Vue.unref(optionSource) === "custom" ? (Vue.openBlock(), Vue.createBlock(_component_el_form_item, { key: 0 }, {
          default: Vue.withCtx(() => [
            Vue.createElementVNode("div", _hoisted_1, [
              Vue.createElementVNode("div", _hoisted_2, [
                _cache[7] || (_cache[7] = Vue.createElementVNode("span", null, null, -1)),
                _cache[8] || (_cache[8] = Vue.createElementVNode("span", { class: "header-label" }, "显示值", -1)),
                _cache[9] || (_cache[9] = Vue.createElementVNode("span", { class: "header-label" }, "真实值", -1)),
                Vue.createElementVNode("div", {
                  class: "icon-btn add-btn",
                  onClick: handleAddOption
                }, [
                  Vue.createVNode(_component_el_icon, null, {
                    default: Vue.withCtx(() => [
                      Vue.createVNode(Vue.unref(index$3.Plus))
                    ]),
                    _: 1
                  })
                ])
              ]),
              Vue.createVNode(Vue.unref(vueDraggablePlus.VueDraggable), {
                modelValue: Vue.unref(options),
                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => Vue.isRef(options) ? options.value = $event : null),
                animation: 150,
                handle: ".drag-handle"
              }, {
                default: Vue.withCtx(() => [
                  (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(options), (option, index2) => {
                    return Vue.openBlock(), Vue.createElementBlock("div", {
                      key: option.id,
                      class: "option-item"
                    }, [
                      Vue.createElementVNode("div", _hoisted_3, [
                        Vue.createVNode(_component_el_icon, null, {
                          default: Vue.withCtx(() => [
                            Vue.createVNode(Vue.unref(index$3.Rank))
                          ]),
                          _: 1
                        })
                      ]),
                      Vue.createVNode(_component_el_input, {
                        modelValue: option.label,
                        "onUpdate:modelValue": ($event) => option.label = $event,
                        placeholder: "显示值"
                      }, null, 8, ["modelValue", "onUpdate:modelValue"]),
                      Vue.createVNode(_component_el_input, {
                        modelValue: option.value,
                        "onUpdate:modelValue": ($event) => option.value = $event,
                        placeholder: "真实值"
                      }, null, 8, ["modelValue", "onUpdate:modelValue"]),
                      Vue.createElementVNode("div", {
                        class: "icon-btn delete-btn",
                        onClick: ($event) => handleDeleteOption(index2)
                      }, [
                        Vue.createVNode(_component_el_icon, null, {
                          default: Vue.withCtx(() => [
                            Vue.createVNode(Vue.unref(index$3.Minus))
                          ]),
                          _: 1
                        })
                      ], 8, _hoisted_4)
                    ]);
                  }), 128))
                ]),
                _: 1
              }, 8, ["modelValue"])
            ])
          ]),
          _: 1
        })) : Vue.unref(optionSource) === "dataSource" ? (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 1 }, [
          Vue.createVNode(_component_el_form_item, null, {
            default: Vue.withCtx(() => [
              Vue.createVNode(DataSourceSelect.default, {
                modelValue: Vue.unref(dataSourceValue),
                "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => Vue.isRef(dataSourceValue) ? dataSourceValue.value = $event : null)
              }, null, 8, ["modelValue"])
            ]),
            _: 1
          }),
          Vue.createElementVNode("div", _hoisted_5, [
            Vue.createElementVNode("div", _hoisted_6, [
              _cache[10] || (_cache[10] = Vue.createElementVNode("span", { class: "field-label" }, "显示字段", -1)),
              Vue.createVNode(_component_el_input, {
                modelValue: Vue.unref(displayField),
                "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => Vue.isRef(displayField) ? displayField.value = $event : null),
                placeholder: "如：optName"
              }, null, 8, ["modelValue"])
            ]),
            Vue.createElementVNode("div", _hoisted_7, [
              _cache[11] || (_cache[11] = Vue.createElementVNode("span", { class: "field-label" }, "值字段", -1)),
              Vue.createVNode(_component_el_input, {
                modelValue: Vue.unref(valueField),
                "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => Vue.isRef(valueField) ? valueField.value = $event : null),
                placeholder: "如：optCode"
              }, null, 8, ["modelValue"])
            ]),
            Vue.createElementVNode("div", _hoisted_8, [
              _cache[12] || (_cache[12] = Vue.createElementVNode("span", {
                class: "field-label",
                style: { "width": "auto" }
              }, "选中数据映射表单字段", -1)),
              Vue.createVNode(FieldMapping.default, {
                modelValue: Vue.unref(fieldMapping),
                "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => Vue.isRef(fieldMapping) ? fieldMapping.value = $event : null)
              }, null, 8, ["modelValue"])
            ])
          ])
        ], 64)) : Vue.unref(optionSource) === "dictionary" ? (Vue.openBlock(), Vue.createBlock(_component_el_form_item, { key: 2 }, {
          default: Vue.withCtx(() => [
            Vue.createVNode(_component_el_input, {
              modelValue: Vue.unref(dictionaryValue),
              "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => Vue.isRef(dictionaryValue) ? dictionaryValue.value = $event : null),
              placeholder: "keyName"
            }, null, 8, ["modelValue"])
          ]),
          _: 1
        })) : Vue.createCommentVNode("", true)
      ], 64);
    };
  }
};
const OptionConfig = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-fe7440f2"]]);
exports.default = OptionConfig;
