@inploi/plugin-chatbot 3.28.7 → 3.30.0

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