@inploi/plugin-chatbot 7.0.3 → 7.1.1

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