import '@das-fed/upf-ui/packages/components/form/style.css';
import { defineComponent as _, ref as f, reactive as d, computed as r, provide as R, openBlock as x, createElementBlock as S, normalizeClass as M, normalizeStyle as z, renderSlot as B } from "vue";
import { withInstall as $ } from "@das-fed/upf-utils/with-install/index";
import "@das-fed/upf-ui/packages/global/theme";
const b = /* @__PURE__ */ _({
  __name: "Index",
  props: {
    labelLength: { default: 4 },
    labelWidth: {},
    contentWidth: { default: 230 },
    labelPosition: { default: "top" },
    alignType: { default: "vertical" },
    alignItems: { default: "flex-start" },
    marginBottom: { default: "20px" },
    marginRight: { default: "30px" },
    cols: {},
    rules: { default: {} },
    labelMarginRight: { default: "16px" },
    isSearchForm: { type: Boolean, default: !1 },
    errorMode: { default: "default" },
    autoMarginRight: { type: Boolean, default: !1 },
    size: { default: "default" }
  },
  setup(o, { expose: n }) {
    const l = o, s = f();
    let a = d([]);
    const c = r(() => a.filter((e) => {
      var t;
      return (t = e.formItemProps) == null ? void 0 : t.required;
    }).length > 0), m = r(() => a.filter((e) => {
      var t;
      return (t = e.formItemProps) == null ? void 0 : t.helpMessage;
    }).length > 0);
    R("DasForm", d({ props: l, addField: (e) => {
      a.push(e);
    }, removeField: (e) => {
      a = a.filter((t) => t.timeStamp !== e.timeStamp);
    }, hasRequiredFormItem: c, hasHelpMessageFormItem: m }));
    const u = async (e) => {
      const t = await g();
      e(t);
    }, p = async (e, t) => {
      const I = await a.find((i) => i.propName === e && i.rules.length > 0).validate();
      t(I);
    }, g = async () => {
      let e = !0;
      for (const t of a)
        t.propName && t.rules.length > 0 && (await t.validate() || (e = !1));
      return e;
    }, h = () => {
      a.forEach((e) => {
        e.resetError();
      });
    }, v = r(() => ({
      display: "grid",
      gridTemplateColumns: `repeat(${l.cols}, ${l.contentWidth && l.contentWidth !== "auto" ? "min-content" : "1fr"})`,
      gridColumnGap: l.cols && l.autoMarginRight ? l.marginRight : void 0
    })), y = r(() => ({
      alignItems: l.alignItems,
      ...l.cols && l.alignType === "vertical" ? v.value : {}
    }));
    return n({
      validate: u,
      validateField: p,
      resetField: h
    }), (e, t) => (x(), S(
      "div",
      {
        class: M(["das-ui-form", { horizontal: o.alignType === "horizontal" }]),
        ref_key: "$formRef",
        ref: s,
        style: z(y.value)
      },
      [
        B(e.$slots, "default", {}, void 0, !0)
      ],
      6
      /* CLASS, STYLE */
    ));
  }
}), k = (o, n) => {
  const l = o.__vccOpts || o;
  for (const [s, a] of n)
    l[s] = a;
  return l;
}, w = /* @__PURE__ */ k(b, [["__scopeId", "data-v-e455d465"]]), P = $(w), q = () => f(null);
export {
  P as DasForm,
  q as DasFormRef,
  P as default
};
