import { isVNode as E, defineComponent as $, computed as p, useSlots as q, ref as d, watch as A, cloneVNode as L, createVNode as r, mergeProps as m, unref as a, openBlock as v, createElementBlock as D, Fragment as K, withCtx as b, createElementVNode as W, normalizeClass as G, normalizeStyle as H, renderSlot as C, createBlock as B, createCommentVNode as k, createTextVNode as J, toDisplayString as Q } from "vue";
import { Button as y, Flex as X, Space as Y, Modal as Z } from "@aplus-frontend/antdv";
import { omit as ee } from "lodash-unified";
import "../../render/index.mjs";
import "../../config-provider/index.mjs";
import "../../hooks/index.mjs";
import { getSingleVNode as te } from "../../utils/slot.mjs";
import "../ap-form.vue.mjs";
import le from "../style/modal-form.mjs";
import { useControllableValue as oe } from "../../hooks/useControllableValue.mjs";
import { useLocale as ae } from "../../config-provider/hooks/use-locale.mjs";
import { useNamespace as ne } from "../../config-provider/hooks/use-namespace.mjs";
import se from "../ap-form.vue2.mjs";
import P from "../../render/render.mjs";
function x(s) {
  return typeof s == "function" || Object.prototype.toString.call(s) === "[object Object]" && !E(s);
}
const Re = /* @__PURE__ */ $({
  name: "ApFormModalForm",
  __name: "index",
  props: {
    layout: {
      default: "horizontal"
    },
    labelCol: {},
    wrapperCol: {},
    colon: {
      type: Boolean,
      default: !0
    },
    labelAlign: {
      default: "right"
    },
    labelWrap: {
      type: Boolean
    },
    prefixCls: {},
    requiredMark: {},
    hideRequiredMark: {
      type: Boolean,
      default: !1
    },
    rules: {},
    validateMessages: {},
    validateOnRuleChange: {
      type: Boolean,
      default: !0
    },
    scrollToFirstError: {},
    onSubmit: {},
    name: {},
    validateTrigger: {
      default: "change"
    },
    size: {},
    disabled: {
      type: Boolean
    },
    onFieldsChange: {},
    onFinishFailed: {},
    onValidate: {},
    variant: {},
    initialValues: {},
    onValuesChange: {},
    syncToUrl: {
      type: [Boolean, Function]
    },
    syncToUrlPriority: {
      type: Boolean
    },
    autoFocusFirstInput: {
      type: Boolean
    },
    open: {
      type: Boolean,
      default: void 0
    },
    "onUpdate:open": {},
    modalProps: {
      default: () => ({})
    },
    title: {},
    width: {
      default: 800
    },
    onFinish: {},
    submitter: {
      type: [Boolean, Object],
      default: () => ({
        resetButtonProps: !1
      })
    },
    showCancel: {
      type: Boolean,
      default: !0
    },
    submitTimeout: {}
  },
  emits: ["update:open"],
  setup(s, {
    expose: S,
    emit: w
  }) {
    const t = s, N = p(() => ee(t, ["modalProps", "open", "onUpdate:open", "title", "width", "onFinish", "submitter"])), c = q(), R = w, o = d(), F = d(0), i = d(), n = d(!1), {
      value: I,
      updateValue: u
    } = oe(t, R, {
      valuePropName: "open",
      defaultValue: !1,
      beforeUpdateValue(e) {
        return e && (F.value += 1), !0;
      }
    }), {
      t: f
    } = ae(), M = le("ap-form-modal-form"), {
      b: U,
      e: h
    } = ne("ap-form-modal-form");
    A(() => o.value, (e) => {
      e && i.value && (e.setFieldsValue?.(i.value), i.value = void 0);
    });
    const g = p(() => {
      const e = te(c.trigger);
      return e ? L(e, {
        onClick: () => {
          u(!0);
        }
      }) : null;
    }), V = p(() => {
      const e = [];
      if (t.submitter === !1)
        return null;
      if (t.showCancel) {
        let l;
        e.push(r(y, {
          onClick: T,
          disabled: n.value
        }, x(l = f("ap.common.cancelText")) ? l : {
          default: () => [l]
        }));
      }
      return t.submitter?.resetButtonProps !== !1 && e.push(r(y, m(t.submitter?.resetButtonProps || {}, {
        key: "reset",
        disabled: n.value,
        onClick: j,
        htmlType: "reset"
      }), {
        default: () => [t.submitter?.resetText || f("ap.common.resetText")]
      })), t.submitter?.submitButtonProps !== !1 && e.push(r(y, m({
        type: "primary",
        key: "submit",
        htmlType: "submit"
      }, t.submitter?.submitButtonProps || {}, {
        loading: n.value
      }), {
        default: () => [t.submitter?.submitText || f("ap.common.okText")]
      })), r(X, {
        justify: "flex-end",
        key: a(F),
        class: [h("footer")]
      }, {
        default: () => [c.submitter ? c.submitter(e) : r(Y, null, x(e) ? e : {
          default: () => [e]
        })]
      });
    });
    function j() {
      t.submitter !== !1 && (o.value?.resetFields(), t.submitter?.onReset?.());
    }
    async function O(e) {
      if (t.submitter !== !1)
        try {
          t.submitter?.onSubmit?.(), n.value = !0;
          const l = t.onFinish?.(e);
          if (t.submitTimeout && l instanceof Promise) {
            const z = setTimeout(() => n.value = !1, t.submitTimeout);
            l.finally(() => {
              clearTimeout(z), n.value = !1;
            });
          }
          await l && u(!1);
        } finally {
          n.value = !1;
        }
    }
    function T() {
      a(n) || u(!1);
    }
    function _(e) {
      !e && a(n) || u(e);
    }
    return S({
      resetFields: async () => {
        o.value?.resetFields();
      },
      clearValidate: (e) => {
        o.value?.clearValidate(e);
      },
      validateFields: (e, l) => o.value?.validateFields(e, l),
      getFieldsValue: (e) => o.value?.getFieldsValue(e),
      validate: (e, l) => o.value?.validate(e, l),
      scrollToField: (e, l = {}) => {
        o.value?.scrollToField(e, l);
      },
      setFieldValue: (e, l) => {
        o.value?.setFieldValue?.(e, l);
      },
      setFieldsValue: (e) => {
        if (!o.value) {
          i.value = e;
          return;
        }
        o.value?.setFieldsValue?.(e);
      },
      getInternalInstance: (e) => o.value?.getInternalInstance(e),
      getFieldsValueTransformed(e) {
        return o.value?.getFieldsValueTransformed(e);
      },
      validateFieldsReturnTransformed(e, l) {
        return o.value?.validateFieldsReturnTransformed(e, l);
      }
    }), (e, l) => (v(), D(K, null, [r(a(Z), m(s.modalProps, {
      open: a(I),
      footer: null,
      width: s.width,
      class: [a(U)(), a(M)],
      "body-style": {
        padding: "0px !important"
      },
      "onUpdate:open": _,
      onCancel: T
    }), {
      title: b(() => [C(e.$slots, "title", {}, () => [J(Q(t.title), 1)])]),
      default: b(() => [r(se, m({
        ref_key: "formRef",
        ref: o
      }, N.value, {
        onFinish: O
      }), {
        default: b(() => [W("div", {
          style: H(s.modalProps?.bodyStyle),
          class: G(a(h)("content"))
        }, [C(e.$slots, "default")], 6), V.value ? (v(), B(a(P), {
          key: 0,
          node: V.value
        }, null, 8, ["node"])) : k("", !0)]),
        _: 3
      }, 16)]),
      _: 3
    }, 16, ["open", "width", "class"]), g.value ? (v(), B(a(P), {
      key: 0,
      node: g.value
    }, null, 8, ["node"])) : k("", !0)], 64));
  }
});
export {
  Re as default
};
