import "../../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                                */
/* empty css                                                                        */
/* empty css                                                                        */
/* empty css                                                                     */
/* empty css                                                                  */
/* empty css                                                                     */
/* empty css                                                                           */
/* empty css                                                                     */
import { getCurrentInstance, computed, ref, watch, createElementBlock, openBlock, Fragment, createVNode, withCtx, renderList, unref, createBlock } from "vue";
import FieldSetMapping from "../../../../components/FieldSetMapping.vue2.mjs";
import { getEditConfigDataFields } from "../../../utils/common.mjs";
import api from "../../../../api/index.mjs";
/* empty css                         */
import _export_sfc from "../../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElFormItem } from "../../../../../../node_modules/element-plus/es/components/form/index.mjs";
import { ElSelect, ElOption } from "../../../../../../node_modules/element-plus/es/components/select/index.mjs";
const _sfc_main = {
  __name: "TableChildSelection",
  props: {
    formData: Object
  },
  setup(__props) {
    const currentInstance = getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    const fieldList = computed(() => {
      return getEditConfigDataFields().filter(
        (item) => item.fieldType == "subTable"
      );
    });
    const subTableOptions = ref({});
    watch(
      () => props.formData.selectSubTableFieldId,
      (id) => {
        const fieldItem = getEditConfigDataFields().find((item) => item.id == id);
        if (fieldItem) {
          const subTableId = fieldItem.subTableId;
          api.getById(ctx.$http, subTableId).then((data) => {
            subTableOptions.value = JSON.parse(data.context);
          });
        }
      },
      {
        immediate: true
      }
    );
    const tableFields = computed(() => {
      var _a, _b;
      return [
        ...((_a = subTableOptions.value) == null ? void 0 : _a.fieldsData) || [],
        ...((_b = subTableOptions.value) == null ? void 0 : _b.hiddenFields) || []
      ];
    });
    return (_ctx, _cache) => {
      const _component_el_option = ElOption;
      const _component_el_select = ElSelect;
      const _component_el_form_item = ElFormItem;
      return openBlock(), createElementBlock(Fragment, null, [
        createVNode(_component_el_form_item, { label: "选择子列表" }, {
          default: withCtx(() => [
            createVNode(_component_el_select, {
              modelValue: __props.formData.selectSubTableFieldId,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => __props.formData.selectSubTableFieldId = $event),
              filterable: "",
              size: "small",
              clearable: ""
            }, {
              default: withCtx(() => [
                (openBlock(true), createElementBlock(Fragment, null, renderList(unref(fieldList), (item) => {
                  return openBlock(), createBlock(_component_el_option, {
                    key: item.id,
                    label: item.label,
                    value: item.id
                  }, null, 8, ["label", "value"]);
                }), 128))
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          _: 1
        }),
        createVNode(_component_el_form_item, { label: "选取后表单赋值映射" }, {
          default: withCtx(() => [
            createVNode(FieldSetMapping, {
              modelValue: __props.formData.subTableSelectionFieldMapping,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => __props.formData.subTableSelectionFieldMapping = $event),
              fieldLabel: "赋值表单字段",
              valueLabel: "列表字段",
              valueOptions: unref(tableFields),
              valueSelectMode: ""
            }, null, 8, ["modelValue", "valueOptions"])
          ]),
          _: 1
        })
      ], 64);
    };
  }
};
const TableChildSelection = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-170db076"]]);
export {
  TableChildSelection as default
};
