import { defineComponent as M, shallowRef as O, computed as p, ref as F, watch as q, provide as x, openBlock as v, createElementBlock as G, normalizeClass as n, unref as l, createVNode as u, withCtx as r, renderSlot as d, createElementVNode as H, createBlock as V, mergeProps as J, createCommentVNode as K } from "vue";
import { useNamespace as L, ElRow as P, ElCol as w, ElFormItem as y, ElForm as Q } from "element-plus";
import { wetProFormProps as U } from "./types.mjs";
import { SymbolState as X } from "./symbol.mjs";
import E from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/cloneDeep.mjs";
import _ from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/get.mjs";
import k from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/set.mjs";
const re = /* @__PURE__ */ M({
  name: "ProForm",
  __name: "index",
  props: U,
  emits: ["change", "update:modelValue"],
  setup(C, { expose: $, emit: I }) {
    const o = L("pro-form"), S = I, i = O(), s = C, N = p(() => ({
      span: s.span,
      ...s.colProps
    })), a = F({}), f = F({}), B = (e) => {
      const t = e.join(".");
      f.value[t] = e;
    }, c = (e) => {
      const t = s.valueEmptyModel === "filter" ? void 0 : null;
      if (e) {
        const m = (Array.isArray(e), e);
        return _(a.value, m, t);
      } else {
        const m = {};
        return Object.values(f.value).forEach((b) => {
          const D = _(a.value, b, t);
          k(m, b, D);
        }), m;
      }
    }, g = (e, t) => {
      k(a.value, e, t);
    }, T = (e) => {
      S("change", e, c());
    }, j = (e) => {
      var t;
      (t = i.value) == null || t.validateField(e);
    }, h = (e) => {
      var t;
      (t = i.value) == null || t.clearValidate(e);
    }, A = (e) => {
      var t;
      (t = i.value) == null || t.scrollToField(e);
    }, R = async () => {
      var e;
      return await ((e = i.value) == null ? void 0 : e.validate()), c();
    }, W = (e = !1) => (e ? a.value = {} : a.value = E(s.initialValues || {}), setTimeout(() => h(), 200), c());
    q(() => s.initialValues, (e) => {
      e ? a.value = E(e) : a.value = {};
    }, {
      immediate: !0,
      deep: !0
    });
    const z = p(() => s.labelWidth || "100px");
    return x(X, {
      registerFiledsPaths: f,
      formState: a,
      setFormStateValue: B,
      registerChangeEmit: T,
      globalColProps: N,
      labelWidth: z,
      clearable: p(() => s.clearable),
      setFieldsValue: g,
      getFieldsValue: c
    }), $({
      submit: R,
      reset: W,
      validateField: j,
      clearValidate: h,
      getFieldsValue: c,
      setFieldsValue: g,
      scrollToField: A
    }), (e, t) => s.isFormItem ? (v(), G("div", {
      key: 0,
      class: n([l(o).b()])
    }, [
      u(l(P), {
        gutter: s.gutter,
        class: n([l(o).e("row")])
      }, {
        default: r(() => [
          d(e.$slots, "default"),
          u(l(w), {
            class: n([l(o).e("actions")])
          }, {
            default: r(() => [
              u(l(y), null, {
                default: r(() => [
                  H("div", {
                    class: n([l(o).e("actions-slot")])
                  }, [
                    d(e.$slots, "actions")
                  ], 2)
                ]),
                _: 3
              })
            ]),
            _: 3
          }, 8, ["class"])
        ]),
        _: 3
      }, 8, ["gutter", "class"])
    ], 2)) : (v(), V(l(Q), J({
      key: 1,
      ref_key: "formIns",
      ref: i,
      class: [l(o).b()],
      model: a.value,
      "scroll-into-view-options": {
        behavior: "smooth",
        block: "center"
      },
      disabled: s.disabled
    }, e.$attrs), {
      default: r(() => [
        u(l(P), {
          gutter: s.gutter,
          class: n([l(o).e("row")])
        }, {
          default: r(() => [
            d(e.$slots, "default"),
            e.$slots.actions ? (v(), V(l(w), {
              key: 0,
              class: n([l(o).e("actions")])
            }, {
              default: r(() => [
                u(l(y), null, {
                  default: r(() => [
                    d(e.$slots, "actions")
                  ]),
                  _: 3
                })
              ]),
              _: 3
            }, 8, ["class"])) : K("", !0)
          ]),
          _: 3
        }, 8, ["gutter", "class"])
      ]),
      _: 3
    }, 16, ["class", "model", "disabled"]));
  }
});
export {
  re as default
};
