'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../utils/index.js');
var elementPlus = require('element-plus');
var VNodeRenderer = require('../../common/VNodeRenderer.js');
var drawerForm = require('./drawerForm.js');
var event = require('../../../../utils/src/elementPlus/event.js');

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

exports.default = _sfc_main;
//# sourceMappingURL=DrawerForm.vue2.js.map
