/* empty css                                               */
/* empty css                                                     */
import { computed, provide, ref, useSlots, createBlock, openBlock, mergeProps, withCtx, createVNode, renderSlot, toRaw } from "vue";
import { getParmDicMapByKeys } from "../../../utils/optionUtil.mjs";
/* empty css           */
import _export_sfc from "../../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { Form } from "../../../../node_modules/vant/es/form/index.mjs";
import { CellGroup } from "../../../../node_modules/vant/es/cell-group/index.mjs";
const _sfc_main = {
  __name: "Form",
  props: {
    modelValue: {
      type: Object,
      default: {}
    },
    disabled: {
      type: Boolean,
      default: false
    },
    formType: {
      type: String,
      default: "edit"
    },
    isCard: {
      //卡片风格
      type: Boolean,
      default: false
    },
    isShadow: {
      //卡片阴影
      type: Boolean,
      default: true
    }
  },
  emits: ["update:modelValue", "submit"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const formData = computed({
      get: () => {
        return props.modelValue;
      },
      set: (val) => {
        emit("update:modelValue", val);
      }
    });
    provide("formData", formData);
    provide(
      "formDisabled",
      computed(() => props.disabled)
    );
    provide(
      "formReadonly",
      computed(() => props.formType == "detail")
    );
    const dicLoaded = ref(false);
    const slots = useSlots();
    const dicListMap = ref({});
    const processSlotComponents = async () => {
      var _a;
      const slotElements = (_a = slots.default) == null ? void 0 : _a.call(slots);
      const dicKeyList = [];
      if (slotElements) {
        slotElements.forEach((node) => {
          if (node.type.__name === "FormItem" && node.props.optionType == "dic") {
            dicKeyList.push(node.props.dicKey);
          }
        });
        if (dicKeyList.length > 0) {
          const uniqueDicKeys = [...new Set(dicKeyList)];
          dicListMap.value = await getParmDicMapByKeys(uniqueDicKeys.join(","));
        }
        dicLoaded.value = true;
      }
    };
    provide("dicListMap", dicListMap);
    processSlotComponents();
    function submitForm(oriFormData) {
      emit("submit", toRaw(formData.value));
    }
    return (_ctx, _cache) => {
      const _component_van_cell_group = CellGroup;
      const _component_van_form = Form;
      return openBlock(), createBlock(_component_van_form, mergeProps(_ctx.$attrs, {
        required: "auto",
        class: { fecMForm: true, isShadow: __props.isCard && __props.isShadow },
        onSubmit: submitForm
      }), {
        default: withCtx(() => [
          createVNode(_component_van_cell_group, { inset: __props.isCard }, {
            default: withCtx(() => [
              renderSlot(_ctx.$slots, "default", {}, void 0, true)
            ]),
            _: 3
          }, 8, ["inset"])
        ]),
        _: 3
      }, 16, ["class"]);
    };
  }
};
const _Form = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d3a67979"]]);
export {
  _Form as default
};
