import { bI as Oe, g as Qe, p as i, h as L, be as Re, o as Ue, l as F, i as s, j as r, k as We, m as Ye, n as T, q as k, u as V, d, w as Ze, x as le, y as $e, z as I, a7 as se, H as he, A as c, B as p, cr as et, E as ye, c as _, al as tt, r as b, X as at, t as N, a2 as Se, a as xe, b as re, e as Fe, s as X, v as lt, f as w, I as ke } from "./index-G5Vdjjso.js";
import Ie from "./Placeholder-Nqkfchy8.js";
import { I as st } from "./InnerForm-D-FagQtf.js";
var rt = w("<label> </label>"), ot = w('<div class="error svelte-16ch0tk"><!> <span class="svelte-16ch0tk"> </span></div>'), it = w('<div class="helpText svelte-16ch0tk"><!> <span class="svelte-16ch0tk"> </span></div>'), nt = w("<!> <!>", 1), dt = w('<div><!> <div class="spectrum-Form-itemField svelte-16ch0tk"><!></div></div>');
function ft(Ae, e) {
  const Pe = Oe(e, ["children", "$$slots", "$$events", "$$legacy"]);
  Qe(e, !1);
  const n = () => le(ze, "$component", K), J = () => le(Be, "$formStep", K), oe = () => le(ve, "$fieldInfo", K), [K, Ce] = $e(), q = I(), ie = I(), ne = I();
  let de = i(e, "label", 24, () => {
  }), O = i(e, "field", 24, () => {
  }), o = i(e, "fieldState", 12), z = i(e, "fieldApi", 12), v = i(e, "fieldSchema", 12), Q = i(e, "defaultValue", 24, () => {
  }), g = i(e, "type", 8), j = i(e, "disabled", 8, !1), A = i(e, "readonly", 8, !1), R = i(e, "validation", 8), B = i(e, "span", 8, 6), fe = i(e, "helpText", 24, () => {
  });
  const ce = L("form"), Le = L("form-step"), Te = L("field-group"), { styleable: Ve, builderStore: we, Provider: qe } = L("sdk"), ze = L("component"), je = ce?.formApi, U = Te?.labelPosition || "above";
  let W = I(), Y = I(!1), D = I();
  const Be = Le || se(1), ve = Re({
    field: O() || n().name,
    type: g(),
    defaultValue: Q(),
    disabled: j(),
    readonly: A(),
    validation: R(),
    formStep: J() || 1
  }), De = (a) => {
    p(W, je?.registerField(a.field, a.type, a.defaultValue, a.disabled, a.readonly, a.validation, a.formStep));
  }, Ee = (a) => {
    if (r(Y)) {
      const Z = a.target;
      we.actions.updateProp("label", Z.textContent);
    }
    p(Y, !1);
  };
  Ue(() => {
    z()?.deregister(), r(ie)?.();
  }), F(
    () => (s(O()), n(), s(g()), s(Q()), s(j()), s(A()), s(R()), J()),
    () => {
      ve.set({
        field: O() || n().name,
        type: g(),
        defaultValue: Q(),
        disabled: j(),
        readonly: A(),
        validation: R(),
        formStep: J() || 1
      });
    }
  ), F(() => oe(), () => {
    De(oe());
  }), F(() => r(W), () => {
    p(ie, r(W)?.subscribe((a) => {
      o(a?.fieldState), z(a?.fieldApi), v(a?.fieldSchema);
    }));
  }), F(() => s(v()), () => {
    p(q, v()?.type !== "formula" && v()?.type !== "bigint" ? v()?.type : "string");
  }), F(() => (n(), r(D)), () => {
    n().editing && r(D)?.focus();
  }), F(() => {
  }, () => {
    p(ne, U === "above" ? "" : `spectrum-FieldLabel--${U}`);
  }), We(), Ye();
  {
    let a = he(() => (s(o()), c(() => ({ value: o()?.value }))));
    qe(Ae, {
      get data() {
        return r(a);
      },
      children: (Z, ct) => {
        var ue = T(), Ge = k(ue);
        {
          var He = (h) => {
            {
              let u = he(() => (s(se), c(() => se(1))));
              st(h, {
                get disabled() {
                  return j();
                },
                get readonly() {
                  return A();
                },
                get currentStep() {
                  return r(u);
                },
                provideContext: !1,
                children: (E, $) => {
                  var P = T(), ee = k(P);
                  ft(ee, et(() => Pe, {
                    get fieldState() {
                      return o();
                    },
                    set fieldState(f) {
                      o(f);
                    },
                    get fieldApi() {
                      return z();
                    },
                    set fieldApi(f) {
                      z(f);
                    },
                    get fieldSchema() {
                      return v();
                    },
                    set fieldSchema(f) {
                      v(f);
                    },
                    children: (f, me) => {
                      var l = T(), t = k(l);
                      ye(t, e, "default", {}, null), d(f, l);
                    },
                    $$slots: { default: !0 },
                    $$legacy: !0
                  })), d(E, P);
                },
                $$slots: { default: !0 }
              });
            }
          }, Me = (h) => {
            var u = dt();
            let E;
            var $ = _(u);
            tt($, () => (n(), c(() => n().editing)), (l) => {
              var t = rt();
              let G;
              var te = _(t, !0);
              b(t), at(t, (m) => p(D, m), () => r(D)), N(
                (m) => {
                  Se(t, "contenteditable", (n(), c(() => n().editing))), Se(t, "for", (s(o()), c(() => o()?.fieldId))), G = xe(t, 1, `spectrum-FieldLabel spectrum-FieldLabel--sizeM spectrum-Form-itemLabel ${r(ne)}`, "svelte-16ch0tk", G, m), re(te, de() || " ");
                },
                [() => ({ hidden: !de(), readonly: A() })]
              ), Fe("blur", t, function(...m) {
                (n().editing ? Ee : null)?.apply(this, m);
              }), Fe("input", t, () => p(Y, !0)), d(l, t);
            });
            var P = X($, 2), ee = _(P);
            {
              var f = (l) => {
                Ie(l, {});
              }, me = (l) => {
                var t = T(), G = k(t);
                {
                  var te = (y) => {
                    Ie(y, {
                      text: "This Field setting is the wrong data type for this component"
                    });
                  }, m = (y) => {
                    var pe = nt(), _e = k(pe);
                    ye(_e, e, "default", {}, null);
                    var Ne = X(_e, 2);
                    {
                      var Xe = (S) => {
                        var x = ot(), H = _(x);
                        ke(H, { name: "warning" });
                        var M = X(H, 2), C = _(M, !0);
                        b(M), b(x), N(() => re(C, (s(o()), c(() => o().error)))), d(S, x);
                      }, Je = (S) => {
                        var x = T(), H = k(x);
                        {
                          var M = (C) => {
                            var ae = it(), be = _(ae);
                            ke(be, { name: "question" });
                            var ge = X(be, 2), Ke = _(ge, !0);
                            b(ge), b(ae), N(() => re(Ke, fe())), d(C, ae);
                          };
                          V(
                            H,
                            (C) => {
                              fe() && C(M);
                            },
                            !0
                          );
                        }
                        d(S, x);
                      };
                      V(Ne, (S) => {
                        s(o()), c(() => o().error) ? S(Xe) : S(Je, !1);
                      });
                    }
                    d(y, pe);
                  };
                  V(
                    G,
                    (y) => {
                      r(q), s(g()), c(() => r(q) && r(q) !== g() && !["options", "longform"].includes(g())) ? y(te) : y(m, !1);
                    },
                    !0
                  );
                }
                d(l, t);
              };
              V(ee, (l) => {
                o() ? l(me, !1) : l(f);
              });
            }
            b(P), b(u), lt(u, (l, t) => Ve?.(l, t), () => n().styles), N((l) => E = xe(u, 1, "spectrum-Form-item svelte-16ch0tk", null, E, l), [
              () => ({
                "span-2": B() === 2,
                "span-3": B() === 3,
                "span-6": B() === 6 || !B(),
                above: U === "above"
              })
            ]), d(h, u);
          };
          V(Ge, (h) => {
            ce ? h(Me, !1) : h(He);
          });
        }
        d(Z, ue);
      },
      $$slots: { default: !0 }
    });
  }
  Ze(), Ce();
}
export {
  ft as F
};
