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