@inploi/plugin-chatbot 3.30.0 → 4.0.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.
@@ -0,0 +1,4012 @@
1
+ import { g as Ue, i as tr, k as Le, a as rr, b as le, A as Me, c as Fr, N as Ke, _ as I, d as nr, h as Y, e as re, p as ue, F as mt, u as Z, o as l, f as Ne, j as ft, y as pe, s as M, l as Ze, m as he, n as Lr, q as at, r as ee, t as Nr, v as _e, w as Tr, x as sr, z as Dr, B as ar, C as Rr, D as Se, E as X, G as Or, V as Br, H as ir, I as $e, J as je, K as Pr, L as $r, M as jr, O as zr, P as qr, Q as Ur, R as Lt, S as Kr, T as Gr, U as Hr } from "./index-a2c09edd.js";
2
+ import "@inploi/sdk";
3
+ const Nt = ({
4
+ condition: e,
5
+ context: t,
6
+ submissions: r,
7
+ ifBlock: n
8
+ }) => {
9
+ const [s, ...a] = e.compareKey.split(".");
10
+ if (!s)
11
+ return !1;
12
+ const i = lr({
13
+ context: t,
14
+ key: s,
15
+ path: a,
16
+ submissions: r
17
+ });
18
+ if (!i)
19
+ return !1;
20
+ switch (i.type) {
21
+ case "address": {
22
+ const u = Ue(i.value, a.join("."));
23
+ switch (e.compare) {
24
+ case "equals":
25
+ return u === e.compareValue;
26
+ case "contains":
27
+ return u ? u.includes(e.compareValue) : !1;
28
+ case "notEquals":
29
+ return u !== e.compareValue;
30
+ case "notContains":
31
+ return u ? !u.includes(e.compareValue) : !0;
32
+ }
33
+ break;
34
+ }
35
+ case "integration": {
36
+ if (typeof i.value != "object" || Array.isArray(i.value))
37
+ return !1;
38
+ const u = Ue(i.value, a.join(".")), c = {
39
+ ...n,
40
+ data: {
41
+ ...n.data,
42
+ compareKey: "_temp"
43
+ }
44
+ };
45
+ switch (typeof u) {
46
+ case "boolean":
47
+ return Fe(c, {
48
+ submissions: {
49
+ _temp: {
50
+ value: u,
51
+ type: "boolean"
52
+ }
53
+ },
54
+ context: t
55
+ });
56
+ case "string":
57
+ return Fe(c, {
58
+ submissions: {
59
+ _temp: {
60
+ value: u,
61
+ type: "string"
62
+ }
63
+ },
64
+ context: t
65
+ });
66
+ case "number":
67
+ return Fe(c, {
68
+ submissions: {
69
+ _temp: {
70
+ value: u,
71
+ type: "number"
72
+ }
73
+ },
74
+ context: t
75
+ });
76
+ case "object":
77
+ return Array.isArray(u) && u.every(tr) ? Fe(c, {
78
+ submissions: {
79
+ _temp: {
80
+ value: u,
81
+ type: "enum"
82
+ }
83
+ },
84
+ context: t
85
+ }) : !1;
86
+ }
87
+ break;
88
+ }
89
+ case "boolean": {
90
+ const u = e.compareValue === "true";
91
+ switch (e.compare) {
92
+ case "equals":
93
+ return i.value === u;
94
+ case "notEquals":
95
+ return i.value !== u;
96
+ }
97
+ break;
98
+ }
99
+ case "phone":
100
+ case "string": {
101
+ const u = i.type === "phone" ? Qe(i.value) : i.value;
102
+ switch (e.compare) {
103
+ case "equals":
104
+ return u === e.compareValue;
105
+ case "contains":
106
+ return u ? u.includes(e.compareValue) : !1;
107
+ case "notEquals":
108
+ return u !== e.compareValue;
109
+ case "notContains":
110
+ return u ? !u.includes(e.compareValue) : !0;
111
+ }
112
+ break;
113
+ }
114
+ case "number": {
115
+ try {
116
+ const u = Number(e.compareValue);
117
+ switch (e.compare) {
118
+ case "equals":
119
+ return i.value === u;
120
+ case "notEquals":
121
+ return i.value !== u;
122
+ case "greaterThan":
123
+ return i.value > u;
124
+ case "greaterThanOrEqualTo":
125
+ return i.value >= u;
126
+ case "lessThan":
127
+ return i.value < u;
128
+ case "lessThanOrEqualTo":
129
+ return i.value <= u;
130
+ }
131
+ } catch {
132
+ return console.error(`Failed to parse number in if-block ${n.id}`, i.value), !1;
133
+ }
134
+ break;
135
+ }
136
+ case "enum":
137
+ switch (e.compare) {
138
+ case "equals":
139
+ return i.value.length === 1 && i.value[0] === e.compareValue;
140
+ case "notEquals":
141
+ return i.value.length === 1 && i.value[0] !== e.compareValue;
142
+ case "contains":
143
+ return i.value.includes(e.compareValue);
144
+ case "notContains":
145
+ return !i.value.includes(e.compareValue);
146
+ }
147
+ break;
148
+ }
149
+ }, Fe = (e, {
150
+ context: t,
151
+ submissions: r
152
+ }) => {
153
+ const n = "combinator" in e.data ? e.data.conditions : [e.data];
154
+ if (("combinator" in e.data ? e.data.combinator : "and") === "or") {
155
+ for (const a of n)
156
+ if (Nt({
157
+ condition: a,
158
+ context: t,
159
+ submissions: r,
160
+ ifBlock: e
161
+ }))
162
+ return !0;
163
+ return !1;
164
+ } else {
165
+ for (const a of n)
166
+ if (!Nt({
167
+ condition: a,
168
+ context: t,
169
+ submissions: r,
170
+ ifBlock: e
171
+ }))
172
+ return !1;
173
+ return !0;
174
+ }
175
+ }, Wr = /{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g, ne = (e, {
176
+ context: t,
177
+ submissions: r
178
+ }) => e.replace(Wr, (n, s, a = "") => {
179
+ const [i, ...u] = s.trim().split("."), c = lr({
180
+ key: i,
181
+ path: u,
182
+ submissions: r,
183
+ context: t
184
+ });
185
+ if (!c)
186
+ return a;
187
+ switch (c.type) {
188
+ case "boolean":
189
+ return c.value === !0 ? "true" : "false";
190
+ case "file":
191
+ return c.value.map((h) => `${h.name} (${Le(h.sizeKb)})`).join(", ");
192
+ case "enum":
193
+ return c.value.join(", ");
194
+ case "address":
195
+ return Object.values(c.value).filter((h) => h && h.trim().length > 0).join(", ");
196
+ case "number":
197
+ case "string":
198
+ return c.value ? c.value.toString() : a;
199
+ case "phone":
200
+ return Qe(c.value);
201
+ case "integration": {
202
+ if (typeof c.value != "object" || Array.isArray(c.value))
203
+ break;
204
+ const h = Ue(c.value, u.join("."));
205
+ switch (typeof h) {
206
+ case "boolean":
207
+ return h === !0 ? "true" : "false";
208
+ case "string":
209
+ return h;
210
+ case "number":
211
+ return h.toString();
212
+ case "object":
213
+ if (Array.isArray(h) && h.every(tr))
214
+ return h.join(", ");
215
+ }
216
+ break;
217
+ }
218
+ }
219
+ return a;
220
+ }), or = ({
221
+ node: e,
222
+ nodes: t,
223
+ stopWhen: r
224
+ }) => {
225
+ if ((r == null ? void 0 : r(e)) === !0)
226
+ return e;
227
+ const n = e.nextId ? t.find((s) => s.id === e.nextId) : void 0;
228
+ if (n)
229
+ return or({
230
+ node: n,
231
+ nodes: t,
232
+ stopWhen: r
233
+ });
234
+ }, Jr = ({
235
+ childNode: e,
236
+ nodes: t
237
+ }) => {
238
+ const n = t.filter((s) => s.type === "if-block").find((s) => {
239
+ if (!s.branchId)
240
+ return !1;
241
+ const a = t.find((u) => u.id === s.branchId);
242
+ if (!a)
243
+ return !1;
244
+ const i = or({
245
+ node: a,
246
+ nodes: t,
247
+ stopWhen: (u) => u.id === e.id
248
+ });
249
+ return !(!i || i.id !== e.id);
250
+ });
251
+ if (n != null && n.nextId)
252
+ return t.find((s) => s.id === n.nextId);
253
+ }, Zr = ({
254
+ flow: e,
255
+ analytics: t,
256
+ logger: r,
257
+ context: n,
258
+ apiClient: s,
259
+ getSubmissions: a,
260
+ chatService: i,
261
+ onFlowEnd: u,
262
+ onInterpret: c,
263
+ t: h
264
+ }) => {
265
+ let x = new AbortController();
266
+ const b = {
267
+ ...t.service,
268
+ log: (k) => t.service.log({
269
+ ...k,
270
+ customProperties: {
271
+ ...k.customProperties,
272
+ ...t.customProperties
273
+ }
274
+ })
275
+ }, p = async (k, v) => {
276
+ const E = a();
277
+ c == null || c(k, v);
278
+ try {
279
+ await Qr({
280
+ flow: e,
281
+ analytics: b,
282
+ logger: r,
283
+ apiClient: s,
284
+ context: n,
285
+ node: k,
286
+ submissions: E,
287
+ t: h,
288
+ chat: {
289
+ sendMessage: async (S) => i.send({
290
+ groupId: k.id,
291
+ message: S,
292
+ signal: x.signal
293
+ }),
294
+ userInput: async (S) => i.input({
295
+ input: S,
296
+ signal: x.signal
297
+ }),
298
+ addToSubmissions: i.addToSubmissions
299
+ },
300
+ next: (S) => {
301
+ const A = S ? e.nodes.find((g) => g.id === S) : Jr({
302
+ childNode: k,
303
+ nodes: e.nodes
304
+ });
305
+ return A ? p(A, k) : u == null ? void 0 : u(k);
306
+ },
307
+ end: () => u == null ? void 0 : u(k)
308
+ });
309
+ } catch (S) {
310
+ if (S instanceof Me)
311
+ return;
312
+ throw S;
313
+ }
314
+ };
315
+ return {
316
+ interpret: async (k) => {
317
+ const v = e.nodes.find((E) => E.id === k) ?? rr(e.nodes);
318
+ return p(v);
319
+ },
320
+ undo: (k) => {
321
+ let v = 1;
322
+ const E = e.nodes.find((A) => A.id === k[k.length - 1]);
323
+ for (let A = k.length - 2; A > 0; A--) {
324
+ const g = k[A], T = e.nodes.find((P) => P.id === g);
325
+ if (!T || (v++, T.type.startsWith("question-")))
326
+ break;
327
+ }
328
+ x.abort(), x = new AbortController();
329
+ const S = e.nodes.find((A) => A.id === k[k.length - v]);
330
+ return le(S, "Undo failed: new start node not found"), p(S, E), {
331
+ removed: v
332
+ };
333
+ },
334
+ abort: () => {
335
+ x.abort();
336
+ }
337
+ };
338
+ }, Qe = (e) => `+${e.countryCode} ${e.phoneNumber}`;
339
+ async function Qr(e) {
340
+ const t = e.node;
341
+ switch (t.type) {
342
+ case "text":
343
+ return an({
344
+ ...e,
345
+ node: t
346
+ });
347
+ case "image":
348
+ return on({
349
+ ...e,
350
+ node: t
351
+ });
352
+ case "question-text":
353
+ return ln({
354
+ ...e,
355
+ node: t
356
+ });
357
+ case "question-enum":
358
+ return dn({
359
+ ...e,
360
+ node: t
361
+ });
362
+ case "question-number":
363
+ return un({
364
+ ...e,
365
+ node: t
366
+ });
367
+ case "question-phone":
368
+ return cn({
369
+ ...e,
370
+ node: t
371
+ });
372
+ case "question-boolean":
373
+ return fn({
374
+ ...e,
375
+ node: t
376
+ });
377
+ case "question-file":
378
+ return pn({
379
+ ...e,
380
+ node: t
381
+ });
382
+ case "question-address":
383
+ return hn({
384
+ ...e,
385
+ node: t
386
+ });
387
+ case "end-flow":
388
+ return mn({
389
+ ...e,
390
+ node: t
391
+ });
392
+ case "if-block":
393
+ return sn({
394
+ ...e,
395
+ node: t
396
+ });
397
+ case "jump":
398
+ return en({
399
+ ...e,
400
+ node: t
401
+ });
402
+ case "link":
403
+ return nn({
404
+ ...e,
405
+ node: t
406
+ });
407
+ case "integration-application-submit":
408
+ return rn({
409
+ ...e,
410
+ node: t
411
+ });
412
+ case "add-submission":
413
+ return tn({
414
+ ...e,
415
+ node: t
416
+ });
417
+ case "integration-workflow-get":
418
+ throw Error("Workflow should be unreachable");
419
+ case "identify":
420
+ return Yr({
421
+ ...e,
422
+ node: t
423
+ });
424
+ case "feedback":
425
+ return Xr({
426
+ ...e,
427
+ node: t
428
+ });
429
+ default:
430
+ throw new Error(`Unknown node: ${JSON.stringify(t)}`);
431
+ }
432
+ }
433
+ const Ie = (e, t) => {
434
+ var n;
435
+ const r = (n = e[t]) == null ? void 0 : n.value;
436
+ if (typeof r != "string" && typeof r != "number")
437
+ throw new Error(`Submission at “${t}” is not a string or number`);
438
+ return r;
439
+ };
440
+ async function Xr({
441
+ next: e,
442
+ node: t
443
+ }) {
444
+ e(t.nextId);
445
+ }
446
+ async function Yr({
447
+ next: e,
448
+ node: t,
449
+ analytics: r,
450
+ submissions: n,
451
+ logger: s
452
+ }) {
453
+ if (!n)
454
+ return e(t.nextId);
455
+ try {
456
+ r.log({
457
+ event: "IDENTIFY",
458
+ properties: {
459
+ identifier: Ie(n, t.data.key).toString(),
460
+ first_name: t.data.firstName ? Ie(n, t.data.firstName).toString() : void 0,
461
+ last_name: t.data.lastName ? Ie(n, t.data.lastName).toString() : void 0,
462
+ email: t.data.email ? Ie(n, t.data.email).toString() : void 0,
463
+ phone_number: t.data.phoneNumber ? Ie(n, t.data.phoneNumber).toString() : void 0,
464
+ custom_traits: t.data.customTraits ? Object.fromEntries(t.data.customTraits.map(({
465
+ key: a,
466
+ value: i
467
+ }) => {
468
+ var u;
469
+ return [a, (u = n[i]) == null ? void 0 : u.value];
470
+ })) : void 0
471
+ }
472
+ });
473
+ } catch (a) {
474
+ s.error(a);
475
+ } finally {
476
+ e(t.nextId);
477
+ }
478
+ }
479
+ async function en({
480
+ next: e,
481
+ node: t
482
+ }) {
483
+ e(t.data.targetId);
484
+ }
485
+ async function tn({
486
+ next: e,
487
+ node: t,
488
+ logger: r,
489
+ submissions: n,
490
+ context: s
491
+ }) {
492
+ if (!n) {
493
+ r.error("Submissions not found");
494
+ return;
495
+ }
496
+ n[t.data.key] = {
497
+ type: "string",
498
+ value: ne(t.data.value, {
499
+ submissions: n,
500
+ context: s
501
+ })
502
+ }, e(t.nextId);
503
+ }
504
+ async function rn({
505
+ chat: e,
506
+ next: t,
507
+ node: r,
508
+ logger: n,
509
+ apiClient: s,
510
+ submissions: a,
511
+ analytics: i,
512
+ flow: u,
513
+ t: c
514
+ }) {
515
+ const h = async (x) => {
516
+ x !== !0 && await e.userInput({
517
+ type: "submit",
518
+ key: void 0,
519
+ config: {
520
+ label: r.data.submitLabel
521
+ }
522
+ }), await e.sendMessage({
523
+ type: "loading"
524
+ });
525
+ const {
526
+ anonymous_id: b,
527
+ session_id: p
528
+ } = i.getSessionInfo(), k = await s.fetch("/flow/submit", {
529
+ method: "POST",
530
+ body: JSON.stringify({
531
+ log_submit: !1,
532
+ integration_id: r.data.integrationId,
533
+ anonymous_id: b,
534
+ session_id: p,
535
+ job: u.job,
536
+ submissions: Fr(a || {})
537
+ })
538
+ }).catch((v) => v);
539
+ r.data.key && e.addToSubmissions(r.data.key, {
540
+ type: "integration",
541
+ value: k
542
+ }), Ke(k).with({
543
+ integration_response: I.select(I.union({
544
+ service: I.optional(I.string),
545
+ status: I.number,
546
+ data: I.any
547
+ }, {
548
+ service: I.optional(I.string),
549
+ status: I.number,
550
+ error: {
551
+ message: I.string,
552
+ data: I.any
553
+ }
554
+ }))
555
+ }, (v) => {
556
+ i.log({
557
+ event: "FLOW_SUBMIT",
558
+ properties: {
559
+ flow_id: u.id,
560
+ flow_version: u.version,
561
+ flow_session_id: u.data.flowSessionId,
562
+ flow_build: u.build,
563
+ service: v.service ?? "INVALID_SERVICE",
564
+ response: {
565
+ status: v.status,
566
+ payload: "data" in v ? v.data : v.error.data ?? null
567
+ },
568
+ job: u.job
569
+ }
570
+ });
571
+ }).otherwise(() => {
572
+ }), await Ke(k).with(I.union({
573
+ ats_data: I.select("redirect", {
574
+ redirect_url: I.string,
575
+ message: I.optional(I.union(I.string, I.nullish)),
576
+ button_text: I.optional(I.union(I.string, I.nullish))
577
+ })
578
+ }, {
579
+ integration_response: {
580
+ data: I.select("redirect", {
581
+ redirect_url: I.string,
582
+ message: I.optional(I.union(I.string, I.nullish)),
583
+ button_text: I.optional(I.union(I.string, I.nullish))
584
+ })
585
+ }
586
+ }), async (v) => {
587
+ if (v.redirect !== void 0) {
588
+ await e.sendMessage({
589
+ type: "text",
590
+ author: "bot",
591
+ text: v.redirect.message ?? c("submission_redirect_message")
592
+ });
593
+ try {
594
+ const E = new URL(v.redirect.redirect_url);
595
+ b && !E.searchParams.has("anonymous_id") && E.searchParams.set("anonymous_id", b), await e.sendMessage({
596
+ type: "link",
597
+ href: E.toString(),
598
+ text: v.redirect.button_text ?? c("complete_submission"),
599
+ onClick: () => {
600
+ if (!p) {
601
+ n.error("session_id not set, cannot log FLOW_REDIRECT event");
602
+ return;
603
+ }
604
+ i.log({
605
+ event: "FLOW_REDIRECT",
606
+ properties: {
607
+ flow_build: u.build,
608
+ flow_id: u.id,
609
+ flow_session_id: p,
610
+ flow_version: u.version,
611
+ href: E.toString(),
612
+ job: u.job
613
+ }
614
+ });
615
+ }
616
+ });
617
+ } catch (E) {
618
+ n.error(`Invalid redirect URL: ${v.redirect.redirect_url}`, E), e.sendMessage({
619
+ type: "system",
620
+ variant: "error",
621
+ text: c("redirect_url_error")
622
+ });
623
+ }
624
+ t(r.nextId);
625
+ }
626
+ }).with({
627
+ success: !0
628
+ }, async () => {
629
+ r.data.skipConfirmation !== !0 && await e.sendMessage({
630
+ type: "system",
631
+ variant: "success",
632
+ text: c("submission_completed")
633
+ }), t(r.nextId);
634
+ }).with(I.union({
635
+ success: !1,
636
+ ats_data: I.select("error", {
637
+ message: I.string
638
+ })
639
+ }, {
640
+ integration_response: {
641
+ error: I.select("error", {
642
+ message: I.string
643
+ })
644
+ }
645
+ }), async (v) => {
646
+ var E;
647
+ n.error(v.error), await e.sendMessage({
648
+ type: "system",
649
+ variant: "error",
650
+ text: ((E = v.error) == null ? void 0 : E.message) || c("submission_failed")
651
+ }), await h(!1);
652
+ }).otherwise(async (v) => {
653
+ n.error(v), await e.sendMessage({
654
+ type: "system",
655
+ variant: "error",
656
+ text: c("submission_failed")
657
+ }), await h(!1);
658
+ });
659
+ };
660
+ await h(r.data.skipConfirmation);
661
+ }
662
+ async function nn({
663
+ chat: e,
664
+ next: t,
665
+ node: r,
666
+ submissions: n,
667
+ context: s
668
+ }) {
669
+ await e.sendMessage({
670
+ type: "link",
671
+ href: ne(r.data.href, {
672
+ submissions: n,
673
+ context: s
674
+ }),
675
+ text: ne(r.data.cta, {
676
+ submissions: n,
677
+ context: s
678
+ })
679
+ }), t(r.nextId);
680
+ }
681
+ async function sn({
682
+ submissions: e,
683
+ next: t,
684
+ node: r,
685
+ context: n
686
+ }) {
687
+ t(Fe(r, {
688
+ submissions: e,
689
+ context: n
690
+ }) ? r.branchId : r.nextId);
691
+ }
692
+ async function an({
693
+ chat: e,
694
+ next: t,
695
+ node: r,
696
+ submissions: n,
697
+ context: s
698
+ }) {
699
+ await e.sendMessage({
700
+ author: "bot",
701
+ type: "text",
702
+ text: ne(r.data.text, {
703
+ submissions: n,
704
+ context: s
705
+ })
706
+ }), t(r.nextId);
707
+ }
708
+ async function on({
709
+ chat: e,
710
+ next: t,
711
+ node: r
712
+ }) {
713
+ await e.sendMessage({
714
+ author: "bot",
715
+ type: "image",
716
+ url: r.data.url,
717
+ height: r.data.height,
718
+ width: r.data.width
719
+ }), t(r.nextId);
720
+ }
721
+ async function ln({
722
+ chat: e,
723
+ next: t,
724
+ node: r,
725
+ submissions: n,
726
+ context: s,
727
+ t: a
728
+ }) {
729
+ await e.sendMessage({
730
+ author: "bot",
731
+ type: "text",
732
+ text: ne(r.data.question, {
733
+ submissions: n,
734
+ context: s
735
+ })
736
+ });
737
+ const i = r.data.format === "phone" ? await e.userInput({
738
+ key: r.data.key,
739
+ type: "phone",
740
+ config: {
741
+ optional: r.data.optional,
742
+ placeholder: r.data.placeholder,
743
+ maxChars: r.data.maxChars,
744
+ minChars: r.data.minChars,
745
+ submissionFormat: "text",
746
+ defaultValue: {}
747
+ }
748
+ }) : await e.userInput({
749
+ key: r.data.key,
750
+ type: "text",
751
+ config: {
752
+ optional: r.data.optional,
753
+ placeholder: r.data.placeholder,
754
+ format: r.data.format,
755
+ maxChars: r.data.maxChars,
756
+ minChars: r.data.minChars
757
+ }
758
+ });
759
+ i === null ? await e.sendMessage({
760
+ type: "system",
761
+ variant: "info",
762
+ text: a("skipped")
763
+ }) : await e.sendMessage({
764
+ author: "user",
765
+ type: "text",
766
+ text: i.type === "phone" ? Qe(i.value) : i.value
767
+ }), t(r.nextId);
768
+ }
769
+ async function un({
770
+ chat: e,
771
+ next: t,
772
+ node: r,
773
+ submissions: n,
774
+ context: s,
775
+ t: a
776
+ }) {
777
+ await e.sendMessage({
778
+ author: "bot",
779
+ type: "text",
780
+ text: ne(r.data.question, {
781
+ submissions: n,
782
+ context: s
783
+ })
784
+ });
785
+ const i = await e.userInput({
786
+ key: r.data.key,
787
+ type: "number",
788
+ config: {
789
+ max: r.data.max,
790
+ min: r.data.min,
791
+ optional: r.data.optional,
792
+ placeholder: r.data.placeholder,
793
+ decimalCases: r.data.decimalCases
794
+ }
795
+ });
796
+ i === null ? await e.sendMessage({
797
+ type: "system",
798
+ variant: "info",
799
+ text: a("skipped")
800
+ }) : await e.sendMessage({
801
+ author: "user",
802
+ type: "text",
803
+ text: i.value.toString()
804
+ }), t(r.nextId);
805
+ }
806
+ async function cn({
807
+ chat: e,
808
+ next: t,
809
+ node: r,
810
+ submissions: n,
811
+ context: s
812
+ }) {
813
+ await e.sendMessage({
814
+ author: "bot",
815
+ type: "text",
816
+ text: ne(r.data.question, {
817
+ submissions: n,
818
+ context: s
819
+ })
820
+ });
821
+ const a = await e.userInput({
822
+ key: r.data.key,
823
+ type: "phone",
824
+ config: {
825
+ minChars: r.data.minChars,
826
+ maxChars: r.data.maxChars,
827
+ defaultValue: {
828
+ countryCode: r.data.defaultCountryCode
829
+ },
830
+ placeholder: r.data.placeholder,
831
+ submissionFormat: "phone",
832
+ optional: r.data.optional
833
+ }
834
+ });
835
+ a === null ? await e.sendMessage({
836
+ type: "system",
837
+ variant: "info",
838
+ text: "Skipped"
839
+ }) : await e.sendMessage({
840
+ author: "user",
841
+ type: "text",
842
+ text: a.type === "phone" ? Qe(a.value) : a.value
843
+ }), t(r.nextId);
844
+ }
845
+ async function dn({
846
+ chat: e,
847
+ next: t,
848
+ node: r,
849
+ submissions: n,
850
+ context: s,
851
+ t: a
852
+ }) {
853
+ await e.sendMessage({
854
+ author: "bot",
855
+ type: "text",
856
+ text: ne(r.data.question, {
857
+ submissions: n,
858
+ context: s
859
+ })
860
+ });
861
+ const i = await e.userInput({
862
+ key: r.data.key,
863
+ type: "multiple-choice",
864
+ config: r.data
865
+ });
866
+ i.value.length === 0 ? await e.sendMessage({
867
+ type: "system",
868
+ variant: "info",
869
+ text: a("skipped")
870
+ }) : await e.sendMessage({
871
+ author: "user",
872
+ type: "text",
873
+ text: r.data.options.filter((u) => i.value.includes(u.value)).map((u) => u.label).join(", ")
874
+ }), t(r.nextId);
875
+ }
876
+ async function fn({
877
+ chat: e,
878
+ next: t,
879
+ node: r,
880
+ submissions: n,
881
+ context: s,
882
+ t: a
883
+ }) {
884
+ await e.sendMessage({
885
+ author: "bot",
886
+ type: "text",
887
+ text: ne(r.data.question, {
888
+ submissions: n,
889
+ context: s
890
+ })
891
+ });
892
+ const i = await e.userInput({
893
+ key: r.data.key,
894
+ type: "boolean",
895
+ config: {
896
+ optional: r.data.optional,
897
+ labels: {
898
+ true: r.data.trueLabel,
899
+ false: r.data.falseLabel
900
+ }
901
+ }
902
+ });
903
+ i === null ? await e.sendMessage({
904
+ type: "system",
905
+ variant: "info",
906
+ text: a("skipped")
907
+ }) : await e.sendMessage({
908
+ author: "user",
909
+ type: "text",
910
+ text: i.value === !0 ? r.data.trueLabel : r.data.falseLabel
911
+ }), t(r.nextId);
912
+ }
913
+ async function hn({
914
+ chat: e,
915
+ next: t,
916
+ node: r,
917
+ t: n
918
+ }) {
919
+ await e.sendMessage({
920
+ author: "bot",
921
+ type: "text",
922
+ text: r.data.question
923
+ });
924
+ const s = await e.userInput({
925
+ type: "address",
926
+ key: r.data.key,
927
+ config: {
928
+ optional: r.data.optional,
929
+ keys: r.data.keys,
930
+ placeholder: r.data.placeholder
931
+ }
932
+ });
933
+ if (s === null)
934
+ await e.sendMessage({
935
+ type: "system",
936
+ variant: "info",
937
+ text: n("skipped")
938
+ });
939
+ else {
940
+ const a = Object.values(s.value).filter((i) => i && i.trim().length > 0).join(", ");
941
+ await e.sendMessage({
942
+ author: "user",
943
+ type: "text",
944
+ text: a
945
+ });
946
+ }
947
+ return t(r.nextId);
948
+ }
949
+ async function pn({
950
+ node: e,
951
+ chat: t,
952
+ next: r,
953
+ submissions: n,
954
+ context: s,
955
+ t: a
956
+ }) {
957
+ await t.sendMessage({
958
+ author: "bot",
959
+ type: "text",
960
+ text: ne(e.data.question, {
961
+ submissions: n,
962
+ context: s
963
+ })
964
+ });
965
+ const i = await t.userInput({
966
+ key: e.data.key,
967
+ type: "file",
968
+ config: {
969
+ optional: e.data.optional,
970
+ extensions: e.data.extensions,
971
+ // default value for fileSizeLimitKib is 10MB
972
+ fileSizeLimitKib: e.data.maxSizeKb ?? 10 * 1024,
973
+ allowMultiple: e.data.multiple === !0
974
+ }
975
+ });
976
+ if (i === null)
977
+ await t.sendMessage({
978
+ type: "system",
979
+ variant: "info",
980
+ text: a("skipped")
981
+ });
982
+ else
983
+ for (const u of i.value)
984
+ await t.sendMessage({
985
+ author: "user",
986
+ type: "file",
987
+ fileName: u.name,
988
+ fileSizeKb: u.sizeKb
989
+ });
990
+ r(e.nextId);
991
+ }
992
+ async function mn({
993
+ chat: e,
994
+ end: t,
995
+ node: r
996
+ }) {
997
+ await e.sendMessage({
998
+ type: "system",
999
+ variant: "info",
1000
+ text: r.data.systemMessage
1001
+ }), t();
1002
+ }
1003
+ const lr = ({
1004
+ key: e,
1005
+ path: t,
1006
+ submissions: r,
1007
+ context: n
1008
+ }) => {
1009
+ if (e === "$context") {
1010
+ if (!t)
1011
+ return;
1012
+ const s = Ue(n, t.join("."));
1013
+ switch (typeof s) {
1014
+ case "string":
1015
+ return {
1016
+ type: "string",
1017
+ value: s
1018
+ };
1019
+ case "number":
1020
+ return {
1021
+ type: "number",
1022
+ value: s
1023
+ };
1024
+ case "boolean":
1025
+ return {
1026
+ type: "boolean",
1027
+ value: s
1028
+ };
1029
+ default:
1030
+ console.warn(`Unexpected type for $context.${t.join(".")}`, s);
1031
+ return;
1032
+ }
1033
+ }
1034
+ return r == null ? void 0 : r[e];
1035
+ };
1036
+ function ht(e, t, r) {
1037
+ var n, s, a, i, u;
1038
+ t == null && (t = 100);
1039
+ function c() {
1040
+ var x = Date.now() - i;
1041
+ x < t && x >= 0 ? n = setTimeout(c, t - x) : (n = null, r || (u = e.apply(a, s), a = s = null));
1042
+ }
1043
+ var h = function() {
1044
+ a = this, s = arguments, i = Date.now();
1045
+ var x = r && !n;
1046
+ return n || (n = setTimeout(c, t)), x && (u = e.apply(a, s), a = s = null), u;
1047
+ };
1048
+ return h.clear = function() {
1049
+ n && (clearTimeout(n), n = null);
1050
+ }, h.flush = function() {
1051
+ n && (u = e.apply(a, s), a = s = null, clearTimeout(n), n = null);
1052
+ }, h;
1053
+ }
1054
+ ht.debounce = ht;
1055
+ var gn = ht;
1056
+ const Tt = /* @__PURE__ */ nr(gn);
1057
+ function yn(e) {
1058
+ let {
1059
+ debounce: t,
1060
+ scroll: r,
1061
+ polyfill: n,
1062
+ offsetSize: s
1063
+ } = e === void 0 ? {
1064
+ debounce: 0,
1065
+ scroll: !1,
1066
+ offsetSize: !1
1067
+ } : e;
1068
+ const a = n || (typeof window > "u" ? class {
1069
+ } : window.ResizeObserver);
1070
+ if (!a)
1071
+ throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
1072
+ const [i, u] = Y({
1073
+ left: 0,
1074
+ top: 0,
1075
+ width: 0,
1076
+ height: 0,
1077
+ bottom: 0,
1078
+ right: 0,
1079
+ x: 0,
1080
+ y: 0
1081
+ }), c = re({
1082
+ element: null,
1083
+ scrollContainers: null,
1084
+ resizeObserver: null,
1085
+ lastBounds: i
1086
+ }), h = t ? typeof t == "number" ? t : t.scroll : null, x = t ? typeof t == "number" ? t : t.resize : null, b = re(!1);
1087
+ ue(() => (b.current = !0, () => void (b.current = !1)));
1088
+ const [p, k, v] = mt(() => {
1089
+ const g = () => {
1090
+ if (!c.current.element)
1091
+ return;
1092
+ const {
1093
+ left: T,
1094
+ top: P,
1095
+ width: D,
1096
+ height: me,
1097
+ bottom: ce,
1098
+ right: Ae,
1099
+ x: G,
1100
+ y: se
1101
+ } = c.current.element.getBoundingClientRect(), q = {
1102
+ left: T,
1103
+ top: P,
1104
+ width: D,
1105
+ height: me,
1106
+ bottom: ce,
1107
+ right: Ae,
1108
+ x: G,
1109
+ y: se
1110
+ };
1111
+ c.current.element instanceof HTMLElement && s && (q.height = c.current.element.offsetHeight, q.width = c.current.element.offsetWidth), Object.freeze(q), b.current && !wn(c.current.lastBounds, q) && u(c.current.lastBounds = q);
1112
+ };
1113
+ return [g, x ? Tt(g, x) : g, h ? Tt(g, h) : g];
1114
+ }, [u, s, h, x]);
1115
+ function E() {
1116
+ c.current.scrollContainers && (c.current.scrollContainers.forEach((g) => g.removeEventListener("scroll", v, !0)), c.current.scrollContainers = null), c.current.resizeObserver && (c.current.resizeObserver.disconnect(), c.current.resizeObserver = null);
1117
+ }
1118
+ function S() {
1119
+ c.current.element && (c.current.resizeObserver = new a(v), c.current.resizeObserver.observe(c.current.element), r && c.current.scrollContainers && c.current.scrollContainers.forEach((g) => g.addEventListener("scroll", v, {
1120
+ capture: !0,
1121
+ passive: !0
1122
+ })));
1123
+ }
1124
+ const A = (g) => {
1125
+ !g || g === c.current.element || (E(), c.current.element = g, c.current.scrollContainers = ur(g), S());
1126
+ };
1127
+ return vn(v, !!r), bn(k), ue(() => {
1128
+ E(), S();
1129
+ }, [r, v, k]), ue(() => E, []), [A, i, p];
1130
+ }
1131
+ function bn(e) {
1132
+ ue(() => {
1133
+ const t = e;
1134
+ return window.addEventListener("resize", t), () => void window.removeEventListener("resize", t);
1135
+ }, [e]);
1136
+ }
1137
+ function vn(e, t) {
1138
+ ue(() => {
1139
+ if (t) {
1140
+ const r = e;
1141
+ return window.addEventListener("scroll", r, {
1142
+ capture: !0,
1143
+ passive: !0
1144
+ }), () => void window.removeEventListener("scroll", r, !0);
1145
+ }
1146
+ }, [e, t]);
1147
+ }
1148
+ function ur(e) {
1149
+ const t = [];
1150
+ if (!e || e === document.body)
1151
+ return t;
1152
+ const {
1153
+ overflow: r,
1154
+ overflowX: n,
1155
+ overflowY: s
1156
+ } = window.getComputedStyle(e);
1157
+ return [r, n, s].some((a) => a === "auto" || a === "scroll") && t.push(e), [...t, ...ur(e.parentElement)];
1158
+ }
1159
+ const xn = ["x", "y", "top", "bottom", "left", "right", "width", "height"], wn = (e, t) => xn.every((r) => e[r] === t[r]), be = ({
1160
+ class: e,
1161
+ ...t
1162
+ }) => {
1163
+ const {
1164
+ t: r
1165
+ } = Z();
1166
+ return l("button", {
1167
+ class: Ne("bg-accent-9 active:bg-accent-10 pointer-coarse:touch-hitbox fr flex-shrink-0 rounded-full p-2 text-white transition-all disabled:cursor-not-allowed disabled:opacity-50", e),
1168
+ type: "submit",
1169
+ ...t,
1170
+ children: l("svg", {
1171
+ class: "block",
1172
+ width: "16",
1173
+ height: "16",
1174
+ viewBox: "0 0 16 16",
1175
+ fill: "transparent",
1176
+ stroke: "currentColor",
1177
+ "stroke-linecap": "round",
1178
+ "stroke-width": "2",
1179
+ children: [l("title", {
1180
+ children: r("send")
1181
+ }), l("path", {
1182
+ d: "M3.5 7.5L8 3L12.5 7.5"
1183
+ }), l("path", {
1184
+ d: "M8 4V13"
1185
+ })]
1186
+ })
1187
+ });
1188
+ }, kn = 25, pt = ft({
1189
+ instant: () => {
1190
+ },
1191
+ smooth: () => {
1192
+ }
1193
+ }), z = {
1194
+ onSubmitSuccessFn$: ft(() => {
1195
+ }),
1196
+ isBotTyping$: ft(!1),
1197
+ scrollToEnd: {
1198
+ instant: () => pt.value.instant(),
1199
+ smooth: () => pt.value.smooth()
1200
+ }
1201
+ }, _n = () => {
1202
+ const e = re(null);
1203
+ pe(() => {
1204
+ pt.value = {
1205
+ instant: () => {
1206
+ var r;
1207
+ return (r = e.current) == null ? void 0 : r.scrollTo({
1208
+ top: e.current.scrollHeight,
1209
+ behavior: "instant"
1210
+ });
1211
+ },
1212
+ smooth: () => {
1213
+ e.current && e.current.scrollHeight - e.current.scrollTop <= e.current.clientHeight * 2 && e.current.scrollTo({
1214
+ top: e.current.scrollHeight,
1215
+ behavior: "smooth"
1216
+ });
1217
+ }
1218
+ };
1219
+ }, [e]);
1220
+ const t = mt(() => ({
1221
+ addToSubmissions: (n, s) => M.setSubmission(n, s),
1222
+ send: async ({
1223
+ message: n,
1224
+ signal: s,
1225
+ groupId: a
1226
+ }) => {
1227
+ if (await Ke(n).with({
1228
+ author: "bot",
1229
+ type: "text"
1230
+ }, async (i) => {
1231
+ if (s != null && s.aborted)
1232
+ throw new Me();
1233
+ z.isBotTyping$.value = !0;
1234
+ const u = Math.min(Math.max(20, i.text.length), 100) * kn;
1235
+ await new Promise((c) => setTimeout(c, u, {
1236
+ signal: s
1237
+ })), z.isBotTyping$.value = !1;
1238
+ }).otherwise(async () => {
1239
+ }), s != null && s.aborted)
1240
+ throw new Me();
1241
+ M.addMessage(n, a);
1242
+ },
1243
+ input: ({
1244
+ input: n,
1245
+ signal: s
1246
+ }) => {
1247
+ if (s != null && s.aborted)
1248
+ throw new Me();
1249
+ return M.setInput(n), new Promise((a) => {
1250
+ const i = (u) => {
1251
+ if (s != null && s.aborted)
1252
+ throw new Me();
1253
+ M.setInput(void 0), n.key && M.setSubmission(n.key, u), a(u);
1254
+ };
1255
+ z.onSubmitSuccessFn$.value = i;
1256
+ });
1257
+ }
1258
+ }), []);
1259
+ return {
1260
+ chatRef: e,
1261
+ chatService: t
1262
+ };
1263
+ }, Ce = ({
1264
+ error: e
1265
+ }) => !e || !e.message ? null : l("div", {
1266
+ role: "alert",
1267
+ class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full px-2 py-2",
1268
+ children: [l("svg", {
1269
+ class: "text-error-9 h-4 w-4",
1270
+ viewBox: "0 0 16 16",
1271
+ fill: "none",
1272
+ xmlns: "http://www.w3.org/2000/svg",
1273
+ children: [l("circle", {
1274
+ cx: "8",
1275
+ cy: "8",
1276
+ r: "6.3",
1277
+ stroke: "currentColor",
1278
+ "stroke-width": "1.4"
1279
+ }), l("rect", {
1280
+ x: "7",
1281
+ y: "4",
1282
+ width: "2",
1283
+ height: "5",
1284
+ fill: "currentColor"
1285
+ }), l("rect", {
1286
+ x: "7",
1287
+ y: "10",
1288
+ width: "2",
1289
+ height: "2",
1290
+ fill: "currentColor"
1291
+ })]
1292
+ }), l("p", {
1293
+ class: "truncate pr-1 text-sm",
1294
+ children: e.message
1295
+ })]
1296
+ }), ve = ({
1297
+ class: e,
1298
+ ...t
1299
+ }) => {
1300
+ const {
1301
+ t: r
1302
+ } = Z();
1303
+ return l("button", {
1304
+ type: "button",
1305
+ class: Ne("fr text-neutral-9 flex flex-shrink-0 items-center justify-center gap-1 rounded-full py-[6px] pl-2 pr-3 text-sm underline-offset-2 transition-all", e),
1306
+ ...t,
1307
+ children: [l("svg", {
1308
+ "aria-hidden": !0,
1309
+ class: "block",
1310
+ width: "16",
1311
+ height: "16",
1312
+ viewBox: "0 0 16 16",
1313
+ fill: "transparent",
1314
+ stroke: "currentColor",
1315
+ "stroke-linecap": "round",
1316
+ "stroke-width": "1.5",
1317
+ children: [l("title", {
1318
+ children: r("skip")
1319
+ }), l("path", {
1320
+ d: "M3.25 11.25A5 5 0 0 1 12 7"
1321
+ }), l("path", {
1322
+ d: "M13.25 4.5V8.25H9.5"
1323
+ })]
1324
+ }), r("skip")]
1325
+ });
1326
+ }, gt = {
1327
+ Afghanistan: "93",
1328
+ Albania: "355",
1329
+ Algeria: "213",
1330
+ "American Samoa": "1 684",
1331
+ Andorra: "376",
1332
+ Angola: "244",
1333
+ Anguilla: "1 264",
1334
+ Antarctica: "672",
1335
+ "Antigua and Barbuda": "1 268",
1336
+ Argentina: "54",
1337
+ Armenia: "374",
1338
+ Aruba: "297",
1339
+ Australia: "61",
1340
+ Austria: "43",
1341
+ Azerbaijan: "994",
1342
+ Bahrain: "973",
1343
+ Bangladesh: "880",
1344
+ Barbados: "1 246",
1345
+ Belarus: "375",
1346
+ Belgium: "32",
1347
+ Belize: "501",
1348
+ Benin: "229",
1349
+ Bermuda: "1 441",
1350
+ Bhutan: "975",
1351
+ Bolivia: "591",
1352
+ "Bosnia and Herzegovina": "387",
1353
+ Botswana: "267",
1354
+ "Bouvet Island": "47",
1355
+ Brazil: "55",
1356
+ "British Indian Ocean Territory": "246",
1357
+ "British Virgin Islands": "1 284",
1358
+ Brunei: "673",
1359
+ Bulgaria: "359",
1360
+ "Burkina Faso": "226",
1361
+ Burundi: "257",
1362
+ "Cabo Verde": "238",
1363
+ Cambodia: "855",
1364
+ Cameroon: "237",
1365
+ Canada: "1",
1366
+ "Caribbean Netherlands": "599",
1367
+ "Cayman Islands": "1 345",
1368
+ "Central African Republic": "236",
1369
+ Chad: "235",
1370
+ Chile: "56",
1371
+ China: "86",
1372
+ "Christmas Island": "61",
1373
+ "Cocos (Keeling) Islands": "61",
1374
+ Colombia: "57",
1375
+ Comoros: "269",
1376
+ "Cook Islands": "682",
1377
+ "Costa Rica": "506",
1378
+ Croatia: "385",
1379
+ Cuba: "53",
1380
+ Curaçao: "599",
1381
+ Cyprus: "357",
1382
+ Czechia: "420",
1383
+ "Côte d'Ivoire": "225",
1384
+ "Democratic Republic of the Congo": "243",
1385
+ Denmark: "45",
1386
+ Djibouti: "253",
1387
+ "Dominican Republic": "1 809",
1388
+ Ecuador: "593",
1389
+ Egypt: "20",
1390
+ "El Salvador": "503",
1391
+ "Equatorial Guinea": "240",
1392
+ Eritrea: "291",
1393
+ Estonia: "372",
1394
+ Eswatini: "268",
1395
+ Ethiopia: "251",
1396
+ "Falkland Islands (Islas Malvinas)": "500",
1397
+ "Faroe Islands": "298",
1398
+ Fiji: "679",
1399
+ Finland: "358",
1400
+ France: "33",
1401
+ "French Guiana": "594",
1402
+ "French Polynesia": "689",
1403
+ "French Southern and Antarctic Lands": "262",
1404
+ Gabon: "241",
1405
+ Georgia: "995",
1406
+ Germany: "49",
1407
+ Ghana: "233",
1408
+ Gibraltar: "350",
1409
+ Greece: "30",
1410
+ Greenland: "299",
1411
+ Grenada: "1 473",
1412
+ Guadeloupe: "590",
1413
+ Guam: "1 671",
1414
+ Guatemala: "502",
1415
+ Guernsey: "44",
1416
+ Guinea: "224",
1417
+ "Guinea-Bissau": "245",
1418
+ Guyana: "592",
1419
+ Haiti: "509",
1420
+ Honduras: "504",
1421
+ "Hong Kong": "852",
1422
+ Hungary: "36",
1423
+ Iceland: "354",
1424
+ India: "91",
1425
+ Indonesia: "62",
1426
+ Iran: "98",
1427
+ Iraq: "964",
1428
+ Ireland: "353",
1429
+ "Isle of Man": "44",
1430
+ Israel: "972",
1431
+ Italy: "39",
1432
+ Jamaica: "1 876",
1433
+ Japan: "81",
1434
+ Jersey: "44",
1435
+ Jordan: "962",
1436
+ Kazakhstan: "7",
1437
+ Kenya: "254",
1438
+ Kiribati: "686",
1439
+ Kosovo: "383",
1440
+ Kuwait: "965",
1441
+ Kyrgyzstan: "996",
1442
+ Laos: "856",
1443
+ Latvia: "371",
1444
+ Lebanon: "961",
1445
+ Lesotho: "266",
1446
+ Liberia: "231",
1447
+ Libya: "218",
1448
+ Liechtenstein: "423",
1449
+ Lithuania: "370",
1450
+ Luxembourg: "352",
1451
+ Macao: "853",
1452
+ Madagascar: "261",
1453
+ Malawi: "265",
1454
+ Malaysia: "60",
1455
+ Maldives: "960",
1456
+ Mali: "223",
1457
+ Malta: "356",
1458
+ "Marshall Islands": "692",
1459
+ Martinique: "596",
1460
+ Mauritania: "222",
1461
+ Mauritius: "230",
1462
+ Mayotte: "262",
1463
+ Mexico: "52",
1464
+ Micronesia: "691",
1465
+ Moldova: "373",
1466
+ Monaco: "377",
1467
+ Mongolia: "976",
1468
+ Montenegro: "382",
1469
+ Montserrat: "1 664",
1470
+ Morocco: "212",
1471
+ Mozambique: "258",
1472
+ "Myanmar (Burma)": "95",
1473
+ Namibia: "264",
1474
+ Nauru: "674",
1475
+ Nepal: "977",
1476
+ Netherlands: "31",
1477
+ "New Caledonia": "687",
1478
+ "New Zealand": "64",
1479
+ Nicaragua: "505",
1480
+ Niger: "227",
1481
+ Nigeria: "234",
1482
+ Niue: "683",
1483
+ "Norfolk Island": "672",
1484
+ "North Korea": "850",
1485
+ "North Macedonia": "389",
1486
+ "Northern Mariana Islands": "1 670",
1487
+ Norway: "47",
1488
+ Oman: "968",
1489
+ Pakistan: "92",
1490
+ Palau: "680",
1491
+ Palestine: "970",
1492
+ Panama: "507",
1493
+ "Papua New Guinea": "675",
1494
+ Paraguay: "595",
1495
+ Peru: "51",
1496
+ Philippines: "63",
1497
+ "Pitcairn Islands": "64",
1498
+ Poland: "48",
1499
+ Portugal: "351",
1500
+ "Puerto Rico": "1 787",
1501
+ Qatar: "974",
1502
+ Romania: "40",
1503
+ Russia: "7",
1504
+ Rwanda: "250",
1505
+ Réunion: "262",
1506
+ "Saint Barthélemy": "590",
1507
+ "Saint Helena, Ascension and Tristan da Cunha": "290",
1508
+ "Saint Kitts and Nevis": "1 869",
1509
+ "Saint Lucia": "1 758",
1510
+ "Saint Martin": "590",
1511
+ "Saint Pierre and Miquelon": "508",
1512
+ "Saint Vincent and the Grenadines": "1 784",
1513
+ Samoa: "685",
1514
+ "San Marino": "378",
1515
+ "Saudi Arabia": "966",
1516
+ Senegal: "221",
1517
+ Serbia: "381",
1518
+ Seychelles: "248",
1519
+ "Sierra Leone": "232",
1520
+ Singapore: "65",
1521
+ "Sint Maarten": "1 721",
1522
+ Slovakia: "421",
1523
+ Slovenia: "386",
1524
+ "Solomon Islands": "677",
1525
+ Somalia: "252",
1526
+ "South Africa": "27",
1527
+ "South Georgia and the South Sandwich Islands": "500",
1528
+ "South Korea": "82",
1529
+ "South Sudan": "211",
1530
+ Spain: "34",
1531
+ "Sri Lanka": "94",
1532
+ Sudan: "249",
1533
+ Suriname: "597",
1534
+ "Svalbard and Jan Mayen": "47",
1535
+ Sweden: "46",
1536
+ Switzerland: "41",
1537
+ Syria: "963",
1538
+ "São Tomé and Príncipe": "239",
1539
+ Taiwan: "886",
1540
+ Tajikistan: "992",
1541
+ Tanzania: "255",
1542
+ Thailand: "66",
1543
+ "The Bahamas": "1 242",
1544
+ "The Gambia": "220",
1545
+ "Timor-Leste": "670",
1546
+ Togo: "228",
1547
+ Tokelau: "690",
1548
+ Tonga: "676",
1549
+ "Trinidad and Tobago": "1 868",
1550
+ Tunisia: "216",
1551
+ Turkmenistan: "993",
1552
+ "Turks and Caicos Islands": "1 649",
1553
+ Tuvalu: "688",
1554
+ Türkiye: "90",
1555
+ "U.S. Virgin Islands": "1 340",
1556
+ Uganda: "256",
1557
+ Ukraine: "380",
1558
+ "United Arab Emirates": "971",
1559
+ "United Kingdom": "44",
1560
+ "United States": "1",
1561
+ "United States Minor Outlying Islands": "1",
1562
+ Uruguay: "598",
1563
+ Uzbekistan: "998",
1564
+ Vanuatu: "678",
1565
+ "Vatican City": "379",
1566
+ Venezuela: "58",
1567
+ Vietnam: "84",
1568
+ "Wallis and Futuna": "681",
1569
+ "Western Sahara": "212",
1570
+ Yemen: "967",
1571
+ Zambia: "260",
1572
+ Zimbabwe: "263",
1573
+ "Åland Islands": "358"
1574
+ }, Te = Ze("outline-divider ease-expo-out placeholder:text-neutral-10 text-neutral-12 focus-visible:outline-accent-7 caret-accent-9 bg-lowest py-1 text-base outline outline-2 transition-all", {
1575
+ variants: {
1576
+ optional: {
1577
+ true: "pr-16 pl-3",
1578
+ false: "pl-3 pr-3"
1579
+ }
1580
+ },
1581
+ defaultVariants: {
1582
+ optional: !1
1583
+ }
1584
+ }), Sn = "https://api.mapbox.com/search/searchbox/v1/suggest", Cn = "ZzRDWFU0dTZ3SF9aWk9RNGl6QzZaWS5RZmlFak13a0hPbGxXZXlNSGN5RUhObUJ6TXpSV08yUW5OdE5tSTZJU1lpd2lJb1JYYXRObmJ2Tm5iaGhHZWx4V1lpb2pJMUp5ZS5rcA==", An = (e) => atob(e).split("").reverse().join(""), ae = he({
1585
+ name: ee()
1586
+ }), En = he({
1587
+ suggestions: Lr(he({
1588
+ full_address: at(ee()),
1589
+ place_formatted: at(ee()),
1590
+ name: at(ee()),
1591
+ mapbox_id: ee(),
1592
+ context: Nr(he({
1593
+ address: ae,
1594
+ street: ae,
1595
+ neighborhood: ae,
1596
+ locality: ae,
1597
+ district: ae,
1598
+ place: ae,
1599
+ region: ae,
1600
+ postcode: ae,
1601
+ country: ae
1602
+ }))
1603
+ }))
1604
+ }), In = ({
1605
+ logger: e,
1606
+ t
1607
+ }) => mt(() => {
1608
+ var n;
1609
+ const r = (n = M.current$.peek().flow) == null ? void 0 : n.data.flowSessionId;
1610
+ return r ? {
1611
+ enabled: !0,
1612
+ getPredictions: async (s) => {
1613
+ const a = new URL(Sn);
1614
+ a.searchParams.set("q", s), a.searchParams.set("session_token", r), a.searchParams.set("access_token", An(Cn));
1615
+ const i = await fetch(a);
1616
+ if (!i.ok)
1617
+ return e.error("Failed to get address details", i), {
1618
+ ok: !1,
1619
+ error: t("address_error")
1620
+ };
1621
+ const u = Tr(En, await i.json());
1622
+ if (u.success === !1)
1623
+ return e.error("Failed to parse address details", u.issues), {
1624
+ ok: !1,
1625
+ error: t("address_error")
1626
+ };
1627
+ const {
1628
+ suggestions: c
1629
+ } = u.output;
1630
+ return {
1631
+ ok: !0,
1632
+ data: c.map((h) => {
1633
+ var x, b, p, k, v, E, S, A, g;
1634
+ return {
1635
+ label: h.full_address ?? h.place_formatted ?? h.name ?? h.mapbox_id,
1636
+ id: h.mapbox_id,
1637
+ address: {
1638
+ line1: ((x = h.context.address) == null ? void 0 : x.name) ?? ((b = h.context.street) == null ? void 0 : b.name),
1639
+ line2: void 0,
1640
+ line3: ((p = h.context.neighborhood) == null ? void 0 : p.name) ?? ((k = h.context.locality) == null ? void 0 : k.name),
1641
+ city: ((v = h.context.place) == null ? void 0 : v.name) ?? ((E = h.context.district) == null ? void 0 : E.name),
1642
+ state: (S = h.context.region) == null ? void 0 : S.name,
1643
+ postcode: (A = h.context.postcode) == null ? void 0 : A.name,
1644
+ country: (g = h.context.country) == null ? void 0 : g.name
1645
+ }
1646
+ };
1647
+ })
1648
+ };
1649
+ }
1650
+ } : {
1651
+ enabled: !1
1652
+ };
1653
+ }, [e, t]), Dt = (e) => {
1654
+ const {
1655
+ t
1656
+ } = Z();
1657
+ return l("button", {
1658
+ type: "button",
1659
+ class: "text-neutral-10 hover:bg-neutral-4 hover:text-neutral-12 hover:border-neutral-5 flex items-center gap-1 rounded-[18px] border border-solid border-transparent px-3 py-1 pl-1.5 text-sm transition-colors",
1660
+ ...e,
1661
+ children: [l("svg", {
1662
+ width: "16",
1663
+ height: "16",
1664
+ viewBox: "0 0 16 16",
1665
+ stroke: "currentColor",
1666
+ "stroke-width": "1.5",
1667
+ fill: "none",
1668
+ xmlns: "http://www.w3.org/2000/svg",
1669
+ children: l("path", {
1670
+ d: "M10 3L5 8L10 13"
1671
+ })
1672
+ }), l("span", {
1673
+ children: t("back")
1674
+ })]
1675
+ });
1676
+ }, Vn = ({
1677
+ input: e,
1678
+ onSubmitSuccess: t,
1679
+ logger: r
1680
+ }) => {
1681
+ const {
1682
+ t: n
1683
+ } = Z(), [s, a] = Y(), [i, u] = Y([]), {
1684
+ enabled: c,
1685
+ getPredictions: h
1686
+ } = In({
1687
+ logger: r,
1688
+ t: n
1689
+ }), [x, b] = Y(c ? "query" : "manual"), [p, k] = Y(""), [v, E] = Y(), S = (A) => {
1690
+ le(c, "Query state should not be enabled"), A = A.trim(), A !== (p == null ? void 0 : p.trim()) && (k(A), A === "" && u([]), E(void 0), h(A).then((g) => {
1691
+ if (g.ok === !1) {
1692
+ u([]), E(g.error);
1693
+ return;
1694
+ }
1695
+ u(g.data);
1696
+ }));
1697
+ };
1698
+ switch (x) {
1699
+ case "query":
1700
+ return le(c, "Query state should not be enabled"), l(Mn, {
1701
+ input: e,
1702
+ onSkip: () => t(null),
1703
+ onAddressSelect: (A) => {
1704
+ if (A === "") {
1705
+ a(void 0), b("manual");
1706
+ return;
1707
+ }
1708
+ const g = i.find((T) => T.id === A);
1709
+ g && (a(g.address), b("details"));
1710
+ },
1711
+ onAddressSearch: (A) => {
1712
+ S(A);
1713
+ },
1714
+ suggestions: i,
1715
+ query: p,
1716
+ error: v
1717
+ });
1718
+ case "details":
1719
+ return le(s !== void 0), l(Ot, {
1720
+ input: e,
1721
+ logger: r,
1722
+ onSubmitSuccess: t,
1723
+ addressFields: s,
1724
+ actions: l(Dt, {
1725
+ onClick: () => {
1726
+ b("query");
1727
+ }
1728
+ })
1729
+ });
1730
+ case "manual":
1731
+ return l(Ot, {
1732
+ logger: r,
1733
+ input: e,
1734
+ onSubmitSuccess: t,
1735
+ addressFields: {},
1736
+ actions: c ? l(Dt, {
1737
+ onClick: () => {
1738
+ b("query");
1739
+ }
1740
+ }) : void 0
1741
+ });
1742
+ }
1743
+ }, Mn = ({
1744
+ input: e,
1745
+ onSkip: t,
1746
+ suggestions: r,
1747
+ onAddressSelect: n,
1748
+ query: s,
1749
+ onAddressSearch: a,
1750
+ error: i
1751
+ }) => {
1752
+ const {
1753
+ t: u
1754
+ } = Z(), c = re(null);
1755
+ return pe(() => {
1756
+ c.current && (c.current.focus(), c.current.select());
1757
+ }, []), l(_e, {
1758
+ children: [l("form", {
1759
+ noValidate: !0,
1760
+ onSubmit: (h) => {
1761
+ h.preventDefault();
1762
+ const b = new FormData(h.currentTarget).get("address");
1763
+ typeof b == "string" && a(b);
1764
+ },
1765
+ class: "flex gap-1 p-2.5",
1766
+ children: [l("div", {
1767
+ class: "group relative flex-1",
1768
+ children: [l("input", {
1769
+ ref: c,
1770
+ name: "address",
1771
+ id: "chat-address",
1772
+ autocomplete: "address-line1 country-name postal-code",
1773
+ autoFocus: !0,
1774
+ placeholder: e.config.placeholder || u("address_search"),
1775
+ defaultValue: s,
1776
+ class: Te({
1777
+ optional: !!e.config.optional,
1778
+ className: "w-full rounded-full"
1779
+ })
1780
+ }), l("button", {
1781
+ type: "submit",
1782
+ class: "touch-hitbox text-neutral-12 hover:bg-neutral-3 fr absolute bottom-0 right-0 top-0 flex cursor-pointer items-center gap-1 rounded-full px-3 transition-all",
1783
+ children: l("svg", {
1784
+ width: "16",
1785
+ height: "16",
1786
+ viewBox: "0 0 16 16",
1787
+ fill: "none",
1788
+ xmlns: "http://www.w3.org/2000/svg",
1789
+ children: [l("g", {
1790
+ id: "inploi",
1791
+ stroke: "currentColor",
1792
+ "stroke-linecap": "round",
1793
+ "stroke-linejoin": "round",
1794
+ strokeWidth: "1.5",
1795
+ children: [l("circle", {
1796
+ cx: "7",
1797
+ cy: "7",
1798
+ r: "4"
1799
+ }), l("path", {
1800
+ d: "M10 10L13 13"
1801
+ })]
1802
+ }), l("span", {
1803
+ class: "sr-only",
1804
+ children: u("search")
1805
+ })]
1806
+ })
1807
+ })]
1808
+ }), e.config.optional && l(ve, {
1809
+ class: "",
1810
+ onClick: t
1811
+ })]
1812
+ }), i ? l(Ce, {
1813
+ error: {
1814
+ message: i
1815
+ }
1816
+ }) : null, l("ul", {
1817
+ children: [r.map((h) => l("li", {
1818
+ children: l("button", {
1819
+ class: "text-neutral-11 fr hover:bg-neutral-3 focus-visible:bg-neutral-3 hover:text-neutral-12 border-b-neutral-3 flex w-full items-center border border-b border-solid border-transparent px-4 py-3 text-sm transition-colors duration-100",
1820
+ onClick: () => {
1821
+ n(h.id);
1822
+ },
1823
+ children: [l("span", {
1824
+ class: "flex-grow",
1825
+ children: h.label
1826
+ }), l("svg", {
1827
+ class: "flex-none",
1828
+ width: "16",
1829
+ height: "16",
1830
+ viewBox: "0 0 16 16",
1831
+ stroke: "currentColor",
1832
+ "stroke-width": "1.5",
1833
+ fill: "none",
1834
+ xmlns: "http://www.w3.org/2000/svg",
1835
+ children: l("path", {
1836
+ d: "M6 3L11 8L6 13"
1837
+ })
1838
+ })]
1839
+ })
1840
+ }, h.id)), l("li", {
1841
+ children: l("button", {
1842
+ class: "text-neutral-11 fr hover:bg-neutral-3 focus-visible:bg-neutral-3 hover:text-neutral-12 border-b-neutral-3 flex w-full items-center border border-b border-solid border-transparent px-4 py-3 text-sm transition-colors duration-100",
1843
+ onClick: () => {
1844
+ n("");
1845
+ },
1846
+ children: l("span", {
1847
+ class: "flex-grow",
1848
+ children: u("address_manual")
1849
+ })
1850
+ })
1851
+ }, "")]
1852
+ })]
1853
+ });
1854
+ }, Fn = {
1855
+ line1: "Line 1",
1856
+ line2: "Line 2",
1857
+ line3: "Line 3",
1858
+ city: "City",
1859
+ state: "State",
1860
+ postcode: "Postcode",
1861
+ country: "Country"
1862
+ }, Rt = ["line1", "line2", "line3", "city", "state", "postcode", "country"], Ot = ({
1863
+ addressFields: e,
1864
+ onSubmitSuccess: t,
1865
+ actions: r,
1866
+ input: n
1867
+ }) => {
1868
+ const s = re(null);
1869
+ pe(() => {
1870
+ if (s.current) {
1871
+ const i = s.current.querySelector("input");
1872
+ i && (i.focus(), i.select());
1873
+ }
1874
+ }, []);
1875
+ const a = Object.keys(gt);
1876
+ return l("form", {
1877
+ class: "bg-neutral-1/90 flex flex-col justify-end gap-2 p-2",
1878
+ onSubmit: (i) => {
1879
+ const u = new FormData(i.currentTarget), c = Object.fromEntries(u.entries());
1880
+ t({
1881
+ type: "address",
1882
+ value: c
1883
+ });
1884
+ },
1885
+ children: [l("div", {
1886
+ class: "bg-neutral-3 border-neutral-5 grid items-center gap-1.5 rounded-2xl border pb-2 pl-4 pr-3 pt-3 [grid-template-columns:min-content_1fr]",
1887
+ ref: s,
1888
+ children: Rt.map((i, u) => {
1889
+ const c = `isdk_${i}`, h = n.config.keys[i];
1890
+ return h ? l(_e, {
1891
+ children: [l("label", {
1892
+ for: c,
1893
+ class: "text-neutral-9 [&:has(+*>input:focus)]:text-neutral-11 w-24 pb-2 text-xs uppercase leading-3 tracking-widest transition-colors",
1894
+ children: Fn[i]
1895
+ }), l("div", {
1896
+ class: "flex flex-col items-stretch gap-1.5",
1897
+ children: [i === "country" ? l("div", {
1898
+ class: "relative",
1899
+ children: [l("select", {
1900
+ class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus:bg-neutral-5 w-full flex-1 appearance-none rounded-lg border-solid bg-transparent bg-none px-3 py-1.5 text-base transition-colors focus:outline-none",
1901
+ name: h,
1902
+ id: c,
1903
+ defaultValue: e[i],
1904
+ required: !0,
1905
+ children: [e.country && !a.includes(e.country) ? l("option", {
1906
+ value: e[i],
1907
+ children: e[i]
1908
+ }) : l("option", {
1909
+ value: "",
1910
+ children: "Select a country"
1911
+ }), a.map((x) => l("option", {
1912
+ value: x,
1913
+ children: x
1914
+ }, x))]
1915
+ }), l("svg", {
1916
+ class: "text-neutral-12 absolute bottom-2.5 right-2 flex items-center justify-center",
1917
+ width: "16",
1918
+ height: "16",
1919
+ stroke: "currentColor",
1920
+ "stroke-width": "1.5",
1921
+ "stroke-linecap": "round",
1922
+ "stroke-linejoin": "round",
1923
+ viewBox: "0 0 16 16",
1924
+ fill: "none",
1925
+ xmlns: "http://www.w3.org/2000/svg",
1926
+ children: l("path", {
1927
+ d: "M4 6.5L8 10.5L12 6.5"
1928
+ })
1929
+ })]
1930
+ }) : l("input", {
1931
+ autoFocus: u === 0 ? !0 : void 0,
1932
+ class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus:bg-neutral-5 flex-1 rounded-lg border-solid bg-transparent px-3 py-1.5 text-base transition-colors autofill:shadow-[inset_0_0_0_1000px_hsl(210_16.7%_97.6%)] focus:outline-none",
1933
+ name: h,
1934
+ id: c,
1935
+ defaultValue: e[i],
1936
+ required: !0
1937
+ }), u === Rt.length - 1 ? l("hr", {
1938
+ class: "m-0 w-full border-b border-b-transparent"
1939
+ }) : l("hr", {
1940
+ class: "border-b-neutral-5 m-0 w-full border-b border-solid"
1941
+ })]
1942
+ })]
1943
+ }) : null;
1944
+ })
1945
+ }), l("div", {
1946
+ class: "flex w-full flex-1 ",
1947
+ children: [l("div", {
1948
+ class: "flex-grow",
1949
+ children: r
1950
+ }), l(be, {
1951
+ class: "flex items-center justify-center"
1952
+ })]
1953
+ })]
1954
+ });
1955
+ }, yt = () => {
1956
+ const e = re(null);
1957
+ return ue(() => {
1958
+ var t;
1959
+ (t = e.current) == null || t.focus();
1960
+ }, []), e;
1961
+ }, cr = ["true", "false"], Ln = Rr(cr), Nn = "answer", dr = "flex items-center gap-2 p-2.5", fr = sr(({
1962
+ label: e,
1963
+ ...t
1964
+ }, r) => l("button", {
1965
+ class: "bg-lowest ease-expo-out ring-divider text-neutral-12 active:ring-accent-7 active:bg-accent-2 active:text-accent-11 fr block w-full overflow-hidden rounded-2xl px-2.5 py-2.5 ring-2 transition-all selection:bg-transparent",
1966
+ ...t,
1967
+ ref: r,
1968
+ children: l("p", {
1969
+ class: "truncate text-center text-base",
1970
+ children: e
1971
+ })
1972
+ })), Tn = ({
1973
+ input: e,
1974
+ onSubmitSuccess: t
1975
+ }) => {
1976
+ const r = yt();
1977
+ return l("form", {
1978
+ noValidate: !0,
1979
+ class: "",
1980
+ onSubmit: (n) => {
1981
+ n.preventDefault();
1982
+ const s = Dr(n).value, a = ar(Ln, s);
1983
+ t({
1984
+ type: "boolean",
1985
+ value: a === "true"
1986
+ });
1987
+ },
1988
+ children: [l("ul", {
1989
+ class: dr,
1990
+ children: cr.map((n, s) => l("li", {
1991
+ class: "flex-1",
1992
+ children: l(fr, {
1993
+ ref: s === 0 ? r : null,
1994
+ type: "submit",
1995
+ name: Nn,
1996
+ value: n,
1997
+ label: e.config.labels[n]
1998
+ }, n)
1999
+ }))
2000
+ }), e.config.optional && l("div", {
2001
+ class: "px-2 pb-2",
2002
+ children: l(ve, {
2003
+ class: "w-full",
2004
+ type: "button",
2005
+ onClick: () => t(null)
2006
+ })
2007
+ })]
2008
+ });
2009
+ }, Dn = (e) => new Promise((t, r) => {
2010
+ const n = new FileReader();
2011
+ n.readAsDataURL(e), n.onload = () => n.result ? t(n.result.toString()) : r("No result from reader"), n.onerror = r;
2012
+ }), Rn = (e) => e.reduce((t, r) => t + r.sizeKb, 0), On = Se("file"), Bt = 3, Bn = ({
2013
+ file: e,
2014
+ class: t,
2015
+ ...r
2016
+ }) => {
2017
+ const n = e.name.split(".").pop(), s = e.name.replace(new RegExp(`.${n}$`), "");
2018
+ return l("div", {
2019
+ class: Ne("bg-accent-1 outline-accent-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline", t),
2020
+ ...r,
2021
+ children: [l("p", {
2022
+ "aria-label": "File name",
2023
+ class: "text-accent-12 flex flex-grow overflow-hidden",
2024
+ children: [l("span", {
2025
+ class: "block truncate",
2026
+ children: s
2027
+ }), l("span", {
2028
+ children: [".", n]
2029
+ })]
2030
+ }), l("p", {
2031
+ "aria-label": "File size",
2032
+ class: "text-accent-11",
2033
+ children: Le(e.sizeKb)
2034
+ })]
2035
+ });
2036
+ }, Pt = ({
2037
+ class: e,
2038
+ ...t
2039
+ }) => l("li", {
2040
+ class: Ne("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1", e),
2041
+ ...t
2042
+ }), hr = (e) => {
2043
+ const t = e.split(".").pop();
2044
+ if (!t)
2045
+ throw new Error("No file extension found");
2046
+ return t ? "." + t : "";
2047
+ }, Pn = ({
2048
+ allowedExtensions: e,
2049
+ files: t
2050
+ }) => {
2051
+ const r = e.map((n) => n.toLowerCase());
2052
+ return t.every((n) => r.includes(hr(n.name).toLowerCase()));
2053
+ }, $n = (e, t) => {
2054
+ const r = hr(e);
2055
+ return `${e.replace(new RegExp(`${r}$`), "").slice(0, t)}${r}`;
2056
+ }, jn = ({
2057
+ input: e,
2058
+ onSubmitSuccess: t
2059
+ }) => {
2060
+ var b;
2061
+ const r = (b = M.current$.value.flow) == null ? void 0 : b.data.submissions[e.key], [n, s] = Y(On(r) ? r.value : []), [a, i] = Y(), u = n.length - Bt, c = Rn(n), h = yt(), {
2062
+ t: x
2063
+ } = Z();
2064
+ return l("form", {
2065
+ class: "flex flex-col gap-1 p-2.5",
2066
+ onSubmit: (p) => (p.preventDefault(), i(void 0), n.length === 0 ? i({
2067
+ type: "required",
2068
+ message: x("validation_file")
2069
+ }) : e.config.extensions.length > 0 && !Pn({
2070
+ allowedExtensions: e.config.extensions,
2071
+ files: n
2072
+ }) ? i({
2073
+ type: "validate",
2074
+ message: `${x("validation_file_ext", {
2075
+ ext: e.config.extensions.join(", ")
2076
+ })}`
2077
+ }) : e.config.fileSizeLimitKib && c > e.config.fileSizeLimitKib ? i({
2078
+ type: "max",
2079
+ message: `File size exceeds limit of ${Le(e.config.fileSizeLimitKib)}`
2080
+ }) : e.config.allowMultiple === !1 && n.length > 1 ? i({
2081
+ type: "invalid",
2082
+ message: x("validation_file_max", {
2083
+ count: 1
2084
+ })
2085
+ }) : t({
2086
+ type: "file",
2087
+ value: n
2088
+ })),
2089
+ children: [l("div", {
2090
+ class: "flex items-center gap-2",
2091
+ children: [l("label", {
2092
+ ref: h,
2093
+ for: "dropzone-file",
2094
+ class: "border-neutral-8 bg-neutral-2 flex h-48 w-full cursor-pointer flex-col items-center justify-center overflow-hidden rounded-2xl border border-dashed p-4",
2095
+ children: [n.length > 0 ? l(_e, {
2096
+ children: [l("ul", {
2097
+ class: "flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",
2098
+ children: [n.slice(0, Bt).map((p) => {
2099
+ const k = p.name.split(".").pop(), v = p.name.replace(new RegExp(`.${k}$`), "");
2100
+ return l(Pt, {
2101
+ class: "flex overflow-hidden",
2102
+ children: [l("span", {
2103
+ class: "block truncate",
2104
+ children: v
2105
+ }), l("span", {
2106
+ children: [".", k]
2107
+ })]
2108
+ });
2109
+ }), u > 0 ? l(Pt, {
2110
+ children: ["+", u, " file", u !== 1 ? "s" : ""]
2111
+ }) : null]
2112
+ }), l("p", {
2113
+ class: "text-neutral-11 text-xs",
2114
+ children: [Le(c), " ", n.length > 1 ? "total" : ""]
2115
+ })]
2116
+ }) : l("div", {
2117
+ class: "flex flex-col justify-center gap-4 pb-6 pt-5",
2118
+ children: [l("header", {
2119
+ class: "flex flex-col items-center gap-0",
2120
+ children: [l("svg", {
2121
+ class: "text-neutral-11 mb-1 h-8 w-8",
2122
+ "aria-hidden": "true",
2123
+ xmlns: "http://www.w3.org/2000/svg",
2124
+ fill: "none",
2125
+ viewBox: "0 0 20 16",
2126
+ children: l("path", {
2127
+ stroke: "currentColor",
2128
+ "stroke-linecap": "round",
2129
+ "stroke-linejoin": "round",
2130
+ "stroke-width": "1.5",
2131
+ d: "M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"
2132
+ })
2133
+ }), l("p", {
2134
+ class: "text-neutral-12 tracking-[-0.01em]",
2135
+ children: x("upload_file", {
2136
+ count: e.config.allowMultiple ? 2 : 1
2137
+ })
2138
+ }), e.config.fileSizeLimitKib ? l("p", {
2139
+ class: "text-neutral-10 text-xs",
2140
+ children: ["(", x("file_max_size", {
2141
+ size: Le(e.config.fileSizeLimitKib)
2142
+ }), ")"]
2143
+ }) : null]
2144
+ }), l("aside", {
2145
+ class: "flex flex-col items-center gap-2",
2146
+ children: [l("p", {
2147
+ id: "accepted-filetypes",
2148
+ class: "sr-only",
2149
+ children: x("file_extensions")
2150
+ }), l("ul", {
2151
+ "aria-describedby": "accepted-filetypes",
2152
+ class: "flex flex-wrap justify-center gap-2",
2153
+ children: e.config.extensions.map((p) => l("li", {
2154
+ class: "ring-lowest outline-neutral-6 text-neutral-9 bg-neutral-1 rounded-md px-1 py-0.5 text-[11px] uppercase tracking-wide outline outline-1 ring-2",
2155
+ children: p.replace(".", "")
2156
+ }))
2157
+ })]
2158
+ })]
2159
+ }), l("input", {
2160
+ id: "dropzone-file",
2161
+ onInput: async (p) => {
2162
+ le(p.target instanceof HTMLInputElement);
2163
+ const k = p.target.files ? Array.from(p.target.files) : [], v = await Promise.allSettled(k.map(async (S) => {
2164
+ const A = await Dn(S);
2165
+ return {
2166
+ name: $n(S.name, 42),
2167
+ data: A,
2168
+ sizeKb: S.size / 1e3
2169
+ };
2170
+ }));
2171
+ if (v.some(({
2172
+ status: S
2173
+ }) => S === "rejected"))
2174
+ return i({
2175
+ type: "invalid",
2176
+ message: "Invalid file"
2177
+ });
2178
+ const E = v.map((S) => S.status === "fulfilled" ? S.value : null).filter(Boolean);
2179
+ s(E);
2180
+ },
2181
+ multiple: e.config.allowMultiple,
2182
+ type: "file",
2183
+ class: "sr-only"
2184
+ })]
2185
+ }), l("div", {
2186
+ class: "flex h-full flex-col items-center gap-2",
2187
+ children: [l(be, {
2188
+ disabled: n.length === 0
2189
+ }), e.config.optional && l(ve, {
2190
+ onClick: () => t(null)
2191
+ })]
2192
+ })]
2193
+ }), l(Ce, {
2194
+ error: a
2195
+ })]
2196
+ });
2197
+ };
2198
+ var De = (e) => e.type === "checkbox", ke = (e) => e instanceof Date, U = (e) => e == null;
2199
+ const pr = (e) => typeof e == "object";
2200
+ var $ = (e) => !U(e) && !Array.isArray(e) && pr(e) && !ke(e), zn = (e) => $(e) && e.target ? De(e.target) ? e.target.checked : e.target.value : e, qn = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, Un = (e, t) => e.has(qn(t)), Kn = (e) => {
2201
+ const t = e.constructor && e.constructor.prototype;
2202
+ return $(t) && t.hasOwnProperty("isPrototypeOf");
2203
+ }, bt = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
2204
+ function oe(e) {
2205
+ let t;
2206
+ const r = Array.isArray(e);
2207
+ if (e instanceof Date)
2208
+ t = new Date(e);
2209
+ else if (e instanceof Set)
2210
+ t = new Set(e);
2211
+ else if (!(bt && (e instanceof Blob || e instanceof FileList)) && (r || $(e)))
2212
+ if (t = r ? [] : {}, !r && !Kn(e))
2213
+ t = e;
2214
+ else
2215
+ for (const n in e)
2216
+ e.hasOwnProperty(n) && (t[n] = oe(e[n]));
2217
+ else
2218
+ return e;
2219
+ return t;
2220
+ }
2221
+ var Re = (e) => Array.isArray(e) ? e.filter(Boolean) : [], O = (e) => e === void 0, w = (e, t, r) => {
2222
+ if (!t || !$(e))
2223
+ return r;
2224
+ const n = Re(t.split(/[,[\].]+?/)).reduce((s, a) => U(s) ? s : s[a], e);
2225
+ return O(n) || n === e ? O(e[t]) ? r : e[t] : n;
2226
+ }, de = (e) => typeof e == "boolean";
2227
+ const $t = {
2228
+ BLUR: "blur",
2229
+ FOCUS_OUT: "focusout",
2230
+ CHANGE: "change"
2231
+ }, J = {
2232
+ onBlur: "onBlur",
2233
+ onChange: "onChange",
2234
+ onSubmit: "onSubmit",
2235
+ onTouched: "onTouched",
2236
+ all: "all"
2237
+ }, ie = {
2238
+ max: "max",
2239
+ min: "min",
2240
+ maxLength: "maxLength",
2241
+ minLength: "minLength",
2242
+ pattern: "pattern",
2243
+ required: "required",
2244
+ validate: "validate"
2245
+ };
2246
+ X.createContext(null);
2247
+ var Gn = (e, t, r, n = !0) => {
2248
+ const s = {
2249
+ defaultValues: t._defaultValues
2250
+ };
2251
+ for (const a in e)
2252
+ Object.defineProperty(s, a, {
2253
+ get: () => {
2254
+ const i = a;
2255
+ return t._proxyFormState[i] !== J.all && (t._proxyFormState[i] = !n || J.all), r && (r[i] = !0), e[i];
2256
+ }
2257
+ });
2258
+ return s;
2259
+ }, W = (e) => $(e) && !Object.keys(e).length, Hn = (e, t, r, n) => {
2260
+ r(e);
2261
+ const { name: s, ...a } = e;
2262
+ return W(a) || Object.keys(a).length >= Object.keys(t).length || Object.keys(a).find((i) => t[i] === (!n || J.all));
2263
+ }, it = (e) => Array.isArray(e) ? e : [e];
2264
+ function Wn(e) {
2265
+ const t = X.useRef(e);
2266
+ t.current = e, X.useEffect(() => {
2267
+ const r = !e.disabled && t.current.subject && t.current.subject.subscribe({
2268
+ next: t.current.next
2269
+ });
2270
+ return () => {
2271
+ r && r.unsubscribe();
2272
+ };
2273
+ }, [e.disabled]);
2274
+ }
2275
+ var te = (e) => typeof e == "string", Jn = (e, t, r, n, s) => te(e) ? (n && t.watch.add(e), w(r, e, s)) : Array.isArray(e) ? e.map((a) => (n && t.watch.add(a), w(r, a))) : (n && (t.watchAll = !0), r), vt = (e) => /^\w*$/.test(e), mr = (e) => Re(e.replace(/["|']|\]/g, "").split(/\.|\[/));
2276
+ function L(e, t, r) {
2277
+ let n = -1;
2278
+ const s = vt(t) ? [t] : mr(t), a = s.length, i = a - 1;
2279
+ for (; ++n < a; ) {
2280
+ const u = s[n];
2281
+ let c = r;
2282
+ if (n !== i) {
2283
+ const h = e[u];
2284
+ c = $(h) || Array.isArray(h) ? h : isNaN(+s[n + 1]) ? {} : [];
2285
+ }
2286
+ e[u] = c, e = e[u];
2287
+ }
2288
+ return e;
2289
+ }
2290
+ var gr = (e, t, r, n, s) => t ? {
2291
+ ...r[e],
2292
+ types: {
2293
+ ...r[e] && r[e].types ? r[e].types : {},
2294
+ [n]: s || !0
2295
+ }
2296
+ } : {}, jt = (e) => ({
2297
+ isOnSubmit: !e || e === J.onSubmit,
2298
+ isOnBlur: e === J.onBlur,
2299
+ isOnChange: e === J.onChange,
2300
+ isOnAll: e === J.all,
2301
+ isOnTouch: e === J.onTouched
2302
+ }), zt = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((n) => e.startsWith(n) && /^\.\w+/.test(e.slice(n.length))));
2303
+ const ze = (e, t, r, n) => {
2304
+ for (const s of r || Object.keys(e)) {
2305
+ const a = w(e, s);
2306
+ if (a) {
2307
+ const { _f: i, ...u } = a;
2308
+ if (i) {
2309
+ if (i.refs && i.refs[0] && t(i.refs[0], s) && !n)
2310
+ break;
2311
+ if (i.ref && t(i.ref, i.name) && !n)
2312
+ break;
2313
+ } else
2314
+ $(u) && ze(u, t);
2315
+ }
2316
+ }
2317
+ };
2318
+ var Zn = (e, t, r) => {
2319
+ const n = Re(w(e, r));
2320
+ return L(n, "root", t[r]), L(e, r, n), e;
2321
+ }, xt = (e) => e.type === "file", fe = (e) => typeof e == "function", Ge = (e) => {
2322
+ if (!bt)
2323
+ return !1;
2324
+ const t = e ? e.ownerDocument : 0;
2325
+ return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
2326
+ }, qe = (e) => te(e), wt = (e) => e.type === "radio", He = (e) => e instanceof RegExp;
2327
+ const qt = {
2328
+ value: !1,
2329
+ isValid: !1
2330
+ }, Ut = { value: !0, isValid: !0 };
2331
+ var yr = (e) => {
2332
+ if (Array.isArray(e)) {
2333
+ if (e.length > 1) {
2334
+ const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
2335
+ return { value: t, isValid: !!t.length };
2336
+ }
2337
+ return e[0].checked && !e[0].disabled ? (
2338
+ // @ts-expect-error expected to work in the browser
2339
+ e[0].attributes && !O(e[0].attributes.value) ? O(e[0].value) || e[0].value === "" ? Ut : { value: e[0].value, isValid: !0 } : Ut
2340
+ ) : qt;
2341
+ }
2342
+ return qt;
2343
+ };
2344
+ const Kt = {
2345
+ isValid: !1,
2346
+ value: null
2347
+ };
2348
+ var br = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
2349
+ isValid: !0,
2350
+ value: r.value
2351
+ } : t, Kt) : Kt;
2352
+ function Gt(e, t, r = "validate") {
2353
+ if (qe(e) || Array.isArray(e) && e.every(qe) || de(e) && !e)
2354
+ return {
2355
+ type: r,
2356
+ message: qe(e) ? e : "",
2357
+ ref: t
2358
+ };
2359
+ }
2360
+ var we = (e) => $(e) && !He(e) ? e : {
2361
+ value: e,
2362
+ message: ""
2363
+ }, Ht = async (e, t, r, n, s) => {
2364
+ const { ref: a, refs: i, required: u, maxLength: c, minLength: h, min: x, max: b, pattern: p, validate: k, name: v, valueAsNumber: E, mount: S, disabled: A } = e._f, g = w(t, v);
2365
+ if (!S || A)
2366
+ return {};
2367
+ const T = i ? i[0] : a, P = (F) => {
2368
+ n && T.reportValidity && (T.setCustomValidity(de(F) ? "" : F || ""), T.reportValidity());
2369
+ }, D = {}, me = wt(a), ce = De(a), Ae = me || ce, G = (E || xt(a)) && O(a.value) && O(g) || Ge(a) && a.value === "" || g === "" || Array.isArray(g) && !g.length, se = gr.bind(null, v, r, D), q = (F, V, R, K = ie.maxLength, H = ie.minLength) => {
2370
+ const Q = F ? V : R;
2371
+ D[v] = {
2372
+ type: F ? K : H,
2373
+ message: Q,
2374
+ ref: a,
2375
+ ...se(F ? K : H, Q)
2376
+ };
2377
+ };
2378
+ if (s ? !Array.isArray(g) || !g.length : u && (!Ae && (G || U(g)) || de(g) && !g || ce && !yr(i).isValid || me && !br(i).isValid)) {
2379
+ const { value: F, message: V } = qe(u) ? { value: !!u, message: u } : we(u);
2380
+ if (F && (D[v] = {
2381
+ type: ie.required,
2382
+ message: V,
2383
+ ref: T,
2384
+ ...se(ie.required, V)
2385
+ }, !r))
2386
+ return P(V), D;
2387
+ }
2388
+ if (!G && (!U(x) || !U(b))) {
2389
+ let F, V;
2390
+ const R = we(b), K = we(x);
2391
+ if (!U(g) && !isNaN(g)) {
2392
+ const H = a.valueAsNumber || g && +g;
2393
+ U(R.value) || (F = H > R.value), U(K.value) || (V = H < K.value);
2394
+ } else {
2395
+ const H = a.valueAsDate || new Date(g), Q = (Oe) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + Oe), ge = a.type == "time", Ee = a.type == "week";
2396
+ te(R.value) && g && (F = ge ? Q(g) > Q(R.value) : Ee ? g > R.value : H > new Date(R.value)), te(K.value) && g && (V = ge ? Q(g) < Q(K.value) : Ee ? g < K.value : H < new Date(K.value));
2397
+ }
2398
+ if ((F || V) && (q(!!F, R.message, K.message, ie.max, ie.min), !r))
2399
+ return P(D[v].message), D;
2400
+ }
2401
+ if ((c || h) && !G && (te(g) || s && Array.isArray(g))) {
2402
+ const F = we(c), V = we(h), R = !U(F.value) && g.length > +F.value, K = !U(V.value) && g.length < +V.value;
2403
+ if ((R || K) && (q(R, F.message, V.message), !r))
2404
+ return P(D[v].message), D;
2405
+ }
2406
+ if (p && !G && te(g)) {
2407
+ const { value: F, message: V } = we(p);
2408
+ if (He(F) && !g.match(F) && (D[v] = {
2409
+ type: ie.pattern,
2410
+ message: V,
2411
+ ref: a,
2412
+ ...se(ie.pattern, V)
2413
+ }, !r))
2414
+ return P(V), D;
2415
+ }
2416
+ if (k) {
2417
+ if (fe(k)) {
2418
+ const F = await k(g, t), V = Gt(F, T);
2419
+ if (V && (D[v] = {
2420
+ ...V,
2421
+ ...se(ie.validate, V.message)
2422
+ }, !r))
2423
+ return P(V.message), D;
2424
+ } else if ($(k)) {
2425
+ let F = {};
2426
+ for (const V in k) {
2427
+ if (!W(F) && !r)
2428
+ break;
2429
+ const R = Gt(await k[V](g, t), T, V);
2430
+ R && (F = {
2431
+ ...R,
2432
+ ...se(V, R.message)
2433
+ }, P(R.message), r && (D[v] = F));
2434
+ }
2435
+ if (!W(F) && (D[v] = {
2436
+ ref: T,
2437
+ ...F
2438
+ }, !r))
2439
+ return D;
2440
+ }
2441
+ }
2442
+ return P(!0), D;
2443
+ };
2444
+ function Qn(e, t) {
2445
+ const r = t.slice(0, -1).length;
2446
+ let n = 0;
2447
+ for (; n < r; )
2448
+ e = O(e) ? n++ : e[t[n++]];
2449
+ return e;
2450
+ }
2451
+ function Xn(e) {
2452
+ for (const t in e)
2453
+ if (e.hasOwnProperty(t) && !O(e[t]))
2454
+ return !1;
2455
+ return !0;
2456
+ }
2457
+ function j(e, t) {
2458
+ const r = Array.isArray(t) ? t : vt(t) ? [t] : mr(t), n = r.length === 1 ? e : Qn(e, r), s = r.length - 1, a = r[s];
2459
+ return n && delete n[a], s !== 0 && ($(n) && W(n) || Array.isArray(n) && Xn(n)) && j(e, r.slice(0, -1)), e;
2460
+ }
2461
+ function ot() {
2462
+ let e = [];
2463
+ return {
2464
+ get observers() {
2465
+ return e;
2466
+ },
2467
+ next: (s) => {
2468
+ for (const a of e)
2469
+ a.next && a.next(s);
2470
+ },
2471
+ subscribe: (s) => (e.push(s), {
2472
+ unsubscribe: () => {
2473
+ e = e.filter((a) => a !== s);
2474
+ }
2475
+ }),
2476
+ unsubscribe: () => {
2477
+ e = [];
2478
+ }
2479
+ };
2480
+ }
2481
+ var We = (e) => U(e) || !pr(e);
2482
+ function ye(e, t) {
2483
+ if (We(e) || We(t))
2484
+ return e === t;
2485
+ if (ke(e) && ke(t))
2486
+ return e.getTime() === t.getTime();
2487
+ const r = Object.keys(e), n = Object.keys(t);
2488
+ if (r.length !== n.length)
2489
+ return !1;
2490
+ for (const s of r) {
2491
+ const a = e[s];
2492
+ if (!n.includes(s))
2493
+ return !1;
2494
+ if (s !== "ref") {
2495
+ const i = t[s];
2496
+ if (ke(a) && ke(i) || $(a) && $(i) || Array.isArray(a) && Array.isArray(i) ? !ye(a, i) : a !== i)
2497
+ return !1;
2498
+ }
2499
+ }
2500
+ return !0;
2501
+ }
2502
+ var vr = (e) => e.type === "select-multiple", Yn = (e) => wt(e) || De(e), lt = (e) => Ge(e) && e.isConnected, xr = (e) => {
2503
+ for (const t in e)
2504
+ if (fe(e[t]))
2505
+ return !0;
2506
+ return !1;
2507
+ };
2508
+ function Je(e, t = {}) {
2509
+ const r = Array.isArray(e);
2510
+ if ($(e) || r)
2511
+ for (const n in e)
2512
+ Array.isArray(e[n]) || $(e[n]) && !xr(e[n]) ? (t[n] = Array.isArray(e[n]) ? [] : {}, Je(e[n], t[n])) : U(e[n]) || (t[n] = !0);
2513
+ return t;
2514
+ }
2515
+ function wr(e, t, r) {
2516
+ const n = Array.isArray(e);
2517
+ if ($(e) || n)
2518
+ for (const s in e)
2519
+ Array.isArray(e[s]) || $(e[s]) && !xr(e[s]) ? O(t) || We(r[s]) ? r[s] = Array.isArray(e[s]) ? Je(e[s], []) : { ...Je(e[s]) } : wr(e[s], U(t) ? {} : t[s], r[s]) : r[s] = !ye(e[s], t[s]);
2520
+ return r;
2521
+ }
2522
+ var ut = (e, t) => wr(e, t, Je(t)), kr = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: n }) => O(e) ? e : t ? e === "" ? NaN : e && +e : r && te(e) ? new Date(e) : n ? n(e) : e;
2523
+ function ct(e) {
2524
+ const t = e.ref;
2525
+ if (!(e.refs ? e.refs.every((r) => r.disabled) : t.disabled))
2526
+ return xt(t) ? t.files : wt(t) ? br(e.refs).value : vr(t) ? [...t.selectedOptions].map(({ value: r }) => r) : De(t) ? yr(e.refs).value : kr(O(t.value) ? e.ref.value : t.value, e);
2527
+ }
2528
+ var es = (e, t, r, n) => {
2529
+ const s = {};
2530
+ for (const a of e) {
2531
+ const i = w(t, a);
2532
+ i && L(s, a, i._f);
2533
+ }
2534
+ return {
2535
+ criteriaMode: r,
2536
+ names: [...e],
2537
+ fields: s,
2538
+ shouldUseNativeValidation: n
2539
+ };
2540
+ }, Ve = (e) => O(e) ? e : He(e) ? e.source : $(e) ? He(e.value) ? e.value.source : e.value : e, ts = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate);
2541
+ function Wt(e, t, r) {
2542
+ const n = w(e, r);
2543
+ if (n || vt(r))
2544
+ return {
2545
+ error: n,
2546
+ name: r
2547
+ };
2548
+ const s = r.split(".");
2549
+ for (; s.length; ) {
2550
+ const a = s.join("."), i = w(t, a), u = w(e, a);
2551
+ if (i && !Array.isArray(i) && r !== a)
2552
+ return { name: r };
2553
+ if (u && u.type)
2554
+ return {
2555
+ name: a,
2556
+ error: u
2557
+ };
2558
+ s.pop();
2559
+ }
2560
+ return {
2561
+ name: r
2562
+ };
2563
+ }
2564
+ var rs = (e, t, r, n, s) => s.isOnAll ? !1 : !r && s.isOnTouch ? !(t || e) : (r ? n.isOnBlur : s.isOnBlur) ? !e : (r ? n.isOnChange : s.isOnChange) ? e : !0, ns = (e, t) => !Re(w(e, t)).length && j(e, t);
2565
+ const ss = {
2566
+ mode: J.onSubmit,
2567
+ reValidateMode: J.onChange,
2568
+ shouldFocusError: !0
2569
+ };
2570
+ function as(e = {}, t) {
2571
+ let r = {
2572
+ ...ss,
2573
+ ...e
2574
+ }, n = {
2575
+ submitCount: 0,
2576
+ isDirty: !1,
2577
+ isLoading: fe(r.defaultValues),
2578
+ isValidating: !1,
2579
+ isSubmitted: !1,
2580
+ isSubmitting: !1,
2581
+ isSubmitSuccessful: !1,
2582
+ isValid: !1,
2583
+ touchedFields: {},
2584
+ dirtyFields: {},
2585
+ errors: {},
2586
+ disabled: !1
2587
+ }, s = {}, a = $(r.defaultValues) || $(r.values) ? oe(r.defaultValues || r.values) || {} : {}, i = r.shouldUnregister ? {} : oe(a), u = {
2588
+ action: !1,
2589
+ mount: !1,
2590
+ watch: !1
2591
+ }, c = {
2592
+ mount: /* @__PURE__ */ new Set(),
2593
+ unMount: /* @__PURE__ */ new Set(),
2594
+ array: /* @__PURE__ */ new Set(),
2595
+ watch: /* @__PURE__ */ new Set()
2596
+ }, h, x = 0;
2597
+ const b = {
2598
+ isDirty: !1,
2599
+ dirtyFields: !1,
2600
+ touchedFields: !1,
2601
+ isValidating: !1,
2602
+ isValid: !1,
2603
+ errors: !1
2604
+ }, p = {
2605
+ values: ot(),
2606
+ array: ot(),
2607
+ state: ot()
2608
+ }, k = e.resetOptions && e.resetOptions.keepDirtyValues, v = jt(r.mode), E = jt(r.reValidateMode), S = r.criteriaMode === J.all, A = (o) => (d) => {
2609
+ clearTimeout(x), x = setTimeout(o, d);
2610
+ }, g = async (o) => {
2611
+ if (b.isValid || o) {
2612
+ const d = r.resolver ? W((await G()).errors) : await q(s, !0);
2613
+ d !== n.isValid && p.state.next({
2614
+ isValid: d
2615
+ });
2616
+ }
2617
+ }, T = (o) => b.isValidating && p.state.next({
2618
+ isValidating: o
2619
+ }), P = (o, d = [], f, _, y = !0, m = !0) => {
2620
+ if (_ && f) {
2621
+ if (u.action = !0, m && Array.isArray(w(s, o))) {
2622
+ const C = f(w(s, o), _.argA, _.argB);
2623
+ y && L(s, o, C);
2624
+ }
2625
+ if (m && Array.isArray(w(n.errors, o))) {
2626
+ const C = f(w(n.errors, o), _.argA, _.argB);
2627
+ y && L(n.errors, o, C), ns(n.errors, o);
2628
+ }
2629
+ if (b.touchedFields && m && Array.isArray(w(n.touchedFields, o))) {
2630
+ const C = f(w(n.touchedFields, o), _.argA, _.argB);
2631
+ y && L(n.touchedFields, o, C);
2632
+ }
2633
+ b.dirtyFields && (n.dirtyFields = ut(a, i)), p.state.next({
2634
+ name: o,
2635
+ isDirty: V(o, d),
2636
+ dirtyFields: n.dirtyFields,
2637
+ errors: n.errors,
2638
+ isValid: n.isValid
2639
+ });
2640
+ } else
2641
+ L(i, o, d);
2642
+ }, D = (o, d) => {
2643
+ L(n.errors, o, d), p.state.next({
2644
+ errors: n.errors
2645
+ });
2646
+ }, me = (o, d, f, _) => {
2647
+ const y = w(s, o);
2648
+ if (y) {
2649
+ const m = w(i, o, O(f) ? w(a, o) : f);
2650
+ O(m) || _ && _.defaultChecked || d ? L(i, o, d ? m : ct(y._f)) : H(o, m), u.mount && g();
2651
+ }
2652
+ }, ce = (o, d, f, _, y) => {
2653
+ let m = !1, C = !1;
2654
+ const N = {
2655
+ name: o
2656
+ };
2657
+ if (!f || _) {
2658
+ b.isDirty && (C = n.isDirty, n.isDirty = N.isDirty = V(), m = C !== N.isDirty);
2659
+ const B = ye(w(a, o), d);
2660
+ C = w(n.dirtyFields, o), B ? j(n.dirtyFields, o) : L(n.dirtyFields, o, !0), N.dirtyFields = n.dirtyFields, m = m || b.dirtyFields && C !== !B;
2661
+ }
2662
+ if (f) {
2663
+ const B = w(n.touchedFields, o);
2664
+ B || (L(n.touchedFields, o, f), N.touchedFields = n.touchedFields, m = m || b.touchedFields && B !== f);
2665
+ }
2666
+ return m && y && p.state.next(N), m ? N : {};
2667
+ }, Ae = (o, d, f, _) => {
2668
+ const y = w(n.errors, o), m = b.isValid && de(d) && n.isValid !== d;
2669
+ if (e.delayError && f ? (h = A(() => D(o, f)), h(e.delayError)) : (clearTimeout(x), h = null, f ? L(n.errors, o, f) : j(n.errors, o)), (f ? !ye(y, f) : y) || !W(_) || m) {
2670
+ const C = {
2671
+ ..._,
2672
+ ...m && de(d) ? { isValid: d } : {},
2673
+ errors: n.errors,
2674
+ name: o
2675
+ };
2676
+ n = {
2677
+ ...n,
2678
+ ...C
2679
+ }, p.state.next(C);
2680
+ }
2681
+ T(!1);
2682
+ }, G = async (o) => r.resolver(i, r.context, es(o || c.mount, s, r.criteriaMode, r.shouldUseNativeValidation)), se = async (o) => {
2683
+ const { errors: d } = await G(o);
2684
+ if (o)
2685
+ for (const f of o) {
2686
+ const _ = w(d, f);
2687
+ _ ? L(n.errors, f, _) : j(n.errors, f);
2688
+ }
2689
+ else
2690
+ n.errors = d;
2691
+ return d;
2692
+ }, q = async (o, d, f = {
2693
+ valid: !0
2694
+ }) => {
2695
+ for (const _ in o) {
2696
+ const y = o[_];
2697
+ if (y) {
2698
+ const { _f: m, ...C } = y;
2699
+ if (m) {
2700
+ const N = c.array.has(m.name), B = await Ht(y, i, S, r.shouldUseNativeValidation && !d, N);
2701
+ if (B[m.name] && (f.valid = !1, d))
2702
+ break;
2703
+ !d && (w(B, m.name) ? N ? Zn(n.errors, B, m.name) : L(n.errors, m.name, B[m.name]) : j(n.errors, m.name));
2704
+ }
2705
+ C && await q(C, d, f);
2706
+ }
2707
+ }
2708
+ return f.valid;
2709
+ }, F = () => {
2710
+ for (const o of c.unMount) {
2711
+ const d = w(s, o);
2712
+ d && (d._f.refs ? d._f.refs.every((f) => !lt(f)) : !lt(d._f.ref)) && tt(o);
2713
+ }
2714
+ c.unMount = /* @__PURE__ */ new Set();
2715
+ }, V = (o, d) => (o && d && L(i, o, d), !ye(kt(), a)), R = (o, d, f) => Jn(o, c, {
2716
+ ...u.mount ? i : O(d) ? a : te(o) ? { [o]: d } : d
2717
+ }, f, d), K = (o) => Re(w(u.mount ? i : a, o, e.shouldUnregister ? w(a, o, []) : [])), H = (o, d, f = {}) => {
2718
+ const _ = w(s, o);
2719
+ let y = d;
2720
+ if (_) {
2721
+ const m = _._f;
2722
+ m && (!m.disabled && L(i, o, kr(d, m)), y = Ge(m.ref) && U(d) ? "" : d, vr(m.ref) ? [...m.ref.options].forEach((C) => C.selected = y.includes(C.value)) : m.refs ? De(m.ref) ? m.refs.length > 1 ? m.refs.forEach((C) => (!C.defaultChecked || !C.disabled) && (C.checked = Array.isArray(y) ? !!y.find((N) => N === C.value) : y === C.value)) : m.refs[0] && (m.refs[0].checked = !!y) : m.refs.forEach((C) => C.checked = C.value === y) : xt(m.ref) ? m.ref.value = "" : (m.ref.value = y, m.ref.type || p.values.next({
2723
+ name: o,
2724
+ values: { ...i }
2725
+ })));
2726
+ }
2727
+ (f.shouldDirty || f.shouldTouch) && ce(o, y, f.shouldTouch, f.shouldDirty, !0), f.shouldValidate && et(o);
2728
+ }, Q = (o, d, f) => {
2729
+ for (const _ in d) {
2730
+ const y = d[_], m = `${o}.${_}`, C = w(s, m);
2731
+ (c.array.has(o) || !We(y) || C && !C._f) && !ke(y) ? Q(m, y, f) : H(m, y, f);
2732
+ }
2733
+ }, ge = (o, d, f = {}) => {
2734
+ const _ = w(s, o), y = c.array.has(o), m = oe(d);
2735
+ L(i, o, m), y ? (p.array.next({
2736
+ name: o,
2737
+ values: { ...i }
2738
+ }), (b.isDirty || b.dirtyFields) && f.shouldDirty && p.state.next({
2739
+ name: o,
2740
+ dirtyFields: ut(a, i),
2741
+ isDirty: V(o, m)
2742
+ })) : _ && !_._f && !U(m) ? Q(o, m, f) : H(o, m, f), zt(o, c) && p.state.next({ ...n }), p.values.next({
2743
+ name: o,
2744
+ values: { ...i }
2745
+ }), !u.mount && t();
2746
+ }, Ee = async (o) => {
2747
+ const d = o.target;
2748
+ let f = d.name, _ = !0;
2749
+ const y = w(s, f), m = () => d.type ? ct(y._f) : zn(o), C = (N) => {
2750
+ _ = Number.isNaN(N) || N === w(i, f, N);
2751
+ };
2752
+ if (y) {
2753
+ let N, B;
2754
+ const Be = m(), xe = o.type === $t.BLUR || o.type === $t.FOCUS_OUT, Ir = !ts(y._f) && !r.resolver && !w(n.errors, f) && !y._f.deps || rs(xe, w(n.touchedFields, f), n.isSubmitted, E, v), nt = zt(f, c, xe);
2755
+ L(i, f, Be), xe ? (y._f.onBlur && y._f.onBlur(o), h && h(0)) : y._f.onChange && y._f.onChange(o);
2756
+ const st = ce(f, Be, xe, !1), Vr = !W(st) || nt;
2757
+ if (!xe && p.values.next({
2758
+ name: f,
2759
+ type: o.type,
2760
+ values: { ...i }
2761
+ }), Ir)
2762
+ return b.isValid && g(), Vr && p.state.next({ name: f, ...nt ? {} : st });
2763
+ if (!xe && nt && p.state.next({ ...n }), T(!0), r.resolver) {
2764
+ const { errors: Mt } = await G([f]);
2765
+ if (C(Be), _) {
2766
+ const Mr = Wt(n.errors, s, f), Ft = Wt(Mt, s, Mr.name || f);
2767
+ N = Ft.error, f = Ft.name, B = W(Mt);
2768
+ }
2769
+ } else
2770
+ N = (await Ht(y, i, S, r.shouldUseNativeValidation))[f], C(Be), _ && (N ? B = !1 : b.isValid && (B = await q(s, !0)));
2771
+ _ && (y._f.deps && et(y._f.deps), Ae(f, B, N, st));
2772
+ }
2773
+ }, Oe = (o, d) => {
2774
+ if (w(n.errors, d) && o.focus)
2775
+ return o.focus(), 1;
2776
+ }, et = async (o, d = {}) => {
2777
+ let f, _;
2778
+ const y = it(o);
2779
+ if (T(!0), r.resolver) {
2780
+ const m = await se(O(o) ? o : y);
2781
+ f = W(m), _ = o ? !y.some((C) => w(m, C)) : f;
2782
+ } else
2783
+ o ? (_ = (await Promise.all(y.map(async (m) => {
2784
+ const C = w(s, m);
2785
+ return await q(C && C._f ? { [m]: C } : C);
2786
+ }))).every(Boolean), !(!_ && !n.isValid) && g()) : _ = f = await q(s);
2787
+ return p.state.next({
2788
+ ...!te(o) || b.isValid && f !== n.isValid ? {} : { name: o },
2789
+ ...r.resolver || !o ? { isValid: f } : {},
2790
+ errors: n.errors,
2791
+ isValidating: !1
2792
+ }), d.shouldFocus && !_ && ze(s, Oe, o ? y : c.mount), _;
2793
+ }, kt = (o) => {
2794
+ const d = {
2795
+ ...a,
2796
+ ...u.mount ? i : {}
2797
+ };
2798
+ return O(o) ? d : te(o) ? w(d, o) : o.map((f) => w(d, f));
2799
+ }, _t = (o, d) => ({
2800
+ invalid: !!w((d || n).errors, o),
2801
+ isDirty: !!w((d || n).dirtyFields, o),
2802
+ isTouched: !!w((d || n).touchedFields, o),
2803
+ error: w((d || n).errors, o)
2804
+ }), Sr = (o) => {
2805
+ o && it(o).forEach((d) => j(n.errors, d)), p.state.next({
2806
+ errors: o ? n.errors : {}
2807
+ });
2808
+ }, St = (o, d, f) => {
2809
+ const _ = (w(s, o, { _f: {} })._f || {}).ref;
2810
+ L(n.errors, o, {
2811
+ ...d,
2812
+ ref: _
2813
+ }), p.state.next({
2814
+ name: o,
2815
+ errors: n.errors,
2816
+ isValid: !1
2817
+ }), f && f.shouldFocus && _ && _.focus && _.focus();
2818
+ }, Cr = (o, d) => fe(o) ? p.values.subscribe({
2819
+ next: (f) => o(R(void 0, d), f)
2820
+ }) : R(o, d, !0), tt = (o, d = {}) => {
2821
+ for (const f of o ? it(o) : c.mount)
2822
+ c.mount.delete(f), c.array.delete(f), d.keepValue || (j(s, f), j(i, f)), !d.keepError && j(n.errors, f), !d.keepDirty && j(n.dirtyFields, f), !d.keepTouched && j(n.touchedFields, f), !r.shouldUnregister && !d.keepDefaultValue && j(a, f);
2823
+ p.values.next({
2824
+ values: { ...i }
2825
+ }), p.state.next({
2826
+ ...n,
2827
+ ...d.keepDirty ? { isDirty: V() } : {}
2828
+ }), !d.keepIsValid && g();
2829
+ }, Ct = ({ disabled: o, name: d, field: f, fields: _, value: y }) => {
2830
+ if (de(o)) {
2831
+ const m = o ? void 0 : O(y) ? ct(f ? f._f : w(_, d)._f) : y;
2832
+ L(i, d, m), ce(d, m, !1, !1, !0);
2833
+ }
2834
+ }, rt = (o, d = {}) => {
2835
+ let f = w(s, o);
2836
+ const _ = de(d.disabled);
2837
+ return L(s, o, {
2838
+ ...f || {},
2839
+ _f: {
2840
+ ...f && f._f ? f._f : { ref: { name: o } },
2841
+ name: o,
2842
+ mount: !0,
2843
+ ...d
2844
+ }
2845
+ }), c.mount.add(o), f ? Ct({
2846
+ field: f,
2847
+ disabled: d.disabled,
2848
+ name: o
2849
+ }) : me(o, !0, d.value), {
2850
+ ..._ ? { disabled: d.disabled } : {},
2851
+ ...r.progressive ? {
2852
+ required: !!d.required,
2853
+ min: Ve(d.min),
2854
+ max: Ve(d.max),
2855
+ minLength: Ve(d.minLength),
2856
+ maxLength: Ve(d.maxLength),
2857
+ pattern: Ve(d.pattern)
2858
+ } : {},
2859
+ name: o,
2860
+ onChange: Ee,
2861
+ onBlur: Ee,
2862
+ ref: (y) => {
2863
+ if (y) {
2864
+ rt(o, d), f = w(s, o);
2865
+ const m = O(y.value) && y.querySelectorAll && y.querySelectorAll("input,select,textarea")[0] || y, C = Yn(m), N = f._f.refs || [];
2866
+ if (C ? N.find((B) => B === m) : m === f._f.ref)
2867
+ return;
2868
+ L(s, o, {
2869
+ _f: {
2870
+ ...f._f,
2871
+ ...C ? {
2872
+ refs: [
2873
+ ...N.filter(lt),
2874
+ m,
2875
+ ...Array.isArray(w(a, o)) ? [{}] : []
2876
+ ],
2877
+ ref: { type: m.type, name: o }
2878
+ } : { ref: m }
2879
+ }
2880
+ }), me(o, !1, void 0, m);
2881
+ } else
2882
+ f = w(s, o, {}), f._f && (f._f.mount = !1), (r.shouldUnregister || d.shouldUnregister) && !(Un(c.array, o) && u.action) && c.unMount.add(o);
2883
+ }
2884
+ };
2885
+ }, At = () => r.shouldFocusError && ze(s, Oe, c.mount), Ar = (o) => {
2886
+ de(o) && (p.state.next({ disabled: o }), ze(s, (d) => {
2887
+ d.disabled = o;
2888
+ }, 0, !1));
2889
+ }, Et = (o, d) => async (f) => {
2890
+ f && (f.preventDefault && f.preventDefault(), f.persist && f.persist());
2891
+ let _ = oe(i);
2892
+ if (p.state.next({
2893
+ isSubmitting: !0
2894
+ }), r.resolver) {
2895
+ const { errors: y, values: m } = await G();
2896
+ n.errors = y, _ = m;
2897
+ } else
2898
+ await q(s);
2899
+ j(n.errors, "root"), W(n.errors) ? (p.state.next({
2900
+ errors: {}
2901
+ }), await o(_, f)) : (d && await d({ ...n.errors }, f), At(), setTimeout(At)), p.state.next({
2902
+ isSubmitted: !0,
2903
+ isSubmitting: !1,
2904
+ isSubmitSuccessful: W(n.errors),
2905
+ submitCount: n.submitCount + 1,
2906
+ errors: n.errors
2907
+ });
2908
+ }, Er = (o, d = {}) => {
2909
+ w(s, o) && (O(d.defaultValue) ? ge(o, w(a, o)) : (ge(o, d.defaultValue), L(a, o, d.defaultValue)), d.keepTouched || j(n.touchedFields, o), d.keepDirty || (j(n.dirtyFields, o), n.isDirty = d.defaultValue ? V(o, w(a, o)) : V()), d.keepError || (j(n.errors, o), b.isValid && g()), p.state.next({ ...n }));
2910
+ }, It = (o, d = {}) => {
2911
+ const f = o ? oe(o) : a, _ = oe(f), y = o && !W(o) ? _ : a;
2912
+ if (d.keepDefaultValues || (a = f), !d.keepValues) {
2913
+ if (d.keepDirtyValues || k)
2914
+ for (const m of c.mount)
2915
+ w(n.dirtyFields, m) ? L(y, m, w(i, m)) : ge(m, w(y, m));
2916
+ else {
2917
+ if (bt && O(o))
2918
+ for (const m of c.mount) {
2919
+ const C = w(s, m);
2920
+ if (C && C._f) {
2921
+ const N = Array.isArray(C._f.refs) ? C._f.refs[0] : C._f.ref;
2922
+ if (Ge(N)) {
2923
+ const B = N.closest("form");
2924
+ if (B) {
2925
+ B.reset();
2926
+ break;
2927
+ }
2928
+ }
2929
+ }
2930
+ }
2931
+ s = {};
2932
+ }
2933
+ i = e.shouldUnregister ? d.keepDefaultValues ? oe(a) : {} : oe(y), p.array.next({
2934
+ values: { ...y }
2935
+ }), p.values.next({
2936
+ values: { ...y }
2937
+ });
2938
+ }
2939
+ c = {
2940
+ mount: /* @__PURE__ */ new Set(),
2941
+ unMount: /* @__PURE__ */ new Set(),
2942
+ array: /* @__PURE__ */ new Set(),
2943
+ watch: /* @__PURE__ */ new Set(),
2944
+ watchAll: !1,
2945
+ focus: ""
2946
+ }, !u.mount && t(), u.mount = !b.isValid || !!d.keepIsValid, u.watch = !!e.shouldUnregister, p.state.next({
2947
+ submitCount: d.keepSubmitCount ? n.submitCount : 0,
2948
+ isDirty: d.keepDirty ? n.isDirty : !!(d.keepDefaultValues && !ye(o, a)),
2949
+ isSubmitted: d.keepIsSubmitted ? n.isSubmitted : !1,
2950
+ dirtyFields: d.keepDirtyValues ? n.dirtyFields : d.keepDefaultValues && o ? ut(a, o) : {},
2951
+ touchedFields: d.keepTouched ? n.touchedFields : {},
2952
+ errors: d.keepErrors ? n.errors : {},
2953
+ isSubmitSuccessful: d.keepIsSubmitSuccessful ? n.isSubmitSuccessful : !1,
2954
+ isSubmitting: !1
2955
+ });
2956
+ }, Vt = (o, d) => It(fe(o) ? o(i) : o, d);
2957
+ return {
2958
+ control: {
2959
+ register: rt,
2960
+ unregister: tt,
2961
+ getFieldState: _t,
2962
+ handleSubmit: Et,
2963
+ setError: St,
2964
+ _executeSchema: G,
2965
+ _getWatch: R,
2966
+ _getDirty: V,
2967
+ _updateValid: g,
2968
+ _removeUnmounted: F,
2969
+ _updateFieldArray: P,
2970
+ _updateDisabledField: Ct,
2971
+ _getFieldArray: K,
2972
+ _reset: It,
2973
+ _resetDefaultValues: () => fe(r.defaultValues) && r.defaultValues().then((o) => {
2974
+ Vt(o, r.resetOptions), p.state.next({
2975
+ isLoading: !1
2976
+ });
2977
+ }),
2978
+ _updateFormState: (o) => {
2979
+ n = {
2980
+ ...n,
2981
+ ...o
2982
+ };
2983
+ },
2984
+ _disableForm: Ar,
2985
+ _subjects: p,
2986
+ _proxyFormState: b,
2987
+ get _fields() {
2988
+ return s;
2989
+ },
2990
+ get _formValues() {
2991
+ return i;
2992
+ },
2993
+ get _state() {
2994
+ return u;
2995
+ },
2996
+ set _state(o) {
2997
+ u = o;
2998
+ },
2999
+ get _defaultValues() {
3000
+ return a;
3001
+ },
3002
+ get _names() {
3003
+ return c;
3004
+ },
3005
+ set _names(o) {
3006
+ c = o;
3007
+ },
3008
+ get _formState() {
3009
+ return n;
3010
+ },
3011
+ set _formState(o) {
3012
+ n = o;
3013
+ },
3014
+ get _options() {
3015
+ return r;
3016
+ },
3017
+ set _options(o) {
3018
+ r = {
3019
+ ...r,
3020
+ ...o
3021
+ };
3022
+ }
3023
+ },
3024
+ trigger: et,
3025
+ register: rt,
3026
+ handleSubmit: Et,
3027
+ watch: Cr,
3028
+ setValue: ge,
3029
+ getValues: kt,
3030
+ reset: Vt,
3031
+ resetField: Er,
3032
+ clearErrors: Sr,
3033
+ unregister: tt,
3034
+ setError: St,
3035
+ setFocus: (o, d = {}) => {
3036
+ const f = w(s, o), _ = f && f._f;
3037
+ if (_) {
3038
+ const y = _.refs ? _.refs[0] : _.ref;
3039
+ y.focus && (y.focus(), d.shouldSelect && y.select());
3040
+ }
3041
+ },
3042
+ getFieldState: _t
3043
+ };
3044
+ }
3045
+ function Xe(e = {}) {
3046
+ const t = X.useRef(), r = X.useRef(), [n, s] = X.useState({
3047
+ isDirty: !1,
3048
+ isValidating: !1,
3049
+ isLoading: fe(e.defaultValues),
3050
+ isSubmitted: !1,
3051
+ isSubmitting: !1,
3052
+ isSubmitSuccessful: !1,
3053
+ isValid: !1,
3054
+ submitCount: 0,
3055
+ dirtyFields: {},
3056
+ touchedFields: {},
3057
+ errors: {},
3058
+ disabled: !1,
3059
+ defaultValues: fe(e.defaultValues) ? void 0 : e.defaultValues
3060
+ });
3061
+ t.current || (t.current = {
3062
+ ...as(e, () => s((i) => ({ ...i }))),
3063
+ formState: n
3064
+ });
3065
+ const a = t.current.control;
3066
+ return a._options = e, Wn({
3067
+ subject: a._subjects.state,
3068
+ next: (i) => {
3069
+ Hn(i, a._proxyFormState, a._updateFormState, !0) && s({ ...a._formState });
3070
+ }
3071
+ }), X.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), X.useEffect(() => {
3072
+ if (a._proxyFormState.isDirty) {
3073
+ const i = a._getDirty();
3074
+ i !== n.isDirty && a._subjects.state.next({
3075
+ isDirty: i
3076
+ });
3077
+ }
3078
+ }, [a, n.isDirty]), X.useEffect(() => {
3079
+ e.values && !ye(e.values, r.current) ? (a._reset(e.values, a._options.resetOptions), r.current = e.values) : a._resetDefaultValues();
3080
+ }, [e.values, a]), X.useEffect(() => {
3081
+ a._state.mount || (a._updateValid(), a._state.mount = !0), a._state.watch && (a._state.watch = !1, a._subjects.state.next({ ...a._formState })), a._removeUnmounted();
3082
+ }), t.current.formState = Gn(n, a), t.current;
3083
+ }
3084
+ var Jt = function(e, t, r) {
3085
+ if (e && "reportValidity" in e) {
3086
+ var n = w(r, t);
3087
+ e.setCustomValidity(n && n.message || ""), e.reportValidity();
3088
+ }
3089
+ }, is = function(e, t) {
3090
+ var r = function(s) {
3091
+ var a = t.fields[s];
3092
+ a && a.ref && "reportValidity" in a.ref ? Jt(a.ref, s, e) : a.refs && a.refs.forEach(function(i) {
3093
+ return Jt(i, s, e);
3094
+ });
3095
+ };
3096
+ for (var n in t.fields)
3097
+ r(n);
3098
+ }, os = function(e, t) {
3099
+ t.shouldUseNativeValidation && is(e, t);
3100
+ var r = {};
3101
+ for (var n in e) {
3102
+ var s = w(t.fields, n), a = Object.assign(e[n] || {}, { ref: s && s.ref });
3103
+ if (us(t.names || Object.keys(e), n)) {
3104
+ var i = Object.assign({}, ls(w(r, n)));
3105
+ L(i, "root", a), L(r, n, i);
3106
+ } else
3107
+ L(r, n, a);
3108
+ }
3109
+ return r;
3110
+ }, ls = function(e) {
3111
+ return Array.isArray(e) ? e.filter(Boolean) : [];
3112
+ }, us = function(e, t) {
3113
+ return e.some(function(r) {
3114
+ return r.startsWith(t + ".");
3115
+ });
3116
+ }, cs = function(e, t) {
3117
+ for (var r = {}; e.issues.length; ) {
3118
+ var n = e.issues[0];
3119
+ if (n.path) {
3120
+ var s = n.path.map(function(u) {
3121
+ return u.key;
3122
+ }).join(".");
3123
+ if (r[s] || (r[s] = { message: n.message, type: n.validation }), t) {
3124
+ var a = r[s].types, i = a && a[n.validation];
3125
+ r[s] = gr(s, t, r, n.validation, i ? [].concat(i, n.message) : n.message);
3126
+ }
3127
+ e.issues.shift();
3128
+ }
3129
+ }
3130
+ return r;
3131
+ }, Ye = function(e, t, r) {
3132
+ return r === void 0 && (r = {}), function(n, s, a) {
3133
+ try {
3134
+ return Promise.resolve(function(i, u) {
3135
+ try {
3136
+ var c = function() {
3137
+ function h(b) {
3138
+ return { values: r.raw ? n : b, errors: {} };
3139
+ }
3140
+ var x = Object.assign({}, { abortEarly: !1, abortPipeEarly: !1 }, t);
3141
+ return r.mode === "sync" ? h(ar(e, n, x)) : Promise.resolve(Or(e, n, x)).then(h);
3142
+ }();
3143
+ } catch (h) {
3144
+ return u(h);
3145
+ }
3146
+ return c && c.then ? c.then(void 0, u) : c;
3147
+ }(0, function(i) {
3148
+ if (i instanceof Br)
3149
+ return { values: {}, errors: os(cs(i, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a) };
3150
+ throw i;
3151
+ }));
3152
+ } catch (i) {
3153
+ return Promise.reject(i);
3154
+ }
3155
+ };
3156
+ };
3157
+ const Zt = 27, Qt = 12, Xt = 10, ds = Se("enum"), fs = (e) => {
3158
+ const t = {
3159
+ min: e.minSelected ?? 0,
3160
+ max: e.maxSelected ?? e.options.length
3161
+ };
3162
+ return Ye(he({
3163
+ checked: ir(Pr($r()), (r) => Object.entries(r).filter(([n, s]) => s).map(([n, s]) => n), [$e(t.max, `Please select at most ${t.max} option${t.max !== 1 ? "s" : ""}`), je(t.min, `Please select at least ${t.min} option${t.min !== 1 ? "s" : ""}`)])
3164
+ }));
3165
+ }, hs = sr(({
3166
+ option: e,
3167
+ ...t
3168
+ }, r) => l(_e, {
3169
+ children: [l("input", {
3170
+ class: "peer sr-only h-full",
3171
+ type: "checkbox",
3172
+ ...t,
3173
+ ref: r
3174
+ }), l("label", {
3175
+ class: "bg-lowest hover:bg-neutral-2 active:outline-neutral-8 ease-expo-out outline-divider text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 peer-focus-visible:ring-accent-9 peer-focus-visible:ring-offset-accent-7 block cursor-pointer select-none rounded-2xl px-3 py-1.5 outline outline-1 ring-0 ring-transparent transition-all selection:bg-transparent peer-focus-visible:ring-4",
3176
+ htmlFor: t.id,
3177
+ children: e.label
3178
+ })]
3179
+ })), Yt = Ze("gutter-stable flex w-full flex-1 flex-wrap gap-3 overflow-y-auto rounded-xl p-2.5 pr-4", {
3180
+ variants: {
3181
+ variant: {
3182
+ // In cases where there is only one option, we want to center it
3183
+ singleOption: "justify-center",
3184
+ // Two choices with exactly 1 min 1 max
3185
+ booleanLike: dr
3186
+ }
3187
+ }
3188
+ }), ps = ({
3189
+ input: e,
3190
+ onSubmitSuccess: t
3191
+ }) => {
3192
+ var h, x;
3193
+ const r = e.key ? (h = M.current$.value.flow) == null ? void 0 : h.data.submissions[e.key] : void 0, n = (e.config.minSelected === 1 || e.config.minSelected === void 0) && e.config.maxSelected === 1, s = n && e.config.options.length === 2, {
3194
+ register: a,
3195
+ handleSubmit: i,
3196
+ formState: {
3197
+ errors: u
3198
+ }
3199
+ } = Xe({
3200
+ defaultValues: {
3201
+ checked: n ? {} : ds(r) ? Object.fromEntries(r.value.map((b) => [b, !0])) : {}
3202
+ },
3203
+ resolver: fs(e.config)
3204
+ }), c = yt();
3205
+ return s ? l("ul", {
3206
+ style: {
3207
+ maxHeight: 6.5 * Zt + 5 * Qt + 2 * Xt
3208
+ },
3209
+ class: Yt({
3210
+ variant: "booleanLike"
3211
+ }),
3212
+ children: e.config.options.map((b, p) => l("li", {
3213
+ class: "flex-1",
3214
+ children: l(fr, {
3215
+ type: "submit",
3216
+ ref: (k) => {
3217
+ k && p === 0 && (c.current = k);
3218
+ },
3219
+ label: b.label,
3220
+ value: "true",
3221
+ onClick: () => t({
3222
+ type: "enum",
3223
+ value: [b.value]
3224
+ })
3225
+ })
3226
+ }, b.value))
3227
+ }) : l("form", {
3228
+ noValidate: !0,
3229
+ onSubmit: (b) => i((p) => {
3230
+ const k = p.checked;
3231
+ t({
3232
+ type: "enum",
3233
+ value: k
3234
+ });
3235
+ })(b),
3236
+ children: [l("div", {
3237
+ class: "flex items-center gap-1",
3238
+ children: [l("ul", {
3239
+ style: {
3240
+ maxHeight: 6.5 * Zt + 5 * Qt + 2 * Xt
3241
+ },
3242
+ class: Yt({
3243
+ variant: e.config.options.length === 1 ? "singleOption" : void 0
3244
+ }),
3245
+ children: e.config.options.map((b, p) => {
3246
+ const k = `checked.${b.value}`, {
3247
+ ref: v,
3248
+ ...E
3249
+ } = a(k);
3250
+ return l("li", {
3251
+ class: "relative",
3252
+ children: l(hs, {
3253
+ option: b,
3254
+ autoFocus: p === 0,
3255
+ ref: (S) => {
3256
+ S && p === 0 && (c.current = S), v(S);
3257
+ },
3258
+ id: k,
3259
+ ...E,
3260
+ onClick: n ? () => t({
3261
+ type: "enum",
3262
+ value: [b.value]
3263
+ }) : void 0
3264
+ })
3265
+ }, b.value);
3266
+ })
3267
+ }), l("div", {
3268
+ class: "flex flex-col items-center gap-2 pr-2.5 pt-2.5",
3269
+ children: [n ? null : l(be, {}), e.config.minSelected === 0 && l(ve, {
3270
+ type: "button",
3271
+ onClick: () => t({
3272
+ type: "enum",
3273
+ value: []
3274
+ })
3275
+ })]
3276
+ })]
3277
+ }), l("div", {
3278
+ class: "px-1",
3279
+ children: l(Ce, {
3280
+ error: (x = u.checked) == null ? void 0 : x.root
3281
+ })
3282
+ })]
3283
+ });
3284
+ }, ms = Se("number"), gs = (e, t) => {
3285
+ const r = e.min ?? Number.MIN_SAFE_INTEGER, n = e.max ?? Number.MAX_SAFE_INTEGER, s = e.decimalCases ?? 0;
3286
+ return Ye(he({
3287
+ number: jr(t("validation_number"), [zr(r, t("validation_number_min", {
3288
+ min: r
3289
+ })), qr(n, t("validation_number_max", {
3290
+ max: n
3291
+ })), Ur((a) => a === Number(a.toFixed(s)), t("validation_number_decimal_cases", {
3292
+ count: s
3293
+ }))])
3294
+ }));
3295
+ }, ys = ({
3296
+ input: e,
3297
+ onSubmitSuccess: t
3298
+ }) => {
3299
+ var b;
3300
+ const r = e.config.defaultValue, n = e.key ? (b = M.current$.value.flow) == null ? void 0 : b.data.submissions[e.key] : void 0, {
3301
+ t: s
3302
+ } = Z(), {
3303
+ register: a,
3304
+ handleSubmit: i,
3305
+ formState: {
3306
+ errors: u
3307
+ }
3308
+ } = Xe({
3309
+ defaultValues: {
3310
+ number: r ? Number(r) : ms(n) ? n.value : void 0
3311
+ },
3312
+ resolver: gs(e.config, s)
3313
+ }), {
3314
+ ref: c,
3315
+ ...h
3316
+ } = a("number", {
3317
+ required: !e.config.optional,
3318
+ valueAsNumber: !0
3319
+ }), x = re();
3320
+ return pe(() => {
3321
+ x.current && (x.current.focus(), x.current.select());
3322
+ }, []), l("form", {
3323
+ class: "flex flex-col gap-1 p-2.5",
3324
+ onSubmit: i((p) => {
3325
+ p.number !== void 0 && t({
3326
+ type: "number",
3327
+ value: p.number
3328
+ });
3329
+ }),
3330
+ children: [l("div", {
3331
+ class: "flex items-center gap-2",
3332
+ children: [l("div", {
3333
+ class: "relative min-w-0 flex-grow",
3334
+ children: [l("input", {
3335
+ ...h,
3336
+ id: "chat-input",
3337
+ autocomplete: "off",
3338
+ autoCapitalize: "off",
3339
+ autoCorrect: "off",
3340
+ autoFocus: !0,
3341
+ ref: (p) => {
3342
+ p && (x.current = p), c(p);
3343
+ },
3344
+ type: "text",
3345
+ min: e.config.min,
3346
+ max: e.config.max,
3347
+ class: Te({
3348
+ optional: e.config.optional,
3349
+ className: "[type=number:-webkit-inner-spin-button] w-full rounded-full [-webkit-outer-spin-button:none]"
3350
+ }),
3351
+ placeholder: e.config.placeholder
3352
+ }), e.config.optional && l(ve, {
3353
+ class: "absolute right-0 top-0",
3354
+ onClick: () => t(null)
3355
+ })]
3356
+ }), l(be, {})]
3357
+ }), l(Ce, {
3358
+ error: u.number
3359
+ })]
3360
+ });
3361
+ }, bs = (e) => {
3362
+ if (e === "")
3363
+ return {
3364
+ countryCode: "",
3365
+ phoneNumber: ""
3366
+ };
3367
+ const t = Object.entries(gt).find((s) => e.startsWith(s[1])), r = t ? t[1] : "", n = e.replace(r, "");
3368
+ return /^\d+$/.test(n) ? {
3369
+ countryCode: r,
3370
+ phoneNumber: n
3371
+ } : {
3372
+ countryCode: "",
3373
+ phoneNumber: ""
3374
+ };
3375
+ }, vs = "44", xs = Se("string"), ws = Se("phone"), ks = (e) => {
3376
+ const t = ee(e("validation_country_code"), [Lt(/^\+?[0-9 -]+$/, e("validation_country_code"))]);
3377
+ return Ye(he({
3378
+ countryCode: t,
3379
+ phoneNumber: ir(ee(e("validation_phone"), [Lt(/^\+?[0-9 -]+$/, e("validation_phone"))]), (r) => r.replace(/[^0-9]/g, ""), [])
3380
+ }));
3381
+ }, _s = ({
3382
+ input: e,
3383
+ onSubmitSuccess: t
3384
+ }) => {
3385
+ var E;
3386
+ const r = e.key ? (E = M.current$.value.flow) == null ? void 0 : E.data.submissions[e.key] : void 0, {
3387
+ t: n
3388
+ } = Z(), [s, a] = Y(), i = xs(r) ? bs(r.value) : ws(r) ? r.value : void 0, {
3389
+ register: u,
3390
+ handleSubmit: c,
3391
+ formState: {
3392
+ errors: h
3393
+ },
3394
+ watch: x
3395
+ } = Xe({
3396
+ defaultValues: {
3397
+ countryCode: (i == null ? void 0 : i.countryCode) ?? e.config.defaultValue.countryCode ?? vs,
3398
+ phoneNumber: (i == null ? void 0 : i.phoneNumber) ?? e.config.defaultValue.phoneNumber ?? ""
3399
+ },
3400
+ resolver: ks(n)
3401
+ }), {
3402
+ ref: b,
3403
+ ...p
3404
+ } = u("phoneNumber", {
3405
+ required: !e.config.optional
3406
+ }), k = re(), v = x("countryCode");
3407
+ return pe(() => {
3408
+ k.current && (k.current.focus(), k.current.select());
3409
+ }, []), l("form", {
3410
+ noValidate: !0,
3411
+ class: "flex flex-col gap-1 p-2.5",
3412
+ onSubmit: c((S) => {
3413
+ const A = S.phoneNumber.replace(/[^0-9]/g, ""), g = S.countryCode.replace(/[^0-9]/g, "");
3414
+ if (a(void 0), A.length + g.length > (e.config.maxChars || Number.POSITIVE_INFINITY))
3415
+ return a(n("validation_max_chars", {
3416
+ count: e.config.maxChars ?? 999
3417
+ }));
3418
+ if (A.length + g.length < (e.config.minChars || 0))
3419
+ return a(n("validation_min_chars", {
3420
+ count: e.config.minChars ?? 1
3421
+ }));
3422
+ e.config.submissionFormat === "phone" ? t({
3423
+ type: "phone",
3424
+ value: {
3425
+ countryCode: g,
3426
+ phoneNumber: A
3427
+ }
3428
+ }) : t({
3429
+ type: "string",
3430
+ value: v + S.phoneNumber
3431
+ });
3432
+ }),
3433
+ children: [l("div", {
3434
+ class: "flex items-center gap-2",
3435
+ children: [l("div", {
3436
+ class: "relative flex min-w-0 flex-1 flex-grow gap-2",
3437
+ children: [l("label", {
3438
+ class: "text-neutral-12 bg-lowest hover:bg-neutral-5 placeholder:text-neutral-8 focus-visible:outline-accent-7 focus-within:bg-neutral-5 focus-within:outline-accent-7 outline-divider relative flex h-full cursor-pointer appearance-none items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-l-full border-solid px-3 py-1.5 text-center text-base outline outline-2 transition-all focus-within:outline-none",
3439
+ htmlFor: `isdk_phone_${e.key}`,
3440
+ children: [l("span", {
3441
+ children: ["+", v]
3442
+ }), l("select", {
3443
+ ...u("countryCode", {}),
3444
+ id: `isdk_phone_${e.key}`,
3445
+ class: "absolute inset-0 opacity-0",
3446
+ children: Object.entries(gt).map(([S, A]) => l("option", {
3447
+ value: A,
3448
+ children: [S, " (+", A, ")"]
3449
+ }, S))
3450
+ })]
3451
+ }), l("input", {
3452
+ ...p,
3453
+ id: "chat-input",
3454
+ type: "tel",
3455
+ inputMode: "tel",
3456
+ autocomplete: "off",
3457
+ autoCapitalize: "off",
3458
+ autoCorrect: "off",
3459
+ autoFocus: !0,
3460
+ ref: (S) => {
3461
+ S && (k.current = S), b(S);
3462
+ },
3463
+ class: Te({
3464
+ optional: e.config.optional,
3465
+ className: "flex-1 rounded-r-full"
3466
+ }),
3467
+ placeholder: e.config.placeholder
3468
+ }), e.config.optional && l(ve, {
3469
+ class: "absolute right-0 top-0",
3470
+ onClick: () => t(null)
3471
+ })]
3472
+ }), l(be, {})]
3473
+ }), l(Ce, {
3474
+ error: h.countryCode || h.phoneNumber || {
3475
+ message: s
3476
+ }
3477
+ })]
3478
+ });
3479
+ }, Ss = ({
3480
+ input: e,
3481
+ onSubmitSuccess: t
3482
+ }) => l("div", {
3483
+ class: "flex flex-col items-center py-3",
3484
+ children: l("button", {
3485
+ class: "bg-accent-9 hover:bg-accent-10 active:bg-submit-bg-active hover:border-accent-10 active:border-submit-bg-active border-accent-9 ring-accent-6 focus-visible:outline-accent-8 ring-offset-neutral-1 flex cursor-pointer rounded-full border border-solid px-5 py-3 pr-4 text-white outline-none ring-1 ring-offset-[1.5px] transition-all duration-300 focus-visible:outline-2 active:ring-2 active:ring-offset-2",
3486
+ name: e.key,
3487
+ onClick: () => {
3488
+ t(null);
3489
+ },
3490
+ children: l("span", {
3491
+ class: "flex items-center gap-1.5",
3492
+ children: [l("span", {
3493
+ class: "inline-flex items-center text-sm font-medium",
3494
+ children: e.config.label || "Submit"
3495
+ }), l("svg", {
3496
+ stroke: "currentColor",
3497
+ "stroke-width": "1.5",
3498
+ width: "16",
3499
+ height: "16",
3500
+ viewBox: "0 0 16 16",
3501
+ fill: "none",
3502
+ xmlns: "http://www.w3.org/2000/svg",
3503
+ children: [l("path", {
3504
+ d: "M4 8L8 4L12 8"
3505
+ }), l("path", {
3506
+ d: "M8 4V13"
3507
+ })]
3508
+ })]
3509
+ })
3510
+ })
3511
+ }), dt = {
3512
+ empty: "Please enter some text",
3513
+ email: "That doesn’t look like a valid email address",
3514
+ phone: "That doesn’t look like a valid phone number",
3515
+ url: "That doesn’t look like a valid URL"
3516
+ }, Cs = {
3517
+ email: {
3518
+ type: "email",
3519
+ inputMode: "email",
3520
+ formNoValidate: !0
3521
+ },
3522
+ text: {
3523
+ type: "text",
3524
+ inputMode: "text"
3525
+ },
3526
+ url: {
3527
+ type: "url",
3528
+ inputMode: "url",
3529
+ formNoValidate: !0
3530
+ }
3531
+ }, As = Se("string"), Es = (e, t) => {
3532
+ const r = {
3533
+ maxLength: t("validation_max_chars", {
3534
+ count: e.maxChars ?? 999
3535
+ }),
3536
+ minLength: t("validation_min_chars", {
3537
+ count: e.minChars ?? 1
3538
+ })
3539
+ };
3540
+ return Ye(he({
3541
+ text: {
3542
+ email: ee(dt.email, [Kr(dt.email), je(e.minChars ?? 1, r.minLength), $e(e.maxChars ?? 1 / 0, r.maxLength)]),
3543
+ text: ee([je(e.minChars ?? 1, r.minLength), $e(e.maxChars ?? 1 / 0, r.maxLength)]),
3544
+ url: ee([Gr(dt.url), je(e.minChars ?? 1, r.minLength), $e(e.maxChars ?? 1 / 0, r.maxLength)])
3545
+ }[e.format]
3546
+ }));
3547
+ }, Is = ({
3548
+ input: e,
3549
+ onSubmitSuccess: t
3550
+ }) => {
3551
+ var b;
3552
+ const {
3553
+ t: r
3554
+ } = Z(), n = e.key ? (b = M.current$.value.flow) == null ? void 0 : b.data.submissions[e.key] : void 0, s = e.config.defaultValue, {
3555
+ register: a,
3556
+ handleSubmit: i,
3557
+ formState: {
3558
+ errors: u
3559
+ }
3560
+ } = Xe({
3561
+ defaultValues: {
3562
+ text: s || (As(n) ? n.value : "")
3563
+ },
3564
+ resolver: Es(e.config, r)
3565
+ }), {
3566
+ ref: c,
3567
+ ...h
3568
+ } = a("text", {
3569
+ required: !e.config.optional
3570
+ }), x = re();
3571
+ return pe(() => {
3572
+ x.current && (x.current.focus(), x.current.select());
3573
+ }, []), l("form", {
3574
+ noValidate: !0,
3575
+ class: "flex flex-col gap-1 p-2.5",
3576
+ onSubmit: i((p) => {
3577
+ t({
3578
+ type: "string",
3579
+ value: p.text
3580
+ });
3581
+ }),
3582
+ children: [l("div", {
3583
+ class: "flex items-center gap-2",
3584
+ children: [l("div", {
3585
+ class: "relative min-w-0 flex-1",
3586
+ children: [l("input", {
3587
+ id: "chat-input",
3588
+ ...h,
3589
+ ...Cs[e.config.format],
3590
+ autocomplete: "off",
3591
+ autoCapitalize: "off",
3592
+ autoCorrect: "off",
3593
+ autoFocus: !0,
3594
+ ref: (p) => {
3595
+ p && (x.current = p), c(p);
3596
+ },
3597
+ placeholder: e.config.placeholder,
3598
+ class: Te({
3599
+ optional: !!e.config.optional,
3600
+ className: "w-full rounded-full"
3601
+ })
3602
+ }), e.config.optional && l(ve, {
3603
+ class: "absolute right-0 top-0",
3604
+ onClick: () => t(null)
3605
+ })]
3606
+ }), l(be, {})]
3607
+ }), l(Ce, {
3608
+ error: u.text
3609
+ })]
3610
+ });
3611
+ }, Vs = {
3612
+ text: Is,
3613
+ phone: _s,
3614
+ "multiple-choice": ps,
3615
+ boolean: Tn,
3616
+ file: jn,
3617
+ submit: Ss,
3618
+ address: Vn,
3619
+ number: ys
3620
+ }, Ms = ({
3621
+ logger: e
3622
+ }) => {
3623
+ var a;
3624
+ const t = (a = M.current$.value.flow) == null ? void 0 : a.data.currentInput, [r, n] = yn(), s = re(null);
3625
+ return M.inputHeight$.value = n.height, ue(() => {
3626
+ const i = s.current;
3627
+ if (i)
3628
+ return i.addEventListener("transitionstart", z.scrollToEnd.smooth), i.addEventListener("transitioncancel", z.scrollToEnd.smooth), i.addEventListener("transitionend", z.scrollToEnd.smooth), () => {
3629
+ i.removeEventListener("transitionstart", z.scrollToEnd.smooth), i.removeEventListener("transitioncancel", z.scrollToEnd.smooth), i.removeEventListener("transitionend", z.scrollToEnd.smooth);
3630
+ };
3631
+ }, []), l("div", {
3632
+ ref: s,
3633
+ class: "ease-expo-out absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-xl transition-all duration-700 will-change-[height]",
3634
+ style: {
3635
+ height: n.height
3636
+ },
3637
+ children: l("div", {
3638
+ ref: r,
3639
+ class: "border-divider flex flex-col justify-end border-t",
3640
+ children: t ? (() => {
3641
+ const i = Vs[t.type];
3642
+ return l(i, {
3643
+ logger: e,
3644
+ onSubmitSuccess: z.onSubmitSuccessFn$.value,
3645
+ input: t
3646
+ });
3647
+ })() : l("div", {
3648
+ class: "flex items-center gap-2 p-2.5",
3649
+ children: [l("input", {
3650
+ "aria-hidden": "true",
3651
+ id: "chat-input",
3652
+ class: Te({
3653
+ optional: !1,
3654
+ className: "flex-grow rounded-full"
3655
+ }),
3656
+ disabled: !0
3657
+ }), l(be, {
3658
+ disabled: !0,
3659
+ "aria-hidden": "true",
3660
+ tabIndex: -1
3661
+ })]
3662
+ })
3663
+ })
3664
+ });
3665
+ };
3666
+ var Fs = function(e) {
3667
+ return e instanceof RegExp;
3668
+ }, Ls = function(t) {
3669
+ var r = /[\\^$.*+?()[\]{}|]/g, n = RegExp(r.source);
3670
+ return t && n.test(t) ? t.replace(r, "\\$&") : t;
3671
+ }, _r = function(e) {
3672
+ return typeof e == "string";
3673
+ }, Ns = function(e) {
3674
+ var t = [];
3675
+ return e.forEach(function(r) {
3676
+ Array.isArray(r) ? t = t.concat(r) : t.push(r);
3677
+ }), t;
3678
+ };
3679
+ function Ts(e, t, r) {
3680
+ var n = 0, s = 0;
3681
+ if (e === "")
3682
+ return e;
3683
+ if (!e || !_r(e))
3684
+ throw new TypeError("First argument to react-string-replace#replaceString must be a string");
3685
+ var a = t;
3686
+ Fs(a) || (a = new RegExp("(" + Ls(a) + ")", "gi"));
3687
+ for (var i = e.split(a), u = 1, c = i.length; u < c; u += 2) {
3688
+ if (i[u] === void 0 || i[u - 1] === void 0) {
3689
+ console.warn("reactStringReplace: Encountered undefined value during string replacement. Your RegExp may not be working the way you expect.");
3690
+ continue;
3691
+ }
3692
+ s = i[u].length, n += i[u - 1].length, i[u] = r(i[u], u, n), n += s;
3693
+ }
3694
+ return i;
3695
+ }
3696
+ var Ds = function(t, r, n) {
3697
+ return Array.isArray(t) || (t = [t]), Ns(t.map(function(s) {
3698
+ return _r(s) ? Ts(s, r, n) : s;
3699
+ }));
3700
+ };
3701
+ const Pe = /* @__PURE__ */ nr(Ds), Rs = /(\[[^\]]+\]\([^)]+\))/g, Os = /\[([^\]]+)\]\(([^)]+)\)/, Bs = /(https?:\/\/[^\s]+)/g, Ps = /_(.*?)_/g, $s = /\*\*(.*?)\*\*/g, er = "text-accent-10 hover:text-accent-11 no-underline underline-offset-2 hover:underline", js = (e) => {
3702
+ const t = Pe(e, Rs, (a, i) => {
3703
+ const [, u, c] = a.match(Os) ?? [];
3704
+ return c ? l("a", {
3705
+ class: er,
3706
+ href: c,
3707
+ children: u ?? c
3708
+ }, c + i) : l("span", {
3709
+ children: "INVALID LINK"
3710
+ });
3711
+ }), r = Pe(t, Bs, (a, i) => l("a", {
3712
+ class: er,
3713
+ href: a,
3714
+ children: a
3715
+ }, a + i)), n = Pe(r, Ps, (a, i) => l("em", {
3716
+ children: a
3717
+ }, a + i));
3718
+ return Pe(n, $s, (a, i) => l("strong", {
3719
+ children: a
3720
+ }, a + i));
3721
+ }, zs = Ze("select-text max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink min-w-[2rem] py-2 px-3 rounded-[18px] min-h-[36px] break-words relative", {
3722
+ variants: {
3723
+ side: {
3724
+ left: "bg-bubble-weak-bg text-neutral-12 shadow-surface-sm outline outline-1 outline-bubble-weak rounded-bl-md",
3725
+ right: "ml-auto bg-accent-9 text-white rounded-br-md shadow-surface-sm shadow-bubble-strong-shadow"
3726
+ },
3727
+ animate: {
3728
+ true: "animate-bubble-in",
3729
+ false: ""
3730
+ }
3731
+ },
3732
+ defaultVariants: {
3733
+ side: "left"
3734
+ }
3735
+ }), qs = ({
3736
+ children: e,
3737
+ className: t,
3738
+ animate: r,
3739
+ side: n,
3740
+ ...s
3741
+ }) => l("p", {
3742
+ style: {
3743
+ transformOrigin: n === "left" ? "0% 50%" : "100% 50%"
3744
+ },
3745
+ class: zs({
3746
+ className: t,
3747
+ side: n,
3748
+ animate: r
3749
+ }),
3750
+ ...s,
3751
+ children: e
3752
+ }), Us = ({
3753
+ message: e
3754
+ }) => l("div", {
3755
+ class: "bg-accent-3 flex w-full items-center justify-center overflow-hidden rounded-xl px-2 py-2",
3756
+ children: l("a", {
3757
+ onClick: e.onClick,
3758
+ class: "bg-lowest shadow-surface-sm ring-accent-6 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 text-wrap-balance flex items-center gap-1.5 rounded-full py-2 pl-4 pr-2.5 text-center no-underline ring-1 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2",
3759
+ target: "_blank",
3760
+ href: e.href,
3761
+ children: [e.text, l("svg", {
3762
+ class: "flex-none",
3763
+ width: "15",
3764
+ height: "15",
3765
+ viewBox: "0 0 15 15",
3766
+ fill: "none",
3767
+ xmlns: "http://www.w3.org/2000/svg",
3768
+ children: l("path", {
3769
+ d: "M3.64645 11.3536C3.45118 11.1583 3.45118 10.8417 3.64645 10.6465L10.2929 4L6 4C5.72386 4 5.5 3.77614 5.5 3.5C5.5 3.22386 5.72386 3 6 3L11.5 3C11.6326 3 11.7598 3.05268 11.8536 3.14645C11.9473 3.24022 12 3.36739 12 3.5L12 9.00001C12 9.27615 11.7761 9.50001 11.5 9.50001C11.2239 9.50001 11 9.27615 11 9.00001V4.70711L4.35355 11.3536C4.15829 11.5488 3.84171 11.5488 3.64645 11.3536Z",
3770
+ fill: "currentColor",
3771
+ "fill-rule": "evenodd",
3772
+ "clip-rule": "evenodd"
3773
+ })
3774
+ })]
3775
+ })
3776
+ }), Ks = ({
3777
+ className: e,
3778
+ ...t
3779
+ }) => (ue(() => {
3780
+ z.scrollToEnd.smooth();
3781
+ }), l("div", {
3782
+ "aria-hidden": !0,
3783
+ children: z.isBotTyping$.value === !0 ? l("div", {
3784
+ "aria-label": "Typing…",
3785
+ class: Ne("flex gap-1 p-4", e),
3786
+ ...t,
3787
+ children: Array.from({
3788
+ length: 3
3789
+ }, (r, n) => l("div", {
3790
+ class: "bg-accent-9 h-1.5 w-1.5 animate-bounce rounded-full",
3791
+ style: {
3792
+ animationDelay: `${-n * 200}ms`
3793
+ }
3794
+ }))
3795
+ }) : void 0
3796
+ })), Gs = {
3797
+ bot: "left",
3798
+ user: "right"
3799
+ }, Hs = Ze("w-full select-none py-2 text-wrap-balance text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_var(--i-color-n-1)]", {
3800
+ variants: {
3801
+ variant: {
3802
+ info: "text-neutral-8",
3803
+ warning: "text-[#FFC107]",
3804
+ error: "text-error-9",
3805
+ success: "text-[#4CAF50]"
3806
+ }
3807
+ }
3808
+ }), Ws = ({
3809
+ lastSentMessageFooter: e
3810
+ }) => {
3811
+ var r;
3812
+ const t = ((r = M.current$.value.flow) == null ? void 0 : r.data.messages) ?? [];
3813
+ return ue(() => {
3814
+ z.scrollToEnd.smooth();
3815
+ }, [t.length]), l("ol", {
3816
+ "aria-label": "Chat messages",
3817
+ class: "mt-auto flex flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",
3818
+ children: [t.map((n, s) => l(_e, {
3819
+ children: l("li", {
3820
+ class: "flex",
3821
+ children: Ke(n).with({
3822
+ type: "system"
3823
+ }, (a) => l("p", {
3824
+ class: Hs({
3825
+ variant: a.variant
3826
+ }),
3827
+ children: a.text
3828
+ })).with({
3829
+ type: "text",
3830
+ author: I.union("bot", "user")
3831
+ }, (a) => {
3832
+ const i = a.author === "user" && !t.slice(s + 1).some((h) => h.type === "text" && h.author === "user"), u = s === t.length - 1, c = a.author === "bot" ? js(a.text) : a.text;
3833
+ return l(qs, {
3834
+ animate: u,
3835
+ side: Gs[a.author],
3836
+ children: [c, i ? e : null]
3837
+ }, s);
3838
+ }).with({
3839
+ type: "link"
3840
+ }, (a) => l(Us, {
3841
+ message: a
3842
+ })).with({
3843
+ type: "image"
3844
+ }, (a) => l("img", {
3845
+ class: "shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",
3846
+ src: a.url,
3847
+ style: {
3848
+ aspectRatio: a.width / a.height
3849
+ }
3850
+ })).with({
3851
+ type: "file"
3852
+ }, (a) => l(Bn, {
3853
+ class: a.author === "bot" ? void 0 : "ml-auto",
3854
+ file: {
3855
+ name: a.fileName,
3856
+ sizeKb: a.fileSizeKb
3857
+ }
3858
+ })).with({
3859
+ type: "loading"
3860
+ }, (a) => {
3861
+ const i = t[t.length - 1];
3862
+ return !(a === i) || z.isBotTyping$.value ? null : l("div", {
3863
+ class: "flex flex-grow flex-col items-center justify-center",
3864
+ children: l(Hr, {
3865
+ class: "text-neutral-6 h-8 w-8"
3866
+ })
3867
+ });
3868
+ }).exhaustive()
3869
+ })
3870
+ }, s)), l(Ks, {}, "typing")]
3871
+ });
3872
+ }, na = ({
3873
+ logger: e,
3874
+ apiClient: t,
3875
+ analytics: r
3876
+ }) => {
3877
+ const {
3878
+ flow: n
3879
+ } = M.current$.value;
3880
+ le(n, "Flow is required to exist to show chatbot body");
3881
+ const s = M.viewState$.value, {
3882
+ chatRef: a,
3883
+ chatService: i
3884
+ } = _n(), {
3885
+ t: u
3886
+ } = Z(), [c, h] = Y();
3887
+ return pe(() => {
3888
+ s === "maximised" && z.scrollToEnd.instant();
3889
+ }, [s]), pe(() => {
3890
+ var S, A;
3891
+ const {
3892
+ state: x,
3893
+ flow: b
3894
+ } = M.current$.peek();
3895
+ if (x !== "loaded")
3896
+ throw new Error(u("invalid_state"));
3897
+ let p = b.data.nodeHistory.at(-1);
3898
+ if (z.scrollToEnd.instant(), M.setInput(void 0), b.data.isFinished)
3899
+ return;
3900
+ p === void 0 ? (p = rr(n.nodes).id, M.setCurrentNodeId(p), r.log({
3901
+ event: "FLOW_START",
3902
+ properties: {
3903
+ flow_id: n.id,
3904
+ flow_version: n.version,
3905
+ flow_session_id: b.data.flowSessionId,
3906
+ flow_build: n.build,
3907
+ job: n.job
3908
+ },
3909
+ customProperties: (S = n.analytics) == null ? void 0 : S.customProperties
3910
+ })) : M.removeMessagesSentByNodeIds([p]);
3911
+ const {
3912
+ interpret: k,
3913
+ abort: v,
3914
+ undo: E
3915
+ } = Zr({
3916
+ context: n.context,
3917
+ analytics: {
3918
+ service: r,
3919
+ customProperties: (A = n.analytics) == null ? void 0 : A.customProperties
3920
+ },
3921
+ apiClient: t,
3922
+ logger: e,
3923
+ flow: n,
3924
+ chatService: i,
3925
+ t: u,
3926
+ // We need to get fresh submissions, that’s why we call `peek` here.
3927
+ getSubmissions: () => {
3928
+ var g;
3929
+ return (g = M.current$.peek().flow) == null ? void 0 : g.data.submissions;
3930
+ },
3931
+ onInterpret: (g, T) => {
3932
+ var D;
3933
+ const P = M.current$.peek().flow;
3934
+ le(P), T && (P.data.sequence = P.data.sequence + 1, r.log({
3935
+ event: "FLOW_NODE",
3936
+ properties: {
3937
+ flow_id: n.id,
3938
+ flow_version: n.version,
3939
+ from_node_id: T.id,
3940
+ flow_build: n.build,
3941
+ to_node_id: g.id,
3942
+ sequence: P.data.sequence,
3943
+ flow_session_id: P.data.flowSessionId,
3944
+ job: n.job
3945
+ },
3946
+ customProperties: (D = n.analytics) == null ? void 0 : D.customProperties
3947
+ })), M.setCurrentNodeId(g.id);
3948
+ },
3949
+ onFlowEnd: async () => {
3950
+ var T;
3951
+ M.markAsFinished();
3952
+ const g = M.current$.peek().flow;
3953
+ le(g), r.log({
3954
+ event: "FLOW_END",
3955
+ properties: {
3956
+ flow_id: n.id,
3957
+ flow_version: n.version,
3958
+ flow_session_id: g.data.flowSessionId,
3959
+ flow_build: n.build,
3960
+ job: n.job
3961
+ },
3962
+ customProperties: (T = n.analytics) == null ? void 0 : T.customProperties
3963
+ });
3964
+ }
3965
+ });
3966
+ return h(() => E), k(p), v;
3967
+ }, [r, t, i, e, n, u]), l(_e, {
3968
+ children: [l("div", {
3969
+ ref: a,
3970
+ className: "hide-scrollbars relative flex w-full max-w-full flex-grow flex-col overflow-y-scroll",
3971
+ style: {
3972
+ WebkitOverflowScrolling: "touch",
3973
+ paddingBottom: M.inputHeight$.value
3974
+ },
3975
+ children: l(Ws, {
3976
+ lastSentMessageFooter: n.data.isFinished || !c ? null : l(Zs, {
3977
+ undoFn: c
3978
+ })
3979
+ })
3980
+ }), l(Ms, {
3981
+ logger: e
3982
+ })]
3983
+ });
3984
+ }, Js = (e) => "key" in e.data && e.data.key ? [e.data.key] : "keys" in e.data ? Object.values(e.data.keys).filter((t) => typeof t == "string") : [], Zs = ({
3985
+ undoFn: e
3986
+ }) => {
3987
+ const {
3988
+ t
3989
+ } = Z();
3990
+ return l("div", {
3991
+ class: "absolute bottom-0 right-0 flex w-full translate-y-full justify-end",
3992
+ children: l("button", {
3993
+ class: "fr touch-hitbox text-neutral-9 hover:text-neutral-12 rounded-full p-1 text-right text-xs transition-all",
3994
+ onClick: async () => {
3995
+ const {
3996
+ flow: r
3997
+ } = M.current$.peek();
3998
+ le(r);
3999
+ const {
4000
+ removed: n
4001
+ } = e(r.data.nodeHistory), s = r.data.nodeHistory.splice(-n);
4002
+ s.length !== 0 && (M.removeMessagesSentByNodeIds(s), M.setInput(void 0), s.pop(), s.map((a) => r.nodes.find((i) => i.id === a)).filter(Boolean).flatMap(Js).forEach((a) => delete r.data.submissions[a]), M.current$.value = {
4003
+ ...M.current$.value
4004
+ });
4005
+ },
4006
+ children: t("undo")
4007
+ })
4008
+ });
4009
+ };
4010
+ export {
4011
+ na as ChatbotBody
4012
+ };