import "../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                       */
/* empty css                                                           */
/* empty css                                                               */
/* empty css                                                            */
/* empty css                                                         */
/* empty css                                                            */
/* empty css                                                                  */
/* empty css                                                            */
/* empty css                                                            */
import { computed, createElementBlock, openBlock, createBlock, unref, withCtx, createTextVNode, createElementVNode, Fragment, renderList, createVNode, createCommentVNode } from "vue";
import { Plus as plus_default, Delete as delete_default } from "../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import { getEditConfigDataFields, getEditConfigData } from "../packages/utils/common.mjs";
/* empty css                  */
import _export_sfc from "../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElButton } from "../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElSelect, ElOptionGroup, ElOption } from "../../../node_modules/element-plus/es/components/select/index.mjs";
import { ElInput } from "../../../node_modules/element-plus/es/components/input/index.mjs";
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 = computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const emit = __emit;
    const formFields = computed(() => {
      const fields = 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 = computed(() => {
      const editConfigData = 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(index) {
      mappings.value.splice(index, 1);
    }
    return (_ctx, _cache) => {
      const _component_el_button = ElButton;
      const _component_el_option = ElOption;
      const _component_el_option_group = ElOptionGroup;
      const _component_el_select = ElSelect;
      const _component_el_input = ElInput;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        unref(mappings).length === 0 ? (openBlock(), createBlock(_component_el_button, {
          key: 0,
          type: "primary",
          size: "small",
          icon: unref(plus_default),
          link: "",
          onClick: addMapping
        }, {
          default: withCtx(() => _cache[0] || (_cache[0] = [
            createTextVNode(" 新增字段映射 ")
          ])),
          _: 1
        }, 8, ["icon"])) : (openBlock(), createElementBlock("div", _hoisted_2, [
          _cache[2] || (_cache[2] = createElementVNode("div", { class: "mapping-header" }, [
            createElementVNode("div", { class: "mapping-cell field-header" }, "表单字段"),
            createElementVNode("div", { class: "mapping-cell value-header" }, "映射字段"),
            createElementVNode("div", {
              class: "mapping-cell action-header",
              style: { "width": "50px" }
            })
          ], -1)),
          createElementVNode("div", _hoisted_3, [
            (openBlock(true), createElementBlock(Fragment, null, renderList(unref(mappings), (item, index) => {
              return openBlock(), createElementBlock("div", {
                key: item.id,
                class: "mapping-row"
              }, [
                createElementVNode("div", _hoisted_4, [
                  createVNode(_component_el_select, {
                    modelValue: item.field,
                    "onUpdate:modelValue": ($event) => item.field = $event,
                    placeholder: "选择表单字段",
                    size: "small",
                    style: { "width": "100%" }
                  }, {
                    default: withCtx(() => [
                      unref(formFields).length > 0 ? (openBlock(), createBlock(_component_el_option_group, {
                        key: 0,
                        label: "表单字段"
                      }, {
                        default: withCtx(() => [
                          (openBlock(true), createElementBlock(Fragment, null, renderList(unref(formFields), (field) => {
                            return openBlock(), createBlock(_component_el_option, {
                              key: field.fieldId,
                              label: field.label,
                              value: field.fieldId
                            }, null, 8, ["label", "value"]);
                          }), 128))
                        ]),
                        _: 1
                      })) : createCommentVNode("", true),
                      unref(hiddenFields).length > 0 ? (openBlock(), createBlock(_component_el_option_group, {
                        key: 1,
                        label: "隐藏域"
                      }, {
                        default: withCtx(() => [
                          (openBlock(true), createElementBlock(Fragment, null, renderList(unref(hiddenFields), (field) => {
                            return openBlock(), createBlock(_component_el_option, {
                              key: field.id,
                              label: field.label,
                              value: field.id
                            }, null, 8, ["label", "value"]);
                          }), 128))
                        ]),
                        _: 1
                      })) : createCommentVNode("", true)
                    ]),
                    _: 2
                  }, 1032, ["modelValue", "onUpdate:modelValue"])
                ]),
                createElementVNode("div", _hoisted_5, [
                  createVNode(_component_el_input, {
                    modelValue: item.value,
                    "onUpdate:modelValue": ($event) => item.value = $event,
                    placeholder: "输入返回字段名",
                    size: "small"
                  }, null, 8, ["modelValue", "onUpdate:modelValue"])
                ]),
                createElementVNode("div", _hoisted_6, [
                  createVNode(_component_el_button, {
                    type: "danger",
                    size: "small",
                    icon: unref(delete_default),
                    text: "",
                    onClick: ($event) => removeMapping(index)
                  }, null, 8, ["icon", "onClick"])
                ])
              ]);
            }), 128))
          ]),
          createElementVNode("div", _hoisted_7, [
            createVNode(_component_el_button, {
              type: "primary",
              size: "small",
              icon: unref(plus_default),
              link: "",
              onClick: addMapping
            }, {
              default: withCtx(() => _cache[1] || (_cache[1] = [
                createTextVNode(" 新增字段映射 ")
              ])),
              _: 1
            }, 8, ["icon"])
          ])
        ]))
      ]);
    };
  }
};
const FieldMapping = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a09f49c9"]]);
export {
  FieldMapping as default
};
