"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$1 = 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/button/index.js");
const index$2 = require("../../../node_modules/element-plus/es/components/select/index.js");
const index$3 = require("../../../node_modules/element-plus/es/components/input/index.js");
const _hoisted_1 = { class: "field-mapping-container" };
const _hoisted_2 = {
  key: 1,
  class: "mapping-table"
};
const _hoisted_3 = { class: "mapping-body" };
const _hoisted_4 = { class: "mapping-cell field-cell" };
const _hoisted_5 = { class: "mapping-cell value-cell" };
const _hoisted_6 = { class: "mapping-cell action-cell" };
const _hoisted_7 = { class: "mapping-footer" };
const _sfc_main = {
  __name: "FieldMapping",
  props: {
    modelValue: {
      type: Array,
      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 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
      }));
    });
    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
      }));
    });
    function addMapping() {
      mappings.value.push({
        id: Date.now(),
        field: "",
        value: ""
      });
    }
    function removeMapping(index2) {
      mappings.value.splice(index2, 1);
    }
    return (_ctx, _cache) => {
      const _component_el_button = index.ElButton;
      const _component_el_option = index$2.ElOption;
      const _component_el_option_group = index$2.ElOptionGroup;
      const _component_el_select = index$2.ElSelect;
      const _component_el_input = index$3.ElInput;
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        Vue.unref(mappings).length === 0 ? (Vue.openBlock(), Vue.createBlock(_component_el_button, {
          key: 0,
          type: "primary",
          size: "small",
          icon: Vue.unref(index$1.Plus),
          link: "",
          onClick: addMapping
        }, {
          default: Vue.withCtx(() => _cache[0] || (_cache[0] = [
            Vue.createTextVNode(" 新增字段映射 ")
          ])),
          _: 1
        }, 8, ["icon"])) : (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_2, [
          _cache[2] || (_cache[2] = Vue.createElementVNode("div", { class: "mapping-header" }, [
            Vue.createElementVNode("div", { class: "mapping-cell field-header" }, "表单字段"),
            Vue.createElementVNode("div", { class: "mapping-cell value-header" }, "映射字段"),
            Vue.createElementVNode("div", {
              class: "mapping-cell action-header",
              style: { "width": "50px" }
            })
          ], -1)),
          Vue.createElementVNode("div", _hoisted_3, [
            (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_4, [
                  Vue.createVNode(_component_el_select, {
                    modelValue: item.field,
                    "onUpdate:modelValue": ($event) => item.field = $event,
                    placeholder: "选择表单字段",
                    size: "small",
                    style: { "width": "100%" }
                  }, {
                    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"])
                ]),
                Vue.createElementVNode("div", _hoisted_5, [
                  Vue.createVNode(_component_el_input, {
                    modelValue: item.value,
                    "onUpdate:modelValue": ($event) => item.value = $event,
                    placeholder: "输入返回字段名",
                    size: "small"
                  }, null, 8, ["modelValue", "onUpdate:modelValue"])
                ]),
                Vue.createElementVNode("div", _hoisted_6, [
                  Vue.createVNode(_component_el_button, {
                    type: "danger",
                    size: "small",
                    icon: Vue.unref(index$1.Delete),
                    text: "",
                    onClick: ($event) => removeMapping(index2)
                  }, null, 8, ["icon", "onClick"])
                ])
              ]);
            }), 128))
          ]),
          Vue.createElementVNode("div", _hoisted_7, [
            Vue.createVNode(_component_el_button, {
              type: "primary",
              size: "small",
              icon: Vue.unref(index$1.Plus),
              link: "",
              onClick: addMapping
            }, {
              default: Vue.withCtx(() => _cache[1] || (_cache[1] = [
                Vue.createTextVNode(" 新增字段映射 ")
              ])),
              _: 1
            }, 8, ["icon"])
          ])
        ]))
      ]);
    };
  }
};
const FieldMapping = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-a09f49c9"]]);
exports.default = FieldMapping;
