import { defineComponent, ref, useSlots, computed, resolveComponent, createBlock, openBlock, mergeProps, toHandlers, unref, withCtx, createVNode, createCommentVNode, createElementBlock, Fragment, renderList, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, createElementVNode, toDisplayString } from 'vue';
import '../../../../utils/index.mjs';
import { drawerEmits } from 'element-plus';
import VNodeRenderer from '../../common/VNodeRenderer.mjs';
import { drawerFormEmits, drawerFormProps } from './drawerForm.mjs';
import { getGmEvent } from '../../../../utils/src/elementPlus/event.mjs';

var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "GmDrawerForm"
  },
  __name: "DrawerForm",
  props: drawerFormProps,
  emits: drawerFormEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const events = getGmEvent(drawerEmits, emit);
    const drawerForm = ref();
    __expose({
      drawerForm
    });
    const slots = useSlots();
    const formItemLists = computed(() => {
      const list = slots?.default?.();
      return list;
    });
    const formRef = ref();
    const resetFormHandle = () => {
      formRef.value.resetFields();
      emit("reset", formRef.value);
    };
    const submitFormHandle = () => {
      formRef.value.validate((valid, fields) => {
        if (valid) {
          emit("submit", props.formData);
        } else {
          emit("vaildFail", fields);
        }
      });
    };
    const cancelHandle = () => {
      emit("update:modelValue", false);
    };
    return (_ctx, _cache) => {
      const _component_gm_form_item_module = resolveComponent("gm-form-item-module");
      const _component_gm_form = resolveComponent("gm-form");
      const _component_gm_button = resolveComponent("gm-button");
      const _component_gm_drawer = resolveComponent("gm-drawer");
      return openBlock(), createBlock(
        _component_gm_drawer,
        mergeProps({
          ref_key: "drawerForm",
          ref: drawerForm
        }, props, toHandlers(unref(events))),
        {
          header: withCtx(() => [
            renderSlot(_ctx.$slots, "header", {}, () => [
              createElementVNode(
                "div",
                null,
                toDisplayString(_ctx.title),
                1
                /* TEXT */
              )
            ])
          ]),
          footer: withCtx(() => [
            renderSlot(_ctx.$slots, "footer", normalizeProps(guardReactiveProps({ formData: _ctx.formData, formRef: formRef.value })), () => [
              createVNode(_component_gm_button, { onClick: cancelHandle }, {
                default: withCtx(() => [
                  createTextVNode("\u53D6\u6D88")
                ]),
                _: 1
                /* STABLE */
              }),
              createVNode(_component_gm_button, {
                type: "primary",
                plain: "",
                onClick: resetFormHandle
              }, {
                default: withCtx(() => [
                  createTextVNode("\u91CD\u7F6E")
                ]),
                _: 1
                /* STABLE */
              }),
              createVNode(_component_gm_button, {
                loading: _ctx.loading,
                type: "primary",
                onClick: submitFormHandle
              }, {
                default: withCtx(() => [
                  createTextVNode("\u786E\u5B9A")
                ]),
                _: 1
                /* STABLE */
              }, 8, ["loading"])
            ])
          ]),
          default: withCtx(() => [
            createVNode(_component_gm_form, {
              ref_key: "formRef",
              ref: formRef,
              model: _ctx.formData,
              rules: _ctx.rules,
              "label-width": _ctx.labelWidth
            }, {
              default: withCtx(() => [
                createCommentVNode(" json \u5F62\u5F0F \u9ED8\u8BA4\u5728 \u6700\u4E0A\u8FB9 "),
                (openBlock(true), createElementBlock(
                  Fragment,
                  null,
                  renderList(_ctx.formItemList, (item) => {
                    return openBlock(), createBlock(_component_gm_form_item_module, mergeProps({
                      key: item.field
                    }, item, {
                      modelValue: _ctx.formData[item.field],
                      "onUpdate:modelValue": ($event) => _ctx.formData[item.field] = $event
                    }), null, 16, ["modelValue", "onUpdate:modelValue"]);
                  }),
                  128
                  /* KEYED_FRAGMENT */
                )),
                createCommentVNode(" slot \u5185\u5BB9 "),
                (openBlock(true), createElementBlock(
                  Fragment,
                  null,
                  renderList(formItemLists.value, (item) => {
                    return openBlock(), createElementBlock(
                      Fragment,
                      {
                        key: item.props.field
                      },
                      [
                        createCommentVNode(" \u4F7F\u7528 \u7EDF\u4E00\u5904\u7406item\u7EC4\u4EF6 gm-form-item-module "),
                        item.type.name === "GmFormItemModule" ? (openBlock(), createBlock(_component_gm_form_item_module, mergeProps({ key: 0 }, { ...item.props, children: item.children }, {
                          modelValue: _ctx.formData[item.props.field],
                          "onUpdate:modelValue": ($event) => _ctx.formData[item.props.field] = $event
                        }), null, 16, ["modelValue", "onUpdate:modelValue"])) : (openBlock(), createElementBlock(
                          Fragment,
                          { key: 1 },
                          [
                            createCommentVNode(" \u4F7F\u7528 form \u9ED8\u8BA4 item \u7EC4\u4EF6 gm-form-item "),
                            createCommentVNode(` v-if="item.type.name === 'GmFormItem'" `),
                            createVNode(unref(VNodeRenderer), { vnode: item }, null, 8, ["vnode"])
                          ],
                          64
                          /* STABLE_FRAGMENT */
                        ))
                      ],
                      64
                      /* STABLE_FRAGMENT */
                    );
                  }),
                  128
                  /* KEYED_FRAGMENT */
                ))
              ]),
              _: 1
              /* STABLE */
            }, 8, ["model", "rules", "label-width"])
          ]),
          _: 3
          /* FORWARDED */
        },
        16
        /* FULL_PROPS */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=DrawerForm.vue2.mjs.map
