@inploi/plugin-chatbot 7.0.0 → 7.0.2

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