import { defineComponent as $, shallowRef as d, useSlots as h, computed as B, cloneVNode as D, openBlock as f, createElementBlock as E, Fragment as F, createBlock as P, resolveDynamicComponent as S, createVNode as a, unref as s, mergeProps as p, withCtx as n, createElementVNode as c, normalizeClass as v, renderSlot as w, createTextVNode as _ } from "vue";
import { useNamespace as x, ElDrawer as A, ElButton as y } from "element-plus";
import I from "./index.vue.mjs";
import { wetDrawerFormProps as z } from "./types.mjs";
const O = { class: "footer-slot__inner" }, q = /* @__PURE__ */ $({
  __name: "drawer-form",
  props: z,
  setup(C) {
    const o = C, t = d(!1), m = d(), u = h(), i = x("drawer-form"), b = B(() => {
      const e = u.trigger && u.trigger();
      return () => e == null ? void 0 : e.map((r) => D(r, {
        onClick: () => {
          t.value = !0;
        }
      }));
    }), k = async () => {
      const e = await o.onCancel();
      t.value = !e;
    }, V = async () => {
      var e;
      if (o.onFinish) {
        const r = await ((e = m.value) == null ? void 0 : e.submit()), l = await o.onFinish(r);
        t.value = !l;
      }
    }, g = async () => {
      const e = await o.onCancel();
      t.value = !e;
    };
    return (e, r) => {
      var l;
      return f(), E(F, null, [
        (f(), P(S(b.value))),
        a(s(A), p({ "before-close": g }, o.drawerProps, {
          title: o.title || ((l = o.drawerProps) == null ? void 0 : l.title),
          "destroy-on-close": o.destroyOnClose,
          modelValue: t.value,
          "onUpdate:modelValue": r[0] || (r[0] = (N) => t.value = N),
          class: [s(i).b()]
        }), {
          footer: n(() => [
            c("div", {
              class: v([s(i).e("footer")])
            }, [
              c("div", O, [
                w(e.$slots, "footer")
              ]),
              c("div", null, [
                a(s(y), { onClick: k }, {
                  default: n(() => [
                    _("取消")
                  ]),
                  _: 1
                }),
                a(s(y), {
                  onClick: V,
                  type: "primary"
                }, {
                  default: n(() => [
                    _("确认")
                  ]),
                  _: 1
                })
              ])
            ], 2)
          ]),
          default: n(() => [
            c("div", {
              class: v([s(i).e("body")])
            }, [
              a(I, p({
                ref_key: "formInstance",
                ref: m
              }, o), {
                default: n(() => [
                  w(e.$slots, "default")
                ]),
                _: 3
              }, 16)
            ], 2)
          ]),
          _: 3
        }, 16, ["title", "destroy-on-close", "modelValue", "class"])
      ], 64);
    };
  }
});
export {
  q as default
};
