@sawabona/forms 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -134,6 +134,7 @@ Isso garante que sua lógica permaneça limpa e seu conteúdo seja facilmente ed
134
134
  | `i18n` | `object` | (Opcional) Tradução de botões e textos fixos. |
135
135
  | `autoReload` | `boolean` | (Opcional) Se `true`, reinicia o formulário automaticamente após o envio. |
136
136
  | `reloadDelay` | `number` | (Opcional) Tempo em milissegundos para aguardar antes de reiniciar (Padrão: 3000). |
137
+ | `disableAutoFocus` | `boolean` | (Opcional) Desativar scroll automático no carregamento (Padrão: false). |
137
138
 
138
139
  ---
139
140
 
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../src/lib/components/ui/TextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,2CA0H7D"}
1
+ {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../../src/lib/components/ui/TextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIjD,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,2CAgI7D"}
@@ -67,6 +67,7 @@ export interface FormSchema {
67
67
  };
68
68
  autoReload?: boolean;
69
69
  reloadDelay?: number;
70
+ disableAutoFocus?: boolean;
70
71
  }
71
72
  export type AnswerValue = string | number | boolean | string[] | number[];
72
73
  export interface FormState {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/core/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAClB,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IAAI,CAAC;IACrB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACrE"}
@@ -1,162 +1,164 @@
1
- var _ = Object.defineProperty, D = Object.defineProperties;
2
- var O = Object.getOwnPropertyDescriptors;
3
- var A = Object.getOwnPropertySymbols;
4
- var R = Object.prototype.hasOwnProperty, P = Object.prototype.propertyIsEnumerable;
5
- var T = (e, a, r) => a in e ? _(e, a, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[a] = r, x = (e, a) => {
6
- for (var r in a || (a = {}))
7
- R.call(a, r) && T(e, r, a[r]);
8
- if (A)
9
- for (var r of A(a))
10
- P.call(a, r) && T(e, r, a[r]);
1
+ var Q = Object.defineProperty, H = Object.defineProperties;
2
+ var K = Object.getOwnPropertyDescriptors;
3
+ var R = Object.getOwnPropertySymbols;
4
+ var z = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable;
5
+ var j = (e, i, r) => i in e ? Q(e, i, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[i] = r, h = (e, i) => {
6
+ for (var r in i || (i = {}))
7
+ z.call(i, r) && j(e, r, i[r]);
8
+ if (R)
9
+ for (var r of R(i))
10
+ $.call(i, r) && j(e, r, i[r]);
11
11
  return e;
12
- }, w = (e, a) => D(e, O(a));
13
- var j = (e) => typeof e == "symbol" ? e : e + "", z = (e, a) => {
12
+ }, g = (e, i) => H(e, K(i));
13
+ var B = (e) => typeof e == "symbol" ? e : e + "", _ = (e, i) => {
14
14
  var r = {};
15
15
  for (var t in e)
16
- R.call(e, t) && a.indexOf(t) < 0 && (r[t] = e[t]);
17
- if (e != null && A)
18
- for (var t of A(e))
19
- a.indexOf(t) < 0 && P.call(e, t) && (r[t] = e[t]);
16
+ z.call(e, t) && i.indexOf(t) < 0 && (r[t] = e[t]);
17
+ if (e != null && R)
18
+ for (var t of R(e))
19
+ i.indexOf(t) < 0 && $.call(e, t) && (r[t] = e[t]);
20
20
  return r;
21
21
  };
22
22
  import { jsxs as m, jsx as n } from "react/jsx-runtime";
23
- import { useState as H, useMemo as K, useCallback as C, createContext as Q, useContext as V, useRef as W, useEffect as L } from "react";
24
- import { motion as y, AnimatePresence as M } from "framer-motion";
25
- import { Check as $, Star as U, ChevronLeft as G, ChevronRight as X } from "lucide-react";
26
- function J({ schema: e, onSubmit: a }) {
27
- var b;
28
- const [r, t] = H({
23
+ import { useState as V, useMemo as W, useCallback as S, createContext as M, useContext as U, useRef as G, useEffect as P } from "react";
24
+ import { motion as w, AnimatePresence as X } from "framer-motion";
25
+ import { Check as D, Star as J, ChevronLeft as Y, ChevronRight as Z } from "lucide-react";
26
+ function q({ schema: e, onSubmit: i }) {
27
+ var v;
28
+ const [r, t] = V({
29
29
  answers: {},
30
- currentStepId: ((b = e.questions[0]) == null ? void 0 : b.id) || "",
30
+ currentStepId: ((v = e.questions[0]) == null ? void 0 : v.id) || "",
31
31
  history: [],
32
32
  isSubmitting: !1,
33
33
  errors: {},
34
34
  isCompleted: !1
35
- }), d = K(
36
- () => e.questions.findIndex((s) => s.id === r.currentStepId),
35
+ }), u = W(
36
+ () => e.questions.findIndex((a) => a.id === r.currentStepId),
37
37
  [e.questions, r.currentStepId]
38
- ), l = e.questions[d], h = C((s, o) => {
39
- t((i) => w(x({}, i), {
40
- answers: w(x({}, i.answers), {
41
- [s]: o
38
+ ), s = e.questions[u], p = S((a, o) => {
39
+ t((l) => g(h({}, l), {
40
+ answers: g(h({}, l.answers), {
41
+ [a]: o
42
42
  }),
43
43
  // Clear error on modification
44
- errors: w(x({}, i.errors), {
45
- [s]: ""
44
+ errors: g(h({}, l.errors), {
45
+ [a]: ""
46
46
  })
47
47
  }));
48
- }, []), u = C((s, o) => {
49
- t((i) => {
48
+ }, []), d = S((a, o) => {
49
+ t((l) => {
50
50
  if (o === null) {
51
- const N = i.errors, { [s]: k } = N, I = z(N, [j(s)]);
52
- return w(x({}, i), { errors: I });
51
+ const F = l.errors, { [a]: N } = F, y = _(F, [B(a)]);
52
+ return g(h({}, l), { errors: y });
53
53
  }
54
- return w(x({}, i), {
55
- errors: w(x({}, i.errors), { [s]: o })
54
+ return g(h({}, l), {
55
+ errors: g(h({}, l.errors), { [a]: o })
56
56
  });
57
57
  });
58
- }, []), c = C(() => {
59
- var i;
60
- if (!l) return !0;
61
- const s = r.answers[l.id], o = l.validation;
62
- return o && o.required && (s === void 0 || s === "" || Array.isArray(s) && s.length === 0) ? (u(l.id, ((i = e.i18n) == null ? void 0 : i.required) || "This field is required"), !1) : !0;
63
- }, [l, r.answers, u, e.i18n]), p = C((s) => {
64
- const o = e.questions.findIndex((i) => i.id === s.id);
58
+ }, []), c = S(() => {
59
+ var l;
60
+ if (!s) return !0;
61
+ const a = r.answers[s.id], o = s.validation;
62
+ return o && o.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (d(s.id, ((l = e.i18n) == null ? void 0 : l.required) || "This field is required"), !1) : !0;
63
+ }, [s, r.answers, d, e.i18n]), f = S((a) => {
64
+ const o = e.questions.findIndex((l) => l.id === a.id);
65
65
  return o < e.questions.length - 1 ? e.questions[o + 1].id : "submit";
66
- }, [e.questions]), f = C(() => {
66
+ }, [e.questions]), x = S(() => {
67
67
  if (!c()) return;
68
- const s = p(l);
69
- s === "submit" ? (t((o) => w(x({}, o), { isCompleted: !0 })), a == null || a(r.answers)) : t((o) => w(x({}, o), {
68
+ const a = f(s);
69
+ a === "submit" ? (t((o) => g(h({}, o), { isCompleted: !0 })), i == null || i(r.answers)) : t((o) => g(h({}, o), {
70
70
  history: [...o.history, o.currentStepId],
71
- currentStepId: s
71
+ currentStepId: a
72
72
  }));
73
- }, [l, r.answers, c, p, a]), g = C(() => {
73
+ }, [s, r.answers, c, f, i]), b = S(() => {
74
74
  if (r.history.length === 0) return;
75
- const s = r.history[r.history.length - 1];
76
- t((o) => w(x({}, o), {
75
+ const a = r.history[r.history.length - 1];
76
+ t((o) => g(h({}, o), {
77
77
  history: o.history.slice(0, -1),
78
- currentStepId: s
78
+ currentStepId: a
79
79
  }));
80
- }, [r.history]), v = C((s) => {
81
- if (!e.questions.some((i) => i.id === s)) {
82
- console.warn(`Step ${s} does not exist`);
80
+ }, [r.history]), C = S((a) => {
81
+ if (!e.questions.some((l) => l.id === a)) {
82
+ console.warn(`Step ${a} does not exist`);
83
83
  return;
84
84
  }
85
- t((i) => w(x({}, i), {
86
- history: [...i.history, i.currentStepId],
87
- currentStepId: s
85
+ t((l) => g(h({}, l), {
86
+ history: [...l.history, l.currentStepId],
87
+ currentStepId: a
88
88
  }));
89
- }, [e.questions]), S = C(() => {
90
- var s;
89
+ }, [e.questions]), I = S(() => {
90
+ var a;
91
91
  t({
92
92
  answers: {},
93
- currentStepId: ((s = e.questions[0]) == null ? void 0 : s.id) || "",
93
+ currentStepId: ((a = e.questions[0]) == null ? void 0 : a.id) || "",
94
94
  history: [],
95
95
  isSubmitting: !1,
96
96
  errors: {},
97
97
  isCompleted: !1
98
98
  });
99
99
  }, [e.questions]);
100
- return w(x({}, r), {
101
- setAnswer: h,
102
- nextStep: f,
103
- prevStep: g,
104
- jumpToStep: v,
105
- submitForm: () => a == null ? void 0 : a(r.answers),
106
- resetForm: S,
107
- registerError: u,
100
+ return g(h({}, r), {
101
+ setAnswer: p,
102
+ nextStep: x,
103
+ prevStep: b,
104
+ jumpToStep: C,
105
+ submitForm: () => i == null ? void 0 : i(r.answers),
106
+ resetForm: I,
107
+ registerError: d,
108
108
  // Helper to calculate progress
109
- progress: d / e.questions.length * 100
109
+ progress: u / e.questions.length * 100
110
110
  });
111
111
  }
112
- const B = Q(void 0), F = () => {
113
- const e = V(B);
112
+ const O = M(void 0), L = () => {
113
+ const e = U(O);
114
114
  if (!e)
115
115
  throw new Error("useFormContext must be used within a FormProvider");
116
116
  return e;
117
117
  };
118
- function Y({ question: e }) {
119
- var g, v, S, b, s;
120
- const { answers: a, setAnswer: r, nextStep: t } = F(), d = a[e.id], l = d != null ? String(d) : "", h = W(null);
121
- L(() => {
122
- const o = setTimeout(() => {
123
- var i;
124
- (i = h.current) == null || i.focus();
125
- }, 500);
126
- return () => clearTimeout(o);
127
- }, [e.id]);
128
- const u = (o) => {
129
- var k;
130
- let i = o.target.value;
131
- const N = ((k = e.validation) == null ? void 0 : k.maxLength) || 2048;
132
- if (i.length > N && (i = i.slice(0, N)), e.type === "number") {
133
- const I = i === "" ? "" : parseFloat(i);
134
- r(e.id, I);
118
+ function ee({ question: e }) {
119
+ var v, a, o, l, F;
120
+ const { answers: i, setAnswer: r, nextStep: t, schema: u } = L(), s = i[e.id], p = s != null ? String(s) : "", d = G(null), c = u.questions[0].id === e.id, f = !u.disableAutoFocus || !c;
121
+ P(() => {
122
+ if (f) {
123
+ const N = setTimeout(() => {
124
+ var y;
125
+ (y = d.current) == null || y.focus();
126
+ }, 500);
127
+ return () => clearTimeout(N);
128
+ }
129
+ }, [e.id, f]);
130
+ const x = (N) => {
131
+ var E;
132
+ let y = N.target.value;
133
+ const A = ((E = e.validation) == null ? void 0 : E.maxLength) || 2048;
134
+ if (y.length > A && (y = y.slice(0, A)), e.type === "number") {
135
+ const T = y === "" ? "" : parseFloat(y);
136
+ r(e.id, T);
135
137
  } else
136
- r(e.id, i);
137
- }, c = () => {
138
- var o, i, N, k, I;
139
- if ((o = e.validation) != null && o.required && !l) return !1;
140
- if (l) {
141
- if ((i = e.validation) != null && i.minLength && l.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l)) return !1;
142
- if ((N = e.validation) != null && N.pattern)
138
+ r(e.id, y);
139
+ }, b = () => {
140
+ var N, y, A, E, T;
141
+ if ((N = e.validation) != null && N.required && !p) return !1;
142
+ if (p) {
143
+ if ((y = e.validation) != null && y.minLength && p.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p)) return !1;
144
+ if ((A = e.validation) != null && A.pattern)
143
145
  try {
144
- if (!new RegExp(e.validation.pattern).test(l)) return !1;
145
- } catch (E) {
146
- console.error("Invalid regex pattern in schema", E);
146
+ if (!new RegExp(e.validation.pattern).test(p)) return !1;
147
+ } catch (k) {
148
+ console.error("Invalid regex pattern in schema", k);
147
149
  }
148
150
  if (e.type === "number") {
149
- const E = parseFloat(l);
150
- if (!isNaN(E) && (((k = e.validation) == null ? void 0 : k.min) !== void 0 && E < e.validation.min || ((I = e.validation) == null ? void 0 : I.max) !== void 0 && E > e.validation.max))
151
+ const k = parseFloat(p);
152
+ if (!isNaN(k) && (((E = e.validation) == null ? void 0 : E.min) !== void 0 && k < e.validation.min || ((T = e.validation) == null ? void 0 : T.max) !== void 0 && k > e.validation.max))
151
153
  return !1;
152
154
  }
153
155
  }
154
156
  return !0;
155
- }, p = (o) => {
156
- if (o.key === "Enter" && !o.shiftKey) {
157
- if (o.preventDefault(), !c()) {
158
- const i = document.querySelector(".sawabona-form-container") || document.body;
159
- i.classList.add("shake-animation"), setTimeout(() => i.classList.remove("shake-animation"), 500);
157
+ }, C = (N) => {
158
+ if (N.key === "Enter" && !N.shiftKey) {
159
+ if (N.preventDefault(), !b()) {
160
+ const y = document.querySelector(".sawabona-form-container") || document.body;
161
+ y.classList.add("shake-animation"), setTimeout(() => y.classList.remove("shake-animation"), 500);
160
162
  return;
161
163
  }
162
164
  t();
@@ -166,25 +168,24 @@ function Y({ question: e }) {
166
168
  /* @__PURE__ */ n(
167
169
  "input",
168
170
  {
169
- ref: h,
171
+ ref: d,
170
172
  type: e.type,
171
- value: typeof l == "string" || typeof l == "number" ? l : "",
172
- onChange: u,
173
- onKeyDown: p,
173
+ value: typeof p == "string" || typeof p == "number" ? p : "",
174
+ onChange: x,
175
+ onKeyDown: C,
174
176
  placeholder: e.placeholder,
175
- minLength: (g = e.validation) == null ? void 0 : g.minLength,
176
- maxLength: ((v = e.validation) == null ? void 0 : v.maxLength) || 2048,
177
- min: (S = e.validation) == null ? void 0 : S.min,
178
- max: (b = e.validation) == null ? void 0 : b.max,
179
- pattern: (s = e.validation) == null ? void 0 : s.pattern,
177
+ minLength: (v = e.validation) == null ? void 0 : v.minLength,
178
+ maxLength: ((a = e.validation) == null ? void 0 : a.maxLength) || 2048,
179
+ min: (o = e.validation) == null ? void 0 : o.min,
180
+ max: (l = e.validation) == null ? void 0 : l.max,
181
+ pattern: (F = e.validation) == null ? void 0 : F.pattern,
180
182
  className: `
181
183
  w-full bg-transparent border-b-2 border-sw-text-secondary/20
182
184
  py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
183
185
  placeholder:text-sw-text-secondary/30
184
186
  focus:border-sw-primary
185
187
  font-sw-heading
186
- `,
187
- autoFocus: !0
188
+ `
188
189
  }
189
190
  ),
190
191
  void 0,
@@ -196,45 +197,45 @@ function Y({ question: e }) {
196
197
  ] })
197
198
  ] });
198
199
  }
199
- function Z({ question: e }) {
200
- var u;
201
- const { answers: a, setAnswer: r, nextStep: t } = F(), d = a[e.id] || "", l = (c) => {
200
+ function te({ question: e }) {
201
+ var d;
202
+ const { answers: i, setAnswer: r, nextStep: t } = L(), u = i[e.id] || "", s = (c) => {
202
203
  r(e.id, c), setTimeout(() => t(), 400);
203
- }, h = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
204
- return L(() => {
205
- const c = (p) => {
206
- var v;
207
- const f = p.key.toUpperCase(), g = h.indexOf(f);
208
- g >= 0 && g < (((v = e.options) == null ? void 0 : v.length) || 0) && l(e.options[g].value);
204
+ }, p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
205
+ return P(() => {
206
+ const c = (f) => {
207
+ var C;
208
+ const x = f.key.toUpperCase(), b = p.indexOf(x);
209
+ b >= 0 && b < (((C = e.options) == null ? void 0 : C.length) || 0) && s(e.options[b].value);
209
210
  };
210
211
  return window.addEventListener("keydown", c), () => window.removeEventListener("keydown", c);
211
- }, [e.options, e.id]), /* @__PURE__ */ n("div", { className: "flex flex-col gap-3 w-full max-w-xl", children: (u = e.options) == null ? void 0 : u.map((c, p) => {
212
- const f = Array.isArray(d) ? d.includes(c.value) : d === c.value;
212
+ }, [e.options, e.id]), /* @__PURE__ */ n("div", { className: "flex flex-col gap-3 w-full max-w-xl", children: (d = e.options) == null ? void 0 : d.map((c, f) => {
213
+ const x = Array.isArray(u) ? u.includes(c.value) : u === c.value;
213
214
  return /* @__PURE__ */ m(
214
- y.button,
215
+ w.button,
215
216
  {
216
217
  initial: { opacity: 0, y: 10 },
217
218
  animate: { opacity: 1, y: 0 },
218
- transition: { delay: p * 0.05 },
219
- onClick: () => l(c.value),
219
+ transition: { delay: f * 0.05 },
220
+ onClick: () => s(c.value),
220
221
  className: `
221
222
  w-full text-left p-4 rounded-lg border-2 transition-all duration-200
222
223
  flex items-center justify-between group
223
- ${f ? "border-sw-primary bg-sw-primary/5 text-sw-primary" : "border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
224
+ ${x ? "border-sw-primary bg-sw-primary/5 text-sw-primary" : "border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
224
225
  `,
225
226
  children: [
226
227
  /* @__PURE__ */ m("span", { className: "text-lg font-medium flex items-center gap-3", children: [
227
228
  /* @__PURE__ */ n("span", { className: `
228
229
  w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
229
- ${f ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
230
- `, children: f && /* @__PURE__ */ n($, { size: 14, className: "text-sw-background" }) }),
230
+ ${x ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
231
+ `, children: x && /* @__PURE__ */ n(D, { size: 14, className: "text-sw-background" }) }),
231
232
  c.label
232
233
  ] }),
233
234
  /* @__PURE__ */ m("span", { className: "opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50", children: [
234
235
  "Select ",
235
236
  /* @__PURE__ */ m("span", { className: "hidden md:inline", children: [
236
237
  "Key ",
237
- p + 1
238
+ f + 1
238
239
  ] })
239
240
  ] })
240
241
  ]
@@ -243,58 +244,58 @@ function Z({ question: e }) {
243
244
  );
244
245
  }) });
245
246
  }
246
- function q({ question: e }) {
247
- var l;
248
- const { answers: a, setAnswer: r } = F(), t = a[e.id] || 0, d = Math.min(((l = e.validation) == null ? void 0 : l.max) || 5, 20);
247
+ function re({ question: e }) {
248
+ var s;
249
+ const { answers: i, setAnswer: r } = L(), t = i[e.id] || 0, u = Math.min(((s = e.validation) == null ? void 0 : s.max) || 5, 20);
249
250
  return /* @__PURE__ */ m("div", { className: "flex flex-col gap-6", children: [
250
- /* @__PURE__ */ n("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: d }).map((h, u) => {
251
- const c = u + 1, p = c <= t;
251
+ /* @__PURE__ */ n("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: u }).map((p, d) => {
252
+ const c = d + 1, f = c <= t;
252
253
  return /* @__PURE__ */ n(
253
- y.button,
254
+ w.button,
254
255
  {
255
256
  initial: { opacity: 0, scale: 0 },
256
257
  animate: { opacity: 1, scale: 1 },
257
- transition: { delay: u * 0.05 },
258
+ transition: { delay: d * 0.05 },
258
259
  onClick: () => r(e.id, c),
259
260
  whileHover: { scale: 1.2, rotate: 5 },
260
261
  whileTap: { scale: 0.9 },
261
262
  className: "focus:outline-none",
262
263
  children: /* @__PURE__ */ n(
263
- U,
264
+ J,
264
265
  {
265
- className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${p ? "fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]" : "text-zinc-600 hover:text-yellow-400/50"}`,
266
+ className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${f ? "fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]" : "text-zinc-600 hover:text-yellow-400/50"}`,
266
267
  strokeWidth: 1.5
267
268
  }
268
269
  )
269
270
  },
270
- u
271
+ d
271
272
  );
272
273
  }) }),
273
274
  /* @__PURE__ */ m("div", { className: "flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center", children: [
274
275
  /* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide", children: e.minLabel || "Poor" }),
275
276
  /* @__PURE__ */ n(
276
- y.div,
277
+ w.div,
277
278
  {
278
279
  initial: { opacity: 0, scale: 0.8 },
279
280
  animate: { opacity: t ? 1 : 0, scale: t ? 1 : 0.8 },
280
281
  className: "font-bold text-primary text-xl",
281
- children: t ? `${t} / ${d}` : ""
282
+ children: t ? `${t} / ${u}` : ""
282
283
  }
283
284
  ),
284
285
  /* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
285
286
  ] })
286
287
  ] });
287
288
  }
288
- function ee({ question: e }) {
289
- const { schema: a } = F(), r = a.questions.findIndex((u) => u.id === e.id) + 1, t = a.questions.length, d = {
289
+ function ne({ question: e }) {
290
+ const { schema: i } = L(), r = i.questions.findIndex((d) => d.id === e.id) + 1, t = i.questions.length, u = {
290
291
  hidden: { opacity: 0, y: 20 },
291
292
  visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] } }
292
- }, l = (u) => u && u.replace(/\{\{(\w+)\}\}/g, (c, p) => {
293
- const f = h.answers[p];
294
- return f != null ? String(f) : "";
295
- }), h = F();
293
+ }, s = (d) => d && d.replace(/\{\{(\w+)\}\}/g, (c, f) => {
294
+ const x = p.answers[f];
295
+ return x != null ? String(x) : "";
296
+ }), p = L();
296
297
  return /* @__PURE__ */ m(
297
- y.div,
298
+ w.div,
298
299
  {
299
300
  className: "flex flex-col gap-8 w-full max-w-4xl mx-auto",
300
301
  initial: "hidden",
@@ -304,33 +305,33 @@ function ee({ question: e }) {
304
305
  },
305
306
  children: [
306
307
  /* @__PURE__ */ m("div", { className: "flex flex-col gap-2", children: [
307
- /* @__PURE__ */ n(y.div, { variants: d, className: "flex gap-4 items-baseline", children: /* @__PURE__ */ m("span", { className: "flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm", children: [
308
+ /* @__PURE__ */ n(w.div, { variants: u, className: "flex gap-4 items-baseline", children: /* @__PURE__ */ m("span", { className: "flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm", children: [
308
309
  /* @__PURE__ */ n("span", { children: r }),
309
310
  /* @__PURE__ */ n("span", { className: "opacity-40 text-xs", children: "/" }),
310
311
  /* @__PURE__ */ n("span", { className: "opacity-60", children: t })
311
312
  ] }) }),
312
313
  /* @__PURE__ */ m(
313
- y.h2,
314
+ w.h2,
314
315
  {
315
- variants: d,
316
+ variants: u,
316
317
  className: "text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",
317
318
  children: [
318
- l(e.title),
319
+ s(e.title),
319
320
  " ",
320
321
  /* @__PURE__ */ n("span", { className: "text-sw-primary", children: "*" })
321
322
  ]
322
323
  }
323
324
  ),
324
325
  e.description && /* @__PURE__ */ n(
325
- y.p,
326
+ w.p,
326
327
  {
327
- variants: d,
328
+ variants: u,
328
329
  className: "text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",
329
- children: l(e.description)
330
+ children: s(e.description)
330
331
  }
331
332
  )
332
333
  ] }),
333
- /* @__PURE__ */ n(y.div, { variants: d, className: "w-full mt-6", children: e.type === "text" || e.type === "email" || e.type === "number" || e.type === "url" ? /* @__PURE__ */ n(Y, { question: e }) : e.type === "select" ? /* @__PURE__ */ n(Z, { question: e }) : e.type === "rating" ? /* @__PURE__ */ n(q, { question: e }) : /* @__PURE__ */ m("div", { className: "p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded", children: [
334
+ /* @__PURE__ */ n(w.div, { variants: u, className: "w-full mt-6", children: e.type === "text" || e.type === "email" || e.type === "number" || e.type === "url" ? /* @__PURE__ */ n(ee, { question: e }) : e.type === "select" ? /* @__PURE__ */ n(te, { question: e }) : e.type === "rating" ? /* @__PURE__ */ n(re, { question: e }) : /* @__PURE__ */ m("div", { className: "p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded", children: [
334
335
  "Unsupported question type: ",
335
336
  e.type,
336
337
  " (ID: ",
@@ -341,7 +342,7 @@ function ee({ question: e }) {
341
342
  }
342
343
  );
343
344
  }
344
- const te = {
345
+ const ie = {
345
346
  next: "Next",
346
347
  back: "Back",
347
348
  submit: "Submit",
@@ -349,16 +350,16 @@ const te = {
349
350
  optional: "Optional",
350
351
  stepInfo: "Question {{current}} of {{total}}"
351
352
  };
352
- function se({ schema: e, onSubmit: a }) {
353
- var S;
354
- const r = J({ schema: e, onSubmit: a }), t = e.theme || {
353
+ function ce({ schema: e, onSubmit: i }) {
354
+ var I;
355
+ const r = q({ schema: e, onSubmit: i }), t = e.theme || {
355
356
  backgroundColor: "#ffffff",
356
357
  textColor: "#000000",
357
358
  // Start with generic defaults, override in usage
358
359
  primaryColor: "#000000",
359
360
  borderRadius: "8px"
360
361
  // fontFamily removed to allow inheritance
361
- }, d = x(x({}, te), e.i18n), l = {
362
+ }, u = h(h({}, ie), e.i18n), s = {
362
363
  backgroundColor: t.backgroundColor,
363
364
  color: t.textColor,
364
365
  fontFamily: t.fontFamily,
@@ -369,49 +370,49 @@ function se({ schema: e, onSubmit: a }) {
369
370
  "--color-sw-text-secondary": t.textColor,
370
371
  "--font-sw-heading": t.fontFamily || "inherit",
371
372
  "--font-sw-body": t.fontFamily || "inherit"
372
- }, h = t.buttonVariant === "outline", u = {
373
- backgroundColor: h ? "transparent" : t.primaryColor,
374
- color: h ? t.primaryColor : t.textColor,
375
- border: h ? `2px solid ${t.primaryColor}` : "none",
373
+ }, p = t.buttonVariant === "outline", d = {
374
+ backgroundColor: p ? "transparent" : t.primaryColor,
375
+ color: p ? t.primaryColor : t.textColor,
376
+ border: p ? `2px solid ${t.primaryColor}` : "none",
376
377
  borderRadius: t.borderRadius || "8px",
377
378
  fontWeight: 600
378
379
  }, c = {
379
380
  color: t.primaryColor,
380
381
  borderRadius: t.borderRadius || "8px",
381
382
  fontWeight: 600
382
- }, { autoReload: p, reloadDelay: f = 3e3 } = e;
383
- if (L(() => {
384
- if (r.isCompleted && p) {
385
- const b = setTimeout(() => {
383
+ }, { autoReload: f, reloadDelay: x = 3e3 } = e;
384
+ if (P(() => {
385
+ if (r.isCompleted && f) {
386
+ const v = setTimeout(() => {
386
387
  r.resetForm();
387
- }, f);
388
- return () => clearTimeout(b);
388
+ }, x);
389
+ return () => clearTimeout(v);
389
390
  }
390
- }, [r.isCompleted, p, f, r.resetForm]), r.isCompleted)
391
+ }, [r.isCompleted, f, x, r.resetForm]), r.isCompleted)
391
392
  return /* @__PURE__ */ m(
392
393
  "div",
393
394
  {
394
395
  className: "flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",
395
- style: l,
396
+ style: s,
396
397
  children: [
397
- p && /* @__PURE__ */ n(
398
- y.div,
398
+ f && /* @__PURE__ */ n(
399
+ w.div,
399
400
  {
400
401
  initial: { width: "0%" },
401
402
  animate: { width: "100%" },
402
- transition: { duration: f / 1e3, ease: "linear" },
403
+ transition: { duration: x / 1e3, ease: "linear" },
403
404
  className: "absolute top-0 left-0 h-1 bg-green-500 z-50"
404
405
  }
405
406
  ),
406
407
  /* @__PURE__ */ m(
407
- y.div,
408
+ w.div,
408
409
  {
409
410
  initial: { scale: 0.9, opacity: 0, y: 20 },
410
411
  animate: { scale: 1, opacity: 1, y: 0 },
411
412
  transition: { duration: 0.6, ease: [0.22, 1, 0.36, 1] },
412
413
  className: "flex flex-col items-center",
413
414
  children: [
414
- /* @__PURE__ */ n("div", { className: "mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center", children: /* @__PURE__ */ n($, { size: 48 }) }),
415
+ /* @__PURE__ */ n("div", { className: "mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center", children: /* @__PURE__ */ n(D, { size: 48 }) }),
415
416
  /* @__PURE__ */ n("h1", { className: "text-4xl md:text-5xl font-bold mb-4 tracking-tight", children: "Obrigado!" }),
416
417
  /* @__PURE__ */ n("p", { className: "text-xl opacity-70 max-w-md leading-relaxed", children: "Suas respostas foram enviadas com sucesso." })
417
418
  ]
@@ -420,37 +421,37 @@ function se({ schema: e, onSubmit: a }) {
420
421
  ]
421
422
  }
422
423
  );
423
- const g = e.questions.find((b) => b.id === r.currentStepId), v = (e.questions.findIndex((b) => b.id === r.currentStepId) + 1) / e.questions.length * 100;
424
- return /* @__PURE__ */ n(B.Provider, { value: w(x({}, r), { schema: e }), children: /* @__PURE__ */ m(
424
+ const b = e.questions.find((v) => v.id === r.currentStepId), C = (e.questions.findIndex((v) => v.id === r.currentStepId) + 1) / e.questions.length * 100;
425
+ return /* @__PURE__ */ n(O.Provider, { value: g(h({}, r), { schema: e }), children: /* @__PURE__ */ m(
425
426
  "div",
426
427
  {
427
428
  className: "w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",
428
- style: l,
429
+ style: s,
429
430
  children: [
430
431
  /* @__PURE__ */ m("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
431
432
  /* @__PURE__ */ n("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
432
433
  /* @__PURE__ */ n(
433
- y.div,
434
+ w.div,
434
435
  {
435
436
  className: "h-full relative z-10",
436
437
  initial: { width: 0 },
437
- animate: { width: `${v}%` },
438
+ animate: { width: `${C}%` },
438
439
  transition: { duration: 0.5, ease: "easeInOut" },
439
440
  style: { backgroundColor: t.primaryColor }
440
441
  }
441
442
  )
442
443
  ] }),
443
- /* @__PURE__ */ n("div", { className: "flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10", children: /* @__PURE__ */ n(M, { mode: "wait", children: g && /* @__PURE__ */ n(
444
- y.div,
444
+ /* @__PURE__ */ n("div", { className: "flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10", children: /* @__PURE__ */ n(X, { mode: "wait", children: b && /* @__PURE__ */ n(
445
+ w.div,
445
446
  {
446
447
  initial: { opacity: 0, y: 40 },
447
448
  animate: { opacity: 1, y: 0 },
448
449
  exit: { opacity: 0, y: -40 },
449
450
  transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
450
451
  className: "w-full",
451
- children: /* @__PURE__ */ n(ee, { question: g })
452
+ children: /* @__PURE__ */ n(ne, { question: b })
452
453
  },
453
- g.id
454
+ b.id
454
455
  ) }) }),
455
456
  /* @__PURE__ */ m("div", { className: "w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4", children: [
456
457
  t.showPoweredBy !== !1 && /* @__PURE__ */ m(
@@ -465,7 +466,7 @@ function se({ schema: e, onSubmit: a }) {
465
466
  {
466
467
  className: "text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",
467
468
  style: { color: t.brandColor || t.primaryColor },
468
- children: ((S = t.poweredBy) == null ? void 0 : S.replace("Powered by ", "")) || "SAWABONA TECH"
469
+ children: ((I = t.poweredBy) == null ? void 0 : I.replace("Powered by ", "")) || "SAWABONA TECH"
469
470
  }
470
471
  )
471
472
  ]
@@ -473,7 +474,7 @@ function se({ schema: e, onSubmit: a }) {
473
474
  ),
474
475
  /* @__PURE__ */ m("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
475
476
  /* @__PURE__ */ n(
476
- y.button,
477
+ w.button,
477
478
  {
478
479
  onClick: r.prevStep,
479
480
  disabled: r.history.length === 0,
@@ -481,20 +482,20 @@ function se({ schema: e, onSubmit: a }) {
481
482
  whileTap: { scale: 0.95 },
482
483
  className: "w-12 h-12 md:w-14 md:h-14 flex items-center justify-center disabled:opacity-0 disabled:pointer-events-none transition-all hover:bg-white/5 rounded-full",
483
484
  style: c,
484
- children: /* @__PURE__ */ n(G, { size: 24 })
485
+ children: /* @__PURE__ */ n(Y, { size: 24 })
485
486
  }
486
487
  ),
487
488
  /* @__PURE__ */ m(
488
- y.button,
489
+ w.button,
489
490
  {
490
491
  onClick: r.nextStep,
491
492
  whileHover: { scale: 1.02 },
492
493
  whileTap: { scale: 0.98 },
493
494
  className: "px-8 py-3 md:px-10 md:py-4 text-lg font-bold shadow-2xl flex items-center gap-3 transition-all rounded-lg",
494
- style: u,
495
+ style: d,
495
496
  children: [
496
- /* @__PURE__ */ n("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || d.submit : d.next }),
497
- r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ n(X, { size: 20, strokeWidth: 3 })
497
+ /* @__PURE__ */ n("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || u.submit : u.next }),
498
+ r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ n(Z, { size: 20, strokeWidth: 3 })
498
499
  ]
499
500
  }
500
501
  )
@@ -505,5 +506,5 @@ function se({ schema: e, onSubmit: a }) {
505
506
  ) });
506
507
  }
507
508
  export {
508
- se as FormRenderer
509
+ ce as FormRenderer
509
510
  };
@@ -1,14 +1,14 @@
1
- (function(o,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("react/jsx-runtime"),require("react"),require("framer-motion"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","framer-motion","lucide-react"],t):(o=typeof globalThis!="undefined"?globalThis:o||self,t(o.SawabonaForms={},o.jsxRuntime,o.React,o.Motion,o.Lucide))})(this,(function(o,t,a,c,F){"use strict";var W=Object.defineProperty,U=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var j=(o,t,a)=>t in o?W(o,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[t]=a,h=(o,t)=>{for(var a in t||(t={}))P.call(t,a)&&j(o,a,t[a]);if(A)for(var a of A(t))z.call(t,a)&&j(o,a,t[a]);return o},g=(o,t)=>U(o,G(t));var $=o=>typeof o=="symbol"?o:o+"",B=(o,t)=>{var a={};for(var c in o)P.call(o,c)&&t.indexOf(c)<0&&(a[c]=o[c]);if(o!=null&&A)for(var c of A(o))t.indexOf(c)<0&&z.call(o,c)&&(a[c]=o[c]);return a};function O({schema:e,onSubmit:f}){var v;const[s,r]=a.useState({answers:{},currentStepId:((v=e.questions[0])==null?void 0:v.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1}),p=a.useMemo(()=>e.questions.findIndex(i=>i.id===s.currentStepId),[e.questions,s.currentStepId]),d=e.questions[p],w=a.useCallback((i,l)=>{r(n=>g(h({},n),{answers:g(h({},n.answers),{[i]:l}),errors:g(h({},n.errors),{[i]:""})}))},[]),x=a.useCallback((i,l)=>{r(n=>{if(l===null){const N=n.errors,{[i]:S}=N,I=B(N,[$(i)]);return g(h({},n),{errors:I})}return g(h({},n),{errors:g(h({},n.errors),{[i]:l})})})},[]),u=a.useCallback(()=>{var n;if(!d)return!0;const i=s.answers[d.id],l=d.validation;return l&&l.required&&(i===void 0||i===""||Array.isArray(i)&&i.length===0)?(x(d.id,((n=e.i18n)==null?void 0:n.required)||"This field is required"),!1):!0},[d,s.answers,x,e.i18n]),m=a.useCallback(i=>{const l=e.questions.findIndex(n=>n.id===i.id);return l<e.questions.length-1?e.questions[l+1].id:"submit"},[e.questions]),y=a.useCallback(()=>{if(!u())return;const i=m(d);i==="submit"?(r(l=>g(h({},l),{isCompleted:!0})),f==null||f(s.answers)):r(l=>g(h({},l),{history:[...l.history,l.currentStepId],currentStepId:i}))},[d,s.answers,u,m,f]),b=a.useCallback(()=>{if(s.history.length===0)return;const i=s.history[s.history.length-1];r(l=>g(h({},l),{history:l.history.slice(0,-1),currentStepId:i}))},[s.history]),C=a.useCallback(i=>{if(!e.questions.some(n=>n.id===i)){console.warn(`Step ${i} does not exist`);return}r(n=>g(h({},n),{history:[...n.history,n.currentStepId],currentStepId:i}))},[e.questions]),k=a.useCallback(()=>{var i;r({answers:{},currentStepId:((i=e.questions[0])==null?void 0:i.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1})},[e.questions]);return g(h({},s),{setAnswer:w,nextStep:y,prevStep:b,jumpToStep:C,submitForm:()=>f==null?void 0:f(s.answers),resetForm:k,registerError:x,progress:p/e.questions.length*100})}const L=a.createContext(void 0),T=()=>{const e=a.useContext(L);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e};function _({question:e}){var b,C,k,v,i;const{answers:f,setAnswer:s,nextStep:r}=T(),p=f[e.id],d=p!=null?String(p):"",w=a.useRef(null);a.useEffect(()=>{const l=setTimeout(()=>{var n;(n=w.current)==null||n.focus()},500);return()=>clearTimeout(l)},[e.id]);const x=l=>{var S;let n=l.target.value;const N=((S=e.validation)==null?void 0:S.maxLength)||2048;if(n.length>N&&(n=n.slice(0,N)),e.type==="number"){const I=n===""?"":parseFloat(n);s(e.id,I)}else s(e.id,n)},u=()=>{var l,n,N,S,I;if((l=e.validation)!=null&&l.required&&!d)return!1;if(d){if((n=e.validation)!=null&&n.minLength&&d.length<e.validation.minLength||e.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d))return!1;if((N=e.validation)!=null&&N.pattern)try{if(!new RegExp(e.validation.pattern).test(d))return!1}catch(E){console.error("Invalid regex pattern in schema",E)}if(e.type==="number"){const E=parseFloat(d);if(!isNaN(E)&&(((S=e.validation)==null?void 0:S.min)!==void 0&&E<e.validation.min||((I=e.validation)==null?void 0:I.max)!==void 0&&E>e.validation.max))return!1}}return!0},m=l=>{if(l.key==="Enter"&&!l.shiftKey){if(l.preventDefault(),!u()){const n=document.querySelector(".sawabona-form-container")||document.body;n.classList.add("shake-animation"),setTimeout(()=>n.classList.remove("shake-animation"),500);return}r()}};return t.jsxs("div",{className:"w-full relative group",children:[t.jsx("input",{ref:w,type:e.type,value:typeof d=="string"||typeof d=="number"?d:"",onChange:x,onKeyDown:m,placeholder:e.placeholder,minLength:(b=e.validation)==null?void 0:b.minLength,maxLength:((C=e.validation)==null?void 0:C.maxLength)||2048,min:(k=e.validation)==null?void 0:k.min,max:(v=e.validation)==null?void 0:v.max,pattern:(i=e.validation)==null?void 0:i.pattern,className:`
1
+ (function(n,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("react/jsx-runtime"),require("react"),require("framer-motion"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","framer-motion","lucide-react"],t):(n=typeof globalThis!="undefined"?globalThis:n||self,t(n.SawabonaForms={},n.jsxRuntime,n.React,n.Motion,n.Lucide))})(this,(function(n,t,o,l,I){"use strict";var X=Object.defineProperty,J=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var B=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var $=(n,t,o)=>t in n?X(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,g=(n,t)=>{for(var o in t||(t={}))B.call(t,o)&&$(n,o,t[o]);if(P)for(var o of P(t))O.call(t,o)&&$(n,o,t[o]);return n},b=(n,t)=>J(n,Y(t));var _=n=>typeof n=="symbol"?n:n+"",D=(n,t)=>{var o={};for(var l in n)B.call(n,l)&&t.indexOf(l)<0&&(o[l]=n[l]);if(n!=null&&P)for(var l of P(n))t.indexOf(l)<0&&O.call(n,l)&&(o[l]=n[l]);return o};function Q({schema:e,onSubmit:m}){var C;const[s,r]=o.useState({answers:{},currentStepId:((C=e.questions[0])==null?void 0:C.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1}),x=o.useMemo(()=>e.questions.findIndex(a=>a.id===s.currentStepId),[e.questions,s.currentStepId]),i=e.questions[x],f=o.useCallback((a,d)=>{r(c=>b(g({},c),{answers:b(g({},c.answers),{[a]:d}),errors:b(g({},c.errors),{[a]:""})}))},[]),p=o.useCallback((a,d)=>{r(c=>{if(d===null){const A=c.errors,{[a]:N}=A,w=D(A,[_(a)]);return b(g({},c),{errors:w})}return b(g({},c),{errors:b(g({},c.errors),{[a]:d})})})},[]),u=o.useCallback(()=>{var c;if(!i)return!0;const a=s.answers[i.id],d=i.validation;return d&&d.required&&(a===void 0||a===""||Array.isArray(a)&&a.length===0)?(p(i.id,((c=e.i18n)==null?void 0:c.required)||"This field is required"),!1):!0},[i,s.answers,p,e.i18n]),y=o.useCallback(a=>{const d=e.questions.findIndex(c=>c.id===a.id);return d<e.questions.length-1?e.questions[d+1].id:"submit"},[e.questions]),h=o.useCallback(()=>{if(!u())return;const a=y(i);a==="submit"?(r(d=>b(g({},d),{isCompleted:!0})),m==null||m(s.answers)):r(d=>b(g({},d),{history:[...d.history,d.currentStepId],currentStepId:a}))},[i,s.answers,u,y,m]),v=o.useCallback(()=>{if(s.history.length===0)return;const a=s.history[s.history.length-1];r(d=>b(g({},d),{history:d.history.slice(0,-1),currentStepId:a}))},[s.history]),k=o.useCallback(a=>{if(!e.questions.some(c=>c.id===a)){console.warn(`Step ${a} does not exist`);return}r(c=>b(g({},c),{history:[...c.history,c.currentStepId],currentStepId:a}))},[e.questions]),E=o.useCallback(()=>{var a;r({answers:{},currentStepId:((a=e.questions[0])==null?void 0:a.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1})},[e.questions]);return b(g({},s),{setAnswer:f,nextStep:h,prevStep:v,jumpToStep:k,submitForm:()=>m==null?void 0:m(s.answers),resetForm:E,registerError:p,progress:x/e.questions.length*100})}const z=o.createContext(void 0),F=()=>{const e=o.useContext(z);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e};function H({question:e}){var C,a,d,c,A;const{answers:m,setAnswer:s,nextStep:r,schema:x}=F(),i=m[e.id],f=i!=null?String(i):"",p=o.useRef(null),u=x.questions[0].id===e.id,y=!x.disableAutoFocus||!u;o.useEffect(()=>{if(y){const N=setTimeout(()=>{var w;(w=p.current)==null||w.focus()},500);return()=>clearTimeout(N)}},[e.id,y]);const h=N=>{var L;let w=N.target.value;const T=((L=e.validation)==null?void 0:L.maxLength)||2048;if(w.length>T&&(w=w.slice(0,T)),e.type==="number"){const j=w===""?"":parseFloat(w);s(e.id,j)}else s(e.id,w)},v=()=>{var N,w,T,L,j;if((N=e.validation)!=null&&N.required&&!f)return!1;if(f){if((w=e.validation)!=null&&w.minLength&&f.length<e.validation.minLength||e.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f))return!1;if((T=e.validation)!=null&&T.pattern)try{if(!new RegExp(e.validation.pattern).test(f))return!1}catch(S){console.error("Invalid regex pattern in schema",S)}if(e.type==="number"){const S=parseFloat(f);if(!isNaN(S)&&(((L=e.validation)==null?void 0:L.min)!==void 0&&S<e.validation.min||((j=e.validation)==null?void 0:j.max)!==void 0&&S>e.validation.max))return!1}}return!0},k=N=>{if(N.key==="Enter"&&!N.shiftKey){if(N.preventDefault(),!v()){const w=document.querySelector(".sawabona-form-container")||document.body;w.classList.add("shake-animation"),setTimeout(()=>w.classList.remove("shake-animation"),500);return}r()}};return t.jsxs("div",{className:"w-full relative group",children:[t.jsx("input",{ref:p,type:e.type,value:typeof f=="string"||typeof f=="number"?f:"",onChange:h,onKeyDown:k,placeholder:e.placeholder,minLength:(C=e.validation)==null?void 0:C.minLength,maxLength:((a=e.validation)==null?void 0:a.maxLength)||2048,min:(d=e.validation)==null?void 0:d.min,max:(c=e.validation)==null?void 0:c.max,pattern:(A=e.validation)==null?void 0:A.pattern,className:`
2
2
  w-full bg-transparent border-b-2 border-sw-text-secondary/20
3
3
  py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
4
4
  placeholder:text-sw-text-secondary/30
5
5
  focus:border-sw-primary
6
6
  font-sw-heading
7
- `,autoFocus:!0}),void 0,t.jsxs("p",{className:"text-sm opacity-50 mt-4",children:[e.type==="email"&&"Press Enter to continue",e.type==="text"&&"Press Enter to continue",e.type==="number"&&"Press Enter to continue",e.type==="url"&&"Press Enter to continue"]})]})}function D({question:e}){var x;const{answers:f,setAnswer:s,nextStep:r}=T(),p=f[e.id]||"",d=u=>{s(e.id,u),setTimeout(()=>r(),400)},w="ABCDEFGHIJKLMNOPQRSTUVWXYZ";return a.useEffect(()=>{const u=m=>{var C;const y=m.key.toUpperCase(),b=w.indexOf(y);b>=0&&b<(((C=e.options)==null?void 0:C.length)||0)&&d(e.options[b].value)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e.options,e.id]),t.jsx("div",{className:"flex flex-col gap-3 w-full max-w-xl",children:(x=e.options)==null?void 0:x.map((u,m)=>{const y=Array.isArray(p)?p.includes(u.value):p===u.value;return t.jsxs(c.motion.button,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:m*.05},onClick:()=>d(u.value),className:`
7
+ `}),void 0,t.jsxs("p",{className:"text-sm opacity-50 mt-4",children:[e.type==="email"&&"Press Enter to continue",e.type==="text"&&"Press Enter to continue",e.type==="number"&&"Press Enter to continue",e.type==="url"&&"Press Enter to continue"]})]})}function K({question:e}){var p;const{answers:m,setAnswer:s,nextStep:r}=F(),x=m[e.id]||"",i=u=>{s(e.id,u),setTimeout(()=>r(),400)},f="ABCDEFGHIJKLMNOPQRSTUVWXYZ";return o.useEffect(()=>{const u=y=>{var k;const h=y.key.toUpperCase(),v=f.indexOf(h);v>=0&&v<(((k=e.options)==null?void 0:k.length)||0)&&i(e.options[v].value)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e.options,e.id]),t.jsx("div",{className:"flex flex-col gap-3 w-full max-w-xl",children:(p=e.options)==null?void 0:p.map((u,y)=>{const h=Array.isArray(x)?x.includes(u.value):x===u.value;return t.jsxs(l.motion.button,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:y*.05},onClick:()=>i(u.value),className:`
8
8
  w-full text-left p-4 rounded-lg border-2 transition-all duration-200
9
9
  flex items-center justify-between group
10
- ${y?"border-sw-primary bg-sw-primary/5 text-sw-primary":"border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
10
+ ${h?"border-sw-primary bg-sw-primary/5 text-sw-primary":"border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
11
11
  `,children:[t.jsxs("span",{className:"text-lg font-medium flex items-center gap-3",children:[t.jsx("span",{className:`
12
12
  w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
13
- ${y?"border-sw-primary bg-sw-primary":"border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
14
- `,children:y&&t.jsx(F.Check,{size:14,className:"text-sw-background"})}),u.label]}),t.jsxs("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50",children:["Select ",t.jsxs("span",{className:"hidden md:inline",children:["Key ",m+1]})]})]},String(u.value))})})}function H({question:e}){var d;const{answers:f,setAnswer:s}=T(),r=f[e.id]||0,p=Math.min(((d=e.validation)==null?void 0:d.max)||5,20);return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx("div",{className:"flex gap-4 flex-wrap",children:Array.from({length:p}).map((w,x)=>{const u=x+1,m=u<=r;return t.jsx(c.motion.button,{initial:{opacity:0,scale:0},animate:{opacity:1,scale:1},transition:{delay:x*.05},onClick:()=>s(e.id,u),whileHover:{scale:1.2,rotate:5},whileTap:{scale:.9},className:"focus:outline-none",children:t.jsx(F.Star,{className:`w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${m?"fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]":"text-zinc-600 hover:text-yellow-400/50"}`,strokeWidth:1.5})},x)})}),t.jsxs("div",{className:"flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center",children:[t.jsx("span",{className:"text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide",children:e.minLabel||"Poor"}),t.jsx(c.motion.div,{initial:{opacity:0,scale:.8},animate:{opacity:r?1:0,scale:r?1:.8},className:"font-bold text-primary text-xl",children:r?`${r} / ${p}`:""}),t.jsx("span",{className:"text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide",children:e.maxLabel||"Excellent"})]})]})}function K({question:e}){const{schema:f}=T(),s=f.questions.findIndex(x=>x.id===e.id)+1,r=f.questions.length,p={hidden:{opacity:0,y:20},visible:{opacity:1,y:0,transition:{duration:.5,ease:[.22,1,.36,1]}}},d=x=>x&&x.replace(/\{\{(\w+)\}\}/g,(u,m)=>{const y=w.answers[m];return y!=null?String(y):""}),w=T();return t.jsxs(c.motion.div,{className:"flex flex-col gap-8 w-full max-w-4xl mx-auto",initial:"hidden",animate:"visible",variants:{visible:{transition:{staggerChildren:.1}}},children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(c.motion.div,{variants:p,className:"flex gap-4 items-baseline",children:t.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm",children:[t.jsx("span",{children:s}),t.jsx("span",{className:"opacity-40 text-xs",children:"/"}),t.jsx("span",{className:"opacity-60",children:r})]})}),t.jsxs(c.motion.h2,{variants:p,className:"text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",children:[d(e.title)," ",t.jsx("span",{className:"text-sw-primary",children:"*"})]}),e.description&&t.jsx(c.motion.p,{variants:p,className:"text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",children:d(e.description)})]}),t.jsx(c.motion.div,{variants:p,className:"w-full mt-6",children:e.type==="text"||e.type==="email"||e.type==="number"||e.type==="url"?t.jsx(_,{question:e}):e.type==="select"?t.jsx(D,{question:e}):e.type==="rating"?t.jsx(H,{question:e}):t.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded",children:["Unsupported question type: ",e.type," (ID: ",e.id,")"]})})]})}const Q={next:"Next",back:"Back",submit:"Submit",required:"Required",optional:"Optional",stepInfo:"Question {{current}} of {{total}}"};function V({schema:e,onSubmit:f}){var k;const s=O({schema:e,onSubmit:f}),r=e.theme||{backgroundColor:"#ffffff",textColor:"#000000",primaryColor:"#000000",borderRadius:"8px"},p=h(h({},Q),e.i18n),d={backgroundColor:r.backgroundColor,color:r.textColor,fontFamily:r.fontFamily,"--color-sw-primary":r.primaryColor,"--color-sw-background":r.backgroundColor,"--color-sw-text-primary":r.primaryColor,"--color-sw-text-secondary":r.textColor,"--font-sw-heading":r.fontFamily||"inherit","--font-sw-body":r.fontFamily||"inherit"},w=r.buttonVariant==="outline",x={backgroundColor:w?"transparent":r.primaryColor,color:w?r.primaryColor:r.textColor,border:w?`2px solid ${r.primaryColor}`:"none",borderRadius:r.borderRadius||"8px",fontWeight:600},u={color:r.primaryColor,borderRadius:r.borderRadius||"8px",fontWeight:600},{autoReload:m,reloadDelay:y=3e3}=e;if(a.useEffect(()=>{if(s.isCompleted&&m){const v=setTimeout(()=>{s.resetForm()},y);return()=>clearTimeout(v)}},[s.isCompleted,m,y,s.resetForm]),s.isCompleted)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",style:d,children:[m&&t.jsx(c.motion.div,{initial:{width:"0%"},animate:{width:"100%"},transition:{duration:y/1e3,ease:"linear"},className:"absolute top-0 left-0 h-1 bg-green-500 z-50"}),t.jsxs(c.motion.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"flex flex-col items-center",children:[t.jsx("div",{className:"mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center",children:t.jsx(F.Check,{size:48})}),t.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-4 tracking-tight",children:"Obrigado!"}),t.jsx("p",{className:"text-xl opacity-70 max-w-md leading-relaxed",children:"Suas respostas foram enviadas com sucesso."})]})]});const b=e.questions.find(v=>v.id===s.currentStepId),C=(e.questions.findIndex(v=>v.id===s.currentStepId)+1)/e.questions.length*100;return t.jsx(L.Provider,{value:g(h({},s),{schema:e}),children:t.jsxs("div",{className:"w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",style:d,children:[t.jsxs("div",{className:"absolute top-0 left-0 w-full h-1 z-50",children:[t.jsx("div",{className:"absolute top-0 left-0 w-full h-full bg-current opacity-10"}),t.jsx(c.motion.div,{className:"h-full relative z-10",initial:{width:0},animate:{width:`${C}%`},transition:{duration:.5,ease:"easeInOut"},style:{backgroundColor:r.primaryColor}})]}),t.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10",children:t.jsx(c.AnimatePresence,{mode:"wait",children:b&&t.jsx(c.motion.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},exit:{opacity:0,y:-40},transition:{duration:.5,ease:[.22,1,.36,1]},className:"w-full",children:t.jsx(K,{question:b})},b.id)})}),t.jsxs("div",{className:"w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4",children:[r.showPoweredBy!==!1&&t.jsxs("a",{href:"#",className:"order-3 md:order-1 group flex items-center gap-2 px-3 py-1.5 rounded-md border border-white/10 bg-black/20 hover:border-sw-primary/50 hover:bg-black/40 transition-all duration-300 cursor-pointer no-underline backdrop-blur-sm",children:[t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-medium tracking-[0.2em] uppercase text-muted-foreground group-hover:text-muted-foreground/80 transition-colors",children:"Powered By"}),t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",style:{color:r.brandColor||r.primaryColor},children:((k=r.poweredBy)==null?void 0:k.replace("Powered by ",""))||"SAWABONA TECH"})]}),t.jsxs("div",{className:"flex items-center gap-4 order-2 md:order-3 ml-auto",children:[t.jsx(c.motion.button,{onClick:s.prevStep,disabled:s.history.length===0,whileHover:{scale:1.05},whileTap:{scale:.95},className:"w-12 h-12 md:w-14 md:h-14 flex items-center justify-center disabled:opacity-0 disabled:pointer-events-none transition-all hover:bg-white/5 rounded-full",style:u,children:t.jsx(F.ChevronLeft,{size:24})}),t.jsxs(c.motion.button,{onClick:s.nextStep,whileHover:{scale:1.02},whileTap:{scale:.98},className:"px-8 py-3 md:px-10 md:py-4 text-lg font-bold shadow-2xl flex items-center gap-3 transition-all rounded-lg",style:x,children:[t.jsx("span",{children:s.currentStepId===e.questions[e.questions.length-1].id?r.submitText||p.submit:p.next}),s.currentStepId!==e.questions[e.questions.length-1].id&&t.jsx(F.ChevronRight,{size:20,strokeWidth:3})]})]})]})]})})}o.FormRenderer=V,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
13
+ ${h?"border-sw-primary bg-sw-primary":"border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
14
+ `,children:h&&t.jsx(I.Check,{size:14,className:"text-sw-background"})}),u.label]}),t.jsxs("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50",children:["Select ",t.jsxs("span",{className:"hidden md:inline",children:["Key ",y+1]})]})]},String(u.value))})})}function V({question:e}){var i;const{answers:m,setAnswer:s}=F(),r=m[e.id]||0,x=Math.min(((i=e.validation)==null?void 0:i.max)||5,20);return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx("div",{className:"flex gap-4 flex-wrap",children:Array.from({length:x}).map((f,p)=>{const u=p+1,y=u<=r;return t.jsx(l.motion.button,{initial:{opacity:0,scale:0},animate:{opacity:1,scale:1},transition:{delay:p*.05},onClick:()=>s(e.id,u),whileHover:{scale:1.2,rotate:5},whileTap:{scale:.9},className:"focus:outline-none",children:t.jsx(I.Star,{className:`w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${y?"fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]":"text-zinc-600 hover:text-yellow-400/50"}`,strokeWidth:1.5})},p)})}),t.jsxs("div",{className:"flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center",children:[t.jsx("span",{className:"text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide",children:e.minLabel||"Poor"}),t.jsx(l.motion.div,{initial:{opacity:0,scale:.8},animate:{opacity:r?1:0,scale:r?1:.8},className:"font-bold text-primary text-xl",children:r?`${r} / ${x}`:""}),t.jsx("span",{className:"text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide",children:e.maxLabel||"Excellent"})]})]})}function W({question:e}){const{schema:m}=F(),s=m.questions.findIndex(p=>p.id===e.id)+1,r=m.questions.length,x={hidden:{opacity:0,y:20},visible:{opacity:1,y:0,transition:{duration:.5,ease:[.22,1,.36,1]}}},i=p=>p&&p.replace(/\{\{(\w+)\}\}/g,(u,y)=>{const h=f.answers[y];return h!=null?String(h):""}),f=F();return t.jsxs(l.motion.div,{className:"flex flex-col gap-8 w-full max-w-4xl mx-auto",initial:"hidden",animate:"visible",variants:{visible:{transition:{staggerChildren:.1}}},children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(l.motion.div,{variants:x,className:"flex gap-4 items-baseline",children:t.jsxs("span",{className:"flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm",children:[t.jsx("span",{children:s}),t.jsx("span",{className:"opacity-40 text-xs",children:"/"}),t.jsx("span",{className:"opacity-60",children:r})]})}),t.jsxs(l.motion.h2,{variants:x,className:"text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",children:[i(e.title)," ",t.jsx("span",{className:"text-sw-primary",children:"*"})]}),e.description&&t.jsx(l.motion.p,{variants:x,className:"text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",children:i(e.description)})]}),t.jsx(l.motion.div,{variants:x,className:"w-full mt-6",children:e.type==="text"||e.type==="email"||e.type==="number"||e.type==="url"?t.jsx(H,{question:e}):e.type==="select"?t.jsx(K,{question:e}):e.type==="rating"?t.jsx(V,{question:e}):t.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded",children:["Unsupported question type: ",e.type," (ID: ",e.id,")"]})})]})}const U={next:"Next",back:"Back",submit:"Submit",required:"Required",optional:"Optional",stepInfo:"Question {{current}} of {{total}}"};function G({schema:e,onSubmit:m}){var E;const s=Q({schema:e,onSubmit:m}),r=e.theme||{backgroundColor:"#ffffff",textColor:"#000000",primaryColor:"#000000",borderRadius:"8px"},x=g(g({},U),e.i18n),i={backgroundColor:r.backgroundColor,color:r.textColor,fontFamily:r.fontFamily,"--color-sw-primary":r.primaryColor,"--color-sw-background":r.backgroundColor,"--color-sw-text-primary":r.primaryColor,"--color-sw-text-secondary":r.textColor,"--font-sw-heading":r.fontFamily||"inherit","--font-sw-body":r.fontFamily||"inherit"},f=r.buttonVariant==="outline",p={backgroundColor:f?"transparent":r.primaryColor,color:f?r.primaryColor:r.textColor,border:f?`2px solid ${r.primaryColor}`:"none",borderRadius:r.borderRadius||"8px",fontWeight:600},u={color:r.primaryColor,borderRadius:r.borderRadius||"8px",fontWeight:600},{autoReload:y,reloadDelay:h=3e3}=e;if(o.useEffect(()=>{if(s.isCompleted&&y){const C=setTimeout(()=>{s.resetForm()},h);return()=>clearTimeout(C)}},[s.isCompleted,y,h,s.resetForm]),s.isCompleted)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",style:i,children:[y&&t.jsx(l.motion.div,{initial:{width:"0%"},animate:{width:"100%"},transition:{duration:h/1e3,ease:"linear"},className:"absolute top-0 left-0 h-1 bg-green-500 z-50"}),t.jsxs(l.motion.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"flex flex-col items-center",children:[t.jsx("div",{className:"mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center",children:t.jsx(I.Check,{size:48})}),t.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-4 tracking-tight",children:"Obrigado!"}),t.jsx("p",{className:"text-xl opacity-70 max-w-md leading-relaxed",children:"Suas respostas foram enviadas com sucesso."})]})]});const v=e.questions.find(C=>C.id===s.currentStepId),k=(e.questions.findIndex(C=>C.id===s.currentStepId)+1)/e.questions.length*100;return t.jsx(z.Provider,{value:b(g({},s),{schema:e}),children:t.jsxs("div",{className:"w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",style:i,children:[t.jsxs("div",{className:"absolute top-0 left-0 w-full h-1 z-50",children:[t.jsx("div",{className:"absolute top-0 left-0 w-full h-full bg-current opacity-10"}),t.jsx(l.motion.div,{className:"h-full relative z-10",initial:{width:0},animate:{width:`${k}%`},transition:{duration:.5,ease:"easeInOut"},style:{backgroundColor:r.primaryColor}})]}),t.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10",children:t.jsx(l.AnimatePresence,{mode:"wait",children:v&&t.jsx(l.motion.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},exit:{opacity:0,y:-40},transition:{duration:.5,ease:[.22,1,.36,1]},className:"w-full",children:t.jsx(W,{question:v})},v.id)})}),t.jsxs("div",{className:"w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4",children:[r.showPoweredBy!==!1&&t.jsxs("a",{href:"#",className:"order-3 md:order-1 group flex items-center gap-2 px-3 py-1.5 rounded-md border border-white/10 bg-black/20 hover:border-sw-primary/50 hover:bg-black/40 transition-all duration-300 cursor-pointer no-underline backdrop-blur-sm",children:[t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-medium tracking-[0.2em] uppercase text-muted-foreground group-hover:text-muted-foreground/80 transition-colors",children:"Powered By"}),t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",style:{color:r.brandColor||r.primaryColor},children:((E=r.poweredBy)==null?void 0:E.replace("Powered by ",""))||"SAWABONA TECH"})]}),t.jsxs("div",{className:"flex items-center gap-4 order-2 md:order-3 ml-auto",children:[t.jsx(l.motion.button,{onClick:s.prevStep,disabled:s.history.length===0,whileHover:{scale:1.05},whileTap:{scale:.95},className:"w-12 h-12 md:w-14 md:h-14 flex items-center justify-center disabled:opacity-0 disabled:pointer-events-none transition-all hover:bg-white/5 rounded-full",style:u,children:t.jsx(I.ChevronLeft,{size:24})}),t.jsxs(l.motion.button,{onClick:s.nextStep,whileHover:{scale:1.02},whileTap:{scale:.98},className:"px-8 py-3 md:px-10 md:py-4 text-lg font-bold shadow-2xl flex items-center gap-3 transition-all rounded-lg",style:p,children:[t.jsx("span",{children:s.currentStepId===e.questions[e.questions.length-1].id?r.submitText||x.submit:x.next}),s.currentStepId!==e.questions[e.questions.length-1].id&&t.jsx(I.ChevronRight,{size:20,strokeWidth:3})]})]})]})]})})}n.FormRenderer=G,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sawabona/forms",
3
3
  "private": false,
4
- "version": "0.8.0",
4
+ "version": "0.9.0",
5
5
  "type": "module",
6
6
  "main": "./dist/sawabona-forms.umd.js",
7
7
  "module": "./dist/sawabona-forms.es.js",