import '@das-fed/ui/packages/components/form/style.css';
import { defineComponent as _, ref as p, useSlots as x, watch as N, nextTick as I, provide as M, reactive as b, onMounted as k, createElementBlock as S, openBlock as w, normalizeStyle as z, normalizeClass as B, renderSlot as C } from "vue";
import { withInstall as E } from "@das-fed/utils/with-install/index";
import "@das-fed/ui/packages/global/theme";
const L = /* @__PURE__ */ _({
  __name: "Index",
  props: {
    labelLength: { default: 4 },
    contentWidth: { default: 230 },
    labelPosition: { default: "top" },
    alignType: { default: "vertical" },
    alignItems: { default: "flex-start" },
    marginBottom: { default: "30px" },
    marginRight: { default: "30px" },
    cols: {},
    rules: { default: {} },
    labelMarginRight: { default: "30px" },
    isSearchForm: { type: Boolean, default: !1 },
    errorMode: { default: "default" },
    autoMarginRight: { type: Boolean, default: !1 }
  },
  setup(n, { expose: d }) {
    const a = n, i = p(), c = x(), g = () => {
      const e = ["#comment", "#text"], t = Array.from(i.value.childNodes).filter(
        (r) => !e.includes(r.nodeName)
      ), l = a.cols || 4;
      let o = 0;
      t.forEach((r, R) => {
        const f = Number(r.dataset.col ?? 1);
        o += f;
        const m = t[R];
        o === l || o > l && f === l ? m.classList.add("marin-right-0") : m.classList.remove("marin-right-0"), o === l ? o = 0 : o > l && (o = f);
      });
    };
    N(
      () => c.default(),
      (e) => {
        I(() => {
          u();
        });
      },
      {
        deep: !0
      }
    );
    let s = [];
    M("DasForm", b({ props: a, addField: (e) => {
      s.push(e);
    }, removeField: (e) => {
      s = s.filter((t) => t.timeStamp !== e.timeStamp);
    } }));
    const h = async (e) => {
      const t = await y();
      e(t);
    }, v = async (e, t) => {
      const o = await s.find((r) => r.propName === e && r.rules.length > 0).validate();
      t(o);
    }, y = async () => {
      let e = !0;
      for (const t of s)
        t.propName && t.rules.length > 0 && (await t.validate() || (e = !1));
      return e;
    }, F = () => {
      s.forEach((e) => {
        e.resetError();
      });
    }, u = () => {
      a.autoMarginRight && a.alignType === "horizontal" && g();
    };
    return k(u), d({
      validate: h,
      validateField: v,
      resetField: F
    }), (e, t) => (w(), S(
      "div",
      {
        class: B(["das-ui-form", { horizontal: e.alignType === "horizontal" }]),
        ref_key: "$formRef",
        ref: i,
        style: z({ alignItems: e.alignItems })
      },
      [
        C(e.$slots, "default", {}, void 0, !0)
      ],
      6
      /* CLASS, STYLE */
    ));
  }
}), T = (n, d) => {
  const a = n.__vccOpts || n;
  for (const [i, c] of d)
    a[i] = c;
  return a;
}, A = /* @__PURE__ */ T(L, [["__scopeId", "data-v-e05eb9be"]]), j = E(A), q = () => p(null);
export {
  j as DasForm,
  q as DasFormRef,
  j as default
};
