"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                                                            */
;/* empty css                                                                  */
;/* empty css                                                              */
require("../../../node_modules/element-plus/theme-chalk/el-dropdown-menu.css.js");
require("../../../node_modules/element-plus/theme-chalk/el-dropdown-item.css.js");
;/* empty css                                                              */
const Vue = require("vue");
const index$2 = require("../../../node_modules/@element-plus/icons-vue/dist/index.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/dropdown/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/scrollbar/index.js");
const index$4 = require("../../../node_modules/element-plus/es/components/checkbox/index.js");
const index$5 = require("../../../node_modules/element-plus/es/components/select/index.js");
const index$6 = require("../../../node_modules/element-plus/es/components/input/index.js");
const _hoisted_1 = { class: "dropdown-header" };
const _hoisted_2 = { class: "dropdown-content" };
const _hoisted_3 = {
  key: 1,
  class: "mapping-table"
};
const _hoisted_4 = { class: "mapping-header" };
const _hoisted_5 = { class: "mapping-cell value-header" };
const _hoisted_6 = { class: "mapping-cell field-header" };
const _hoisted_7 = { class: "mapping-body" };
const _hoisted_8 = { class: "mapping-cell value-cell" };
const _hoisted_9 = { class: "mapping-cell field-cell" };
const _hoisted_10 = { class: "mapping-cell action-cell" };
const _hoisted_11 = { class: "mapping-footer" };
const _hoisted_12 = { class: "dropdown-header" };
const _hoisted_13 = { class: "dropdown-content" };
const _sfc_main = {
  __name: "FieldSetMapping",
  props: {
    modelValue: {
      type: Array,
      default: () => []
    },
    // 表单字段的描述文本
    fieldLabel: {
      type: String,
      default: "表单字段"
    },
    // 映射字段的描述文本
    valueLabel: {
      type: String,
      default: "映射字段"
    },
    // 映射字段支持的选择项列表
    valueOptions: {
      type: Array,
      default: () => []
    },
    // 映射字段是否为选择模式（true: 下拉选择，false: 手动输入）
    valueSelectMode: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: ""
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const mappings = Vue.computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const emit = __emit;
    const selectedFields = Vue.ref([]);
    const formFields = Vue.computed(() => {
      const fields = common.getEditConfigDataFields() || [];
      return fields.map((item) => ({
        id: item == null ? void 0 : item.id,
        fieldId: item == null ? void 0 : item.id,
        label: item == null ? void 0 : item.label,
        fieldName: item == null ? void 0 : item.fieldName
      }));
    });
    const hiddenFields = Vue.computed(() => {
      const editConfigData = common.getEditConfigData();
      const fields = (editConfigData == null ? void 0 : editConfigData.hiddenFields) || [];
      return fields.map((item) => ({
        id: item == null ? void 0 : item.id,
        fieldId: item == null ? void 0 : item.id,
        label: item == null ? void 0 : item.label,
        fieldName: item == null ? void 0 : item.fieldName
      }));
    });
    function handleDropdownVisible(visible) {
      if (visible) {
        selectedFields.value = [];
      }
    }
    const dropdownRef = Vue.ref();
    function confirmAddMappings() {
      var _a;
      if (selectedFields.value.length === 0) {
        return;
      }
      const allFields = [...formFields.value, ...hiddenFields.value];
      selectedFields.value.forEach((selectedFieldName) => {
        const newMapping = {
          id: Date.now() + Math.random(),
          field: "",
          // 默认值为空
          value: selectedFieldName
          // 自动赋值为勾选的字段
        };
        const matchedField = allFields.find(
          (field) => field.fieldName === selectedFieldName
        );
        if (matchedField) {
          newMapping.field = matchedField.fieldId;
        }
        mappings.value.push(newMapping);
      });
      selectedFields.value = [];
      (_a = dropdownRef.value) == null ? void 0 : _a.handleClose();
    }
    function removeMapping(index2) {
      mappings.value.splice(index2, 1);
    }
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_el_checkbox = index$4.ElCheckbox;
      const _component_el_dropdown_item = index.ElDropdownItem;
      const _component_el_scrollbar = index$3.ElScrollbar;
      const _component_el_dropdown_menu = index.ElDropdownMenu;
      const _component_el_dropdown = index.ElDropdown;
      const _component_el_option = index$5.ElOption;
      const _component_el_select = index$5.ElSelect;
      const _component_el_input = index$6.ElInput;
      const _component_el_option_group = index$5.ElOptionGroup;
      return Vue.openBlock(), Vue.createElementBlock("div", {
        class: Vue.normalizeClass(["field-mapping-container", __props.size])
      }, [
        Vue.unref(mappings).length === 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_dropdown, {
          key: 0,
          "max-height": 500,
          trigger: "click",
          placement: "bottom",
          "hide-on-click": false,
          onVisibleChange: handleDropdownVisible,
          ref_key: "dropdownRef",
          ref: dropdownRef
        }, {
          dropdown: Vue.withCtx(() => [
            Vue.createVNode(_component_el_dropdown_menu, { class: "field-mapping-dropdown" }, {
              default: Vue.withCtx(() => [
                Vue.createElementVNode("div", _hoisted_1, [
                  _cache[4] || (_cache[4] = Vue.createElementVNode("span", { class: "header-title" }, "选择字段", -1)),
                  Vue.createVNode(_component_el_button, {
                    type: "primary",
                    size: "small",
                    onClick: confirmAddMappings
                  }, {
                    default: Vue.withCtx(() => _cache[3] || (_cache[3] = [
                      Vue.createTextVNode("确定")
                    ])),
                    _: 1
                  })
                ]),
                Vue.createElementVNode("div", _hoisted_2, [
                  Vue.createVNode(_component_el_scrollbar, { "max-height": 300 }, {
                    default: Vue.withCtx(() => [
                      (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(__props.valueOptions, (option) => {
                        return Vue.openBlock(), Vue.createBlock(_component_el_dropdown_item, {
                          key: option.fieldName
                        }, {
                          default: Vue.withCtx(() => [
                            Vue.createVNode(_component_el_checkbox, {
                              modelValue: Vue.unref(selectedFields),
                              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => Vue.isRef(selectedFields) ? selectedFields.value = $event : null),
                              value: option.fieldName,
                              label: option.label
                            }, null, 8, ["modelValue", "value", "label"])
                          ]),
                          _: 2
                        }, 1024);
                      }), 128)),
                      __props.valueOptions.length === 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_dropdown_item, {
                        key: 0,
                        disabled: ""
                      }, {
                        default: Vue.withCtx(() => _cache[5] || (_cache[5] = [
                          Vue.createElementVNode("span", { class: "empty-text" }, "暂无可用字段", -1)
                        ])),
                        _: 1
                      })) : Vue.createCommentVNode("", true)
                    ]),
                    _: 1
                  })
                ])
              ]),
              _: 1
            })
          ]),
          default: Vue.withCtx(() => [
            Vue.createVNode(_component_el_button, {
              type: "primary",
              size: "small",
              icon: Vue.unref(index$2.Plus),
              link: ""
            }, {
              default: Vue.withCtx(() => _cache[2] || (_cache[2] = [
                Vue.createTextVNode(" 新增字段映射 ")
              ])),
              _: 1
            }, 8, ["icon"])
          ]),
          _: 1
        }, 512)) : (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_3, [
          Vue.createElementVNode("div", _hoisted_4, [
            Vue.createElementVNode("div", _hoisted_5, Vue.toDisplayString(__props.valueLabel), 1),
            Vue.createElementVNode("div", _hoisted_6, Vue.toDisplayString(__props.fieldLabel), 1),
            _cache[6] || (_cache[6] = Vue.createElementVNode("div", {
              class: "mapping-cell action-header",
              style: { "width": "50px" }
            }, null, -1))
          ]),
          Vue.createElementVNode("div", _hoisted_7, [
            (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(mappings), (item, index2) => {
              return Vue.openBlock(), Vue.createElementBlock("div", {
                key: item.id,
                class: "mapping-row"
              }, [
                Vue.createElementVNode("div", _hoisted_8, [
                  __props.valueSelectMode ? (Vue.openBlock(), Vue.createBlock(_component_el_select, {
                    key: 0,
                    modelValue: item.value,
                    "onUpdate:modelValue": ($event) => item.value = $event,
                    placeholder: `选择${__props.valueLabel}`,
                    size: "small",
                    style: { "width": "100%" },
                    filterable: ""
                  }, {
                    default: Vue.withCtx(() => [
                      (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(__props.valueOptions, (option) => {
                        return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                          key: option.fieldName,
                          label: option.label,
                          value: option.fieldName
                        }, null, 8, ["label", "value"]);
                      }), 128))
                    ]),
                    _: 2
                  }, 1032, ["modelValue", "onUpdate:modelValue", "placeholder"])) : (Vue.openBlock(), Vue.createBlock(_component_el_input, {
                    key: 1,
                    modelValue: item.value,
                    "onUpdate:modelValue": ($event) => item.value = $event,
                    placeholder: `输入${__props.valueLabel}`,
                    size: "small"
                  }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"]))
                ]),
                Vue.createElementVNode("div", _hoisted_9, [
                  Vue.createVNode(_component_el_select, {
                    modelValue: item.field,
                    "onUpdate:modelValue": ($event) => item.field = $event,
                    placeholder: `选择${__props.fieldLabel}`,
                    size: "small",
                    style: { "width": "100%" },
                    filterable: ""
                  }, {
                    default: Vue.withCtx(() => [
                      Vue.unref(formFields).length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_option_group, {
                        key: 0,
                        label: "表单字段"
                      }, {
                        default: Vue.withCtx(() => [
                          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(formFields), (field) => {
                            return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                              key: field.fieldId,
                              label: field.label,
                              value: field.fieldId
                            }, null, 8, ["label", "value"]);
                          }), 128))
                        ]),
                        _: 1
                      })) : Vue.createCommentVNode("", true),
                      Vue.unref(hiddenFields).length > 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_option_group, {
                        key: 1,
                        label: "隐藏域"
                      }, {
                        default: Vue.withCtx(() => [
                          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(hiddenFields), (field) => {
                            return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                              key: field.id,
                              label: field.label,
                              value: field.id
                            }, null, 8, ["label", "value"]);
                          }), 128))
                        ]),
                        _: 1
                      })) : Vue.createCommentVNode("", true)
                    ]),
                    _: 2
                  }, 1032, ["modelValue", "onUpdate:modelValue", "placeholder"])
                ]),
                Vue.createElementVNode("div", _hoisted_10, [
                  Vue.createVNode(_component_el_button, {
                    type: "danger",
                    size: "small",
                    icon: Vue.unref(index$2.Delete),
                    text: "",
                    onClick: ($event) => removeMapping(index2)
                  }, null, 8, ["icon", "onClick"])
                ])
              ]);
            }), 128))
          ]),
          Vue.createElementVNode("div", _hoisted_11, [
            Vue.createVNode(_component_el_dropdown, {
              "max-height": 500,
              trigger: "click",
              placement: "bottom",
              "hide-on-click": false,
              onVisibleChange: handleDropdownVisible,
              ref_key: "dropdownRef",
              ref: dropdownRef
            }, {
              dropdown: Vue.withCtx(() => [
                Vue.createVNode(_component_el_dropdown_menu, { class: "field-mapping-dropdown" }, {
                  default: Vue.withCtx(() => [
                    Vue.createElementVNode("div", _hoisted_12, [
                      _cache[9] || (_cache[9] = Vue.createElementVNode("span", { class: "header-title" }, "选择字段", -1)),
                      Vue.createVNode(_component_el_button, {
                        type: "primary",
                        size: "small",
                        onClick: confirmAddMappings
                      }, {
                        default: Vue.withCtx(() => _cache[8] || (_cache[8] = [
                          Vue.createTextVNode("确定")
                        ])),
                        _: 1
                      })
                    ]),
                    Vue.createElementVNode("div", _hoisted_13, [
                      Vue.createVNode(_component_el_scrollbar, { "max-height": 300 }, {
                        default: Vue.withCtx(() => [
                          (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(__props.valueOptions, (option) => {
                            return Vue.openBlock(), Vue.createBlock(_component_el_dropdown_item, {
                              key: option.fieldName
                            }, {
                              default: Vue.withCtx(() => [
                                Vue.createVNode(_component_el_checkbox, {
                                  modelValue: Vue.unref(selectedFields),
                                  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => Vue.isRef(selectedFields) ? selectedFields.value = $event : null),
                                  value: option.fieldName,
                                  label: option.label
                                }, null, 8, ["modelValue", "value", "label"])
                              ]),
                              _: 2
                            }, 1024);
                          }), 128)),
                          __props.valueOptions.length === 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_dropdown_item, {
                            key: 0,
                            disabled: ""
                          }, {
                            default: Vue.withCtx(() => _cache[10] || (_cache[10] = [
                              Vue.createElementVNode("span", { class: "empty-text" }, "暂无可用字段", -1)
                            ])),
                            _: 1
                          })) : Vue.createCommentVNode("", true)
                        ]),
                        _: 1
                      })
                    ])
                  ]),
                  _: 1
                })
              ]),
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_button, {
                  type: "primary",
                  size: "small",
                  icon: Vue.unref(index$2.Plus),
                  link: ""
                }, {
                  default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                    Vue.createTextVNode(" 新增字段映射 ")
                  ])),
                  _: 1
                }, 8, ["icon"])
              ]),
              _: 1
            }, 512)
          ])
        ]))
      ], 2);
    };
  }
};
const FieldSetMapping = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-15f7f3da"]]);
exports.default = FieldSetMapping;
