@inploi/plugin-chatbot 7.0.1 → 7.0.2

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