import { g as wt, p as u, h as q, Z as Ct, l as m, i as Y, j as t, k as kt, m as Pt, R as a, n as Mt, q as G, S as tt, d as P, H as g, _ as At, w as Tt, x as H, aj as Ft, y as zt, z as v, a7 as Bt, aQ as et, B as b, s as M, u as ot, A as S, r as Dt, t as It, a as Rt, cI as jt, aM as qt, f as N } from "./index-G5Vdjjso.js";
import { a as Gt, F as Ht } from "./FormBlockComponent-B8-8OzbM.js";
var Nt = N("<!> <!>", 1), Ot = N("<div></div>"), Qt = N("<!> <!> <!> <!>", 1);
function Et(rt, s) {
  wt(s, !1);
  const y = () => H(V, "$component", A), O = () => H(Ft, "$builderStore", A), at = () => H(W, "$context", A), [A, st] = zt(), T = v(), F = v(), z = v(), x = v();
  let w = u(s, "actionType", 8), nt = u(s, "rowId", 8), lt = u(s, "noRowsMessage", 8), Q = u(s, "steps", 8), f = u(s, "dataSource", 8), U = u(s, "buttonPosition", 8, "bottom"), ct = u(s, "size", 8);
  const { fetchDatasourceSchema: it, generateGoldenSample: ut } = q("sdk"), V = q("component"), W = q("context"), Z = Bt(1);
  Ct("current-step", Z);
  let C = v();
  const E = () => {
    const e = et(V).id, c = et(W)[`${e}-provider`]?.rows || [], r = ut(c);
    return { [`${e}-repeater`]: r };
  }, dt = (e, c, r) => {
    if (!c)
      return;
    let i = Math.min(r || 0, e.length - 1);
    i = Math.max(i, 0), Z.set(i + 1);
  }, pt = async (e) => {
    b(C, await it(e) || {});
  }, mt = (e, c) => e?.length ? e.filter((r) => r.active) : Object.values(c || {}).filter((r) => !r.autocolumn).map((r) => ({ name: r.name, active: !0 })), gt = (e, c, r) => {
    const i = e?.length ? e : [{}];
    return i.map((B, k) => {
      const { title: D, fields: $, buttons: o } = B, _ = jt({
        _id: r,
        stepCount: i.length,
        currentStep: k,
        actionType: w(),
        dataSource: f()
      });
      return {
        ...B,
        _stepId: qt(),
        fields: mt($ || [], c),
        title: D ?? _.title,
        buttons: o || _.buttons
      };
    });
  };
  m(() => y(), () => {
    b(T, y().id);
  }), m(() => y(), () => {
    b(F, y().selected);
  }), m(() => O(), () => {
    b(z, O().metadata?.step);
  }), m(() => Y(f()), () => {
    pt(f());
  }), m(() => (Y(Q()), t(C), t(T)), () => {
    b(x, gt(Q(), t(C), t(T)));
  }), m(() => (t(x), t(F), t(z)), () => {
    dt(t(x), t(F), t(z));
  }), kt();
  var ft = { getAdditionalDataContext: E };
  Pt(), Gt(rt, {
    get actionType() {
      return w();
    },
    get dataSource() {
      return f();
    },
    get rowId() {
      return nt();
    },
    get noRowsMessage() {
      return lt();
    },
    children: (e, c) => {
      {
        let r = g(() => ({
          size: ct(),
          dataSource: f(),
          actionType: w() === "Create" ? "Create" : "Update",
          readonly: w() === "View"
        }));
        a(e, {
          type: "form",
          context: "form",
          get props() {
            return t(r);
          },
          styles: {
            normal: {
              width: "600px",
              "margin-left": "auto",
              "margin-right": "auto"
            }
          },
          children: (i, B) => {
            var k = Mt(), D = G(k);
            tt(D, 3, () => t(x), ($) => $._stepId, ($, o, _) => {
              {
                let _t = g(() => ({
                  step: t(_) + 1,
                  _instanceName: `Step ${t(_) + 1}`
                }));
                a($, {
                  type: "formstep",
                  get props() {
                    return t(_t);
                  },
                  children: (ht, Ut) => {
                    a(ht, {
                      type: "container",
                      props: {
                        gap: "M",
                        direction: "column",
                        hAlign: "stretch",
                        vAlign: "top",
                        size: "shrink"
                      },
                      children: (vt, Vt) => {
                        var J = Qt(), K = G(J);
                        a(K, {
                          type: "container",
                          props: { direction: "column", gap: "S" },
                          order: 0,
                          children: (n, I) => {
                            a(n, {
                              type: "container",
                              props: {
                                direction: "row",
                                hAlign: "stretch",
                                vAlign: "center",
                                gap: "M",
                                wrap: !0
                              },
                              order: 0,
                              children: (d, R) => {
                                var l = Nt(), p = G(l);
                                {
                                  let h = g(() => (t(o), S(() => ({ text: `## ${t(o).title}` }))));
                                  a(p, {
                                    type: "textv2",
                                    get props() {
                                      return t(h);
                                    }
                                  });
                                }
                                var j = M(p, 2);
                                {
                                  var yt = (h) => {
                                    {
                                      let xt = g(() => (t(o), S(() => ({ buttons: t(o).buttons }))));
                                      a(h, {
                                        type: "buttongroup",
                                        get props() {
                                          return t(xt);
                                        }
                                      });
                                    }
                                  };
                                  ot(j, (h) => {
                                    U() === "top" && h(yt);
                                  });
                                }
                                P(d, l);
                              },
                              $$slots: { default: !0 }
                            });
                          },
                          $$slots: { default: !0 }
                        });
                        var L = M(K, 2);
                        {
                          let n = g(() => (t(o), S(() => ({ text: t(o).desc }))));
                          a(L, {
                            type: "textv2",
                            get props() {
                              return t(n);
                            },
                            order: 1
                          });
                        }
                        var X = M(L, 2);
                        a(X, {
                          type: "container",
                          order: 2,
                          children: (n, I) => {
                            var d = Ot();
                            let R;
                            tt(d, 7, () => (t(o), S(() => t(o).fields)), (l, p) => `${l.field || l.name}_${p}`, (l, p, j) => {
                              Ht(l, {
                                get field() {
                                  return t(p);
                                },
                                get schema() {
                                  return t(C);
                                },
                                get order() {
                                  return t(j);
                                }
                              });
                            }), Dt(d), It((l) => R = Rt(d, 1, "form-block fields svelte-6gdv45", null, R, l), [() => ({ mobile: at().device.mobile })]), P(n, d);
                          },
                          $$slots: { default: !0 }
                        });
                        var bt = M(X, 2);
                        {
                          var St = (n) => {
                            {
                              let I = g(() => (t(o), S(() => ({
                                buttons: t(o).buttons,
                                collapsed: t(o).buttonsCollapsed,
                                collapsedText: t(o).buttonsCollapsedText
                              }))));
                              a(n, {
                                type: "buttongroup",
                                get props() {
                                  return t(I);
                                },
                                order: 3
                              });
                            }
                          };
                          ot(bt, (n) => {
                            U() === "bottom" && n(St);
                          });
                        }
                        P(vt, J);
                      },
                      $$slots: { default: !0 }
                    });
                  },
                  $$slots: { default: !0 }
                });
              }
            }), P(i, k);
          },
          $$slots: { default: !0 }
        });
      }
    },
    $$slots: { default: !0 }
  }), At(s, "getAdditionalDataContext", E);
  var $t = Tt(ft);
  return st(), $t;
}
export {
  Et as default
};
