@inploi/plugin-chatbot 7.0.1 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3979 +0,0 @@
1
- import { g as Ke, i as er, k as Te, a as tr, b as fe, A as Le, c as Fr, 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 Lr, q as he, r as Nr, t as it, v as X, w as Tr, x as nr, z as Dr, B as sr, C as Rr, D as Ce, E as Y, G as Or, V as Br, H as ye, I as De, J as ze, K as ar, L as Pr, M as $r, O as jr, P as zr, Q as Ur, R as qr, S as Kr, T as Gr, U as Hr, W as Wr, X as Jr } from "./index-df69f83a.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
- }, Zr = /{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g, ne = (e, {
176
- context: t,
177
- submissions: r
178
- }) => e.replace(Zr, (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
- }, Xr = ({
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
- }, Qr = ({
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 (_, y) => {
276
- const A = a();
277
- d == null || d(_, y);
278
- try {
279
- await Yr({
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) : Xr({
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 y = e.nodes.find((A) => A.id === _) ?? tr(e.nodes);
318
- return h(y);
319
- },
320
- undo: (_) => {
321
- let y = 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 || (y++, F.type.startsWith("question-")))
326
- break;
327
- }
328
- w.abort(), w = new AbortController();
329
- const S = e.nodes.find((E) => E.id === _[_.length - y]);
330
- return fe(S, "Undo failed: new start node not found"), h(S, A), {
331
- removed: y
332
- };
333
- },
334
- abort: () => {
335
- w.abort();
336
- }
337
- };
338
- }, Qe = (e) => `+${e.countryCode} ${e.phoneNumber}`;
339
- async function Yr(e) {
340
- const t = e.node;
341
- switch (t.type) {
342
- case "text":
343
- return ln({
344
- ...e,
345
- node: t
346
- });
347
- case "image":
348
- return un({
349
- ...e,
350
- node: t
351
- });
352
- case "question-text":
353
- return cn({
354
- ...e,
355
- node: t
356
- });
357
- case "question-enum":
358
- return hn({
359
- ...e,
360
- node: t
361
- });
362
- case "question-number":
363
- return dn({
364
- ...e,
365
- node: t
366
- });
367
- case "question-phone":
368
- return fn({
369
- ...e,
370
- node: t
371
- });
372
- case "question-boolean":
373
- return pn({
374
- ...e,
375
- node: t
376
- });
377
- case "question-file":
378
- return gn({
379
- ...e,
380
- node: t
381
- });
382
- case "question-address":
383
- return mn({
384
- ...e,
385
- node: t
386
- });
387
- case "end-flow":
388
- return bn({
389
- ...e,
390
- node: t
391
- });
392
- case "if-block":
393
- return on({
394
- ...e,
395
- node: t
396
- });
397
- case "jump":
398
- return rn({
399
- ...e,
400
- node: t
401
- });
402
- case "link":
403
- return an({
404
- ...e,
405
- node: t
406
- });
407
- case "integration-application-submit":
408
- return sn({
409
- ...e,
410
- node: t
411
- });
412
- case "add-submission":
413
- return nn({
414
- ...e,
415
- node: t
416
- });
417
- case "integration-workflow-get":
418
- throw Error("Workflow should be unreachable");
419
- case "identify":
420
- return tn({
421
- ...e,
422
- node: t
423
- });
424
- case "feedback":
425
- return en({
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 en({
441
- next: e,
442
- node: t
443
- }) {
444
- e(t.nextId);
445
- }
446
- async function tn({
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 rn({
480
- next: e,
481
- node: t
482
- }) {
483
- e(t.data.targetId);
484
- }
485
- async function nn({
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 sn({
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: Fr(a || {})
537
- })
538
- }).catch((y) => y);
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
- }, (y) => {
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: y.service ?? "INVALID_SERVICE",
564
- response: {
565
- status: y.status,
566
- payload: "data" in y ? y.data : y.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 (y) => {
581
- await e.sendMessage({
582
- type: "text",
583
- author: "bot",
584
- text: y.redirect.message ?? d("submission_redirect_message")
585
- });
586
- try {
587
- const A = new URL(y.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: y.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: ${y.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 (y) => {
633
- n.error(y.error), await e.sendMessage({
634
- type: "system",
635
- variant: "error",
636
- text: y.error.message || d("submission_failed")
637
- }), await p(!1);
638
- }).otherwise(async (y) => {
639
- n.error(y), 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 an({
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 on({
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 ln({
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 un({
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 cn({
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 dn({
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 fn({
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 hn({
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 pn({
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 mn({
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 gn({
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 bn({
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 vn(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, _, y] = 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 && !_n(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", y, !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(y), d.current.resizeObserver.observe(d.current.element), r && d.current.scrollContainers && d.current.scrollContainers.forEach((g) => g.addEventListener("scroll", y, {
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 wn(y, !!r), xn(_), le(() => {
1112
- A(), S();
1113
- }, [r, y, _]), le(() => A, []), [E, i, h];
1114
- }
1115
- function xn(e) {
1116
- le(() => {
1117
- const t = e;
1118
- return window.addEventListener("resize", t), () => void window.removeEventListener("resize", t);
1119
- }, [e]);
1120
- }
1121
- function wn(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 kn = ["x", "y", "top", "bottom", "left", "right", "width", "height"], _n = (e, t) => kn.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
- }, Sn = 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
- }, Cn = () => {
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) * Sn;
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 touch-hitbox text-neutral-10 bg-neutral-1 ring-divider hover:ring-divider active:ring-interactive-bg-hover hover:text-neutral-12 active:text-neutral-12 hover:bg-divider active:bg-interactive-bg-hover flex flex-shrink-0 items-center justify-center gap-1 self-center rounded-full py-1 pl-2 pr-2.5 text-sm ring-1 transition-all", e),
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
- }), En = "https://api.mapbox.com/search/searchbox/v1/suggest", An = "ZzRDWFU0dTZ3SF9aWk9RNGl6QzZaWS5RZmlFak13a0hPbGxXZXlNSGN5RUhObUJ6TXpSV08yUW5OdE5tSTZJU1lpd2lJb1JYYXRObmJ2Tm5iaGhHZWx4V1lpb2pJMUp5ZS5rcA==", Vn = (e) => atob(e).split("").reverse().join(""), ae = he({
1569
- name: X()
1570
- }), In = he({
1571
- suggestions: Nr(he({
1572
- full_address: it(X()),
1573
- place_formatted: it(X()),
1574
- name: it(X()),
1575
- mapbox_id: X(),
1576
- context: Tr(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
- }), Mn = ({
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(En);
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", Vn(An));
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 = Lr(In, 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 _, y, 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) ?? ((y = h.context.street) == null ? void 0 : y.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
- }, Fn = ({
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
- } = Mn({
1674
- logger: r,
1675
- t: n
1676
- }), [w, v] = ee(d ? "query" : "manual"), [h, _] = ee(""), [y, 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(Ln, {
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: y
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
- }, Ln = ({
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-2 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: "relative",
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
- }, bt = () => {
1937
- const e = re(null);
1938
- return le(() => {
1939
- var t;
1940
- (t = e.current) == null || t.focus();
1941
- }, []), e;
1942
- }, ur = ["true", "false"], Nn = Rr(ur), Tn = "answer", cr = "flex items-center flex-wrap gap-2 p-2.5", dr = "min-w-0 max-w-full flex-auto", fr = 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 py-2.5 ring-2 transition-all selection:bg-transparent",
1947
- ...t,
1948
- ref: r,
1949
- children: l("p", {
1950
- class: "text-center text-base",
1951
- children: e
1952
- })
1953
- })), Dn = ({
1954
- input: e,
1955
- onSubmitSuccess: t
1956
- }) => {
1957
- const r = bt();
1958
- return l("form", {
1959
- noValidate: !0,
1960
- class: "",
1961
- onSubmit: (n) => {
1962
- n.preventDefault();
1963
- const s = Dr(n).value, a = sr(Nn, 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: dr,
1973
- children: l(fr, {
1974
- ref: s === 0 ? r : null,
1975
- type: "submit",
1976
- name: Tn,
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: "relative w-full",
1985
- type: "button",
1986
- onClick: () => t(null)
1987
- })
1988
- })]
1989
- });
1990
- }, Rn = (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
- }), On = (e) => e.reduce((t, r) => t + r.sizeKb, 0), Bn = Ce("file"), Ot = 3, Pn = ({
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
- }), hr = (e) => {
2024
- const t = e.split(".").pop();
2025
- if (!t)
2026
- throw new Error("No file extension found");
2027
- return t ? "." + t : "";
2028
- }, $n = ({
2029
- allowedExtensions: e,
2030
- files: t
2031
- }) => {
2032
- const r = e.map((n) => n.toLowerCase());
2033
- return t.every((n) => r.includes(hr(n.name).toLowerCase()));
2034
- }, jn = (e, t) => {
2035
- const r = hr(e);
2036
- return `${e.replace(new RegExp(`${r}$`), "").slice(0, t)}${r}`;
2037
- }, zn = ({
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(Bn(r) ? r.value : []), [a, i] = ee(), u = n.length - Ot, d = On(n), p = bt(), {
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 && !$n({
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(), y = h.name.replace(new RegExp(`.${_}$`), "");
2081
- return l(Bt, {
2082
- class: "flex overflow-hidden",
2083
- children: [l("span", {
2084
- class: "block truncate",
2085
- children: y
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) : [], y = await Promise.allSettled(_.map(async (S) => {
2145
- const E = await Rn(S);
2146
- return {
2147
- name: jn(S.name, 42),
2148
- data: E,
2149
- sizeKb: S.size / 1e3
2150
- };
2151
- }));
2152
- if (y.some(({
2153
- status: S
2154
- }) => S === "rejected"))
2155
- return i({
2156
- type: "invalid",
2157
- message: "Invalid file"
2158
- });
2159
- const A = y.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
- class: "relative",
2172
- onClick: () => t(null)
2173
- })]
2174
- })]
2175
- }), l(Ee, {
2176
- error: a
2177
- })]
2178
- });
2179
- };
2180
- var Be = (e) => e.type === "checkbox", Se = (e) => e instanceof Date, q = (e) => e == null;
2181
- const pr = (e) => typeof e == "object";
2182
- var P = (e) => !q(e) && !Array.isArray(e) && pr(e) && !Se(e), Un = (e) => P(e) && e.target ? Be(e.target) ? e.target.checked : e.target.value : e, qn = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, Kn = (e, t) => e.has(qn(t)), Gn = (e) => {
2183
- const t = e.constructor && e.constructor.prototype;
2184
- return P(t) && t.hasOwnProperty("isPrototypeOf");
2185
- }, yt = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
2186
- function oe(e) {
2187
- let t;
2188
- const r = Array.isArray(e);
2189
- if (e instanceof Date)
2190
- t = new Date(e);
2191
- else if (e instanceof Set)
2192
- t = new Set(e);
2193
- else if (!(yt && (e instanceof Blob || e instanceof FileList)) && (r || P(e)))
2194
- if (t = r ? [] : {}, !r && !Gn(e))
2195
- t = e;
2196
- else
2197
- for (const n in e)
2198
- e.hasOwnProperty(n) && (t[n] = oe(e[n]));
2199
- else
2200
- return e;
2201
- return t;
2202
- }
2203
- var Pe = (e) => Array.isArray(e) ? e.filter(Boolean) : [], O = (e) => e === void 0, x = (e, t, r) => {
2204
- if (!t || !P(e))
2205
- return r;
2206
- const n = Pe(t.split(/[,[\].]+?/)).reduce((s, a) => q(s) ? s : s[a], e);
2207
- return O(n) || n === e ? O(e[t]) ? r : e[t] : n;
2208
- }, ce = (e) => typeof e == "boolean";
2209
- const Pt = {
2210
- BLUR: "blur",
2211
- FOCUS_OUT: "focusout",
2212
- CHANGE: "change"
2213
- }, Z = {
2214
- onBlur: "onBlur",
2215
- onChange: "onChange",
2216
- onSubmit: "onSubmit",
2217
- onTouched: "onTouched",
2218
- all: "all"
2219
- }, ie = {
2220
- max: "max",
2221
- min: "min",
2222
- maxLength: "maxLength",
2223
- minLength: "minLength",
2224
- pattern: "pattern",
2225
- required: "required",
2226
- validate: "validate"
2227
- };
2228
- Y.createContext(null);
2229
- var Hn = (e, t, r, n = !0) => {
2230
- const s = {
2231
- defaultValues: t._defaultValues
2232
- };
2233
- for (const a in e)
2234
- Object.defineProperty(s, a, {
2235
- get: () => {
2236
- const i = a;
2237
- return t._proxyFormState[i] !== Z.all && (t._proxyFormState[i] = !n || Z.all), r && (r[i] = !0), e[i];
2238
- }
2239
- });
2240
- return s;
2241
- }, J = (e) => P(e) && !Object.keys(e).length, Wn = (e, t, r, n) => {
2242
- r(e);
2243
- const { name: s, ...a } = e;
2244
- return J(a) || Object.keys(a).length >= Object.keys(t).length || Object.keys(a).find((i) => t[i] === (!n || Z.all));
2245
- }, ot = (e) => Array.isArray(e) ? e : [e];
2246
- function Jn(e) {
2247
- const t = Y.useRef(e);
2248
- t.current = e, Y.useEffect(() => {
2249
- const r = !e.disabled && t.current.subject && t.current.subject.subscribe({
2250
- next: t.current.next
2251
- });
2252
- return () => {
2253
- r && r.unsubscribe();
2254
- };
2255
- }, [e.disabled]);
2256
- }
2257
- var te = (e) => typeof e == "string", Zn = (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), mr = (e) => Pe(e.replace(/["|']|\]/g, "").split(/\.|\[/));
2258
- function L(e, t, r) {
2259
- let n = -1;
2260
- const s = vt(t) ? [t] : mr(t), a = s.length, i = a - 1;
2261
- for (; ++n < a; ) {
2262
- const u = s[n];
2263
- let d = r;
2264
- if (n !== i) {
2265
- const p = e[u];
2266
- d = P(p) || Array.isArray(p) ? p : isNaN(+s[n + 1]) ? {} : [];
2267
- }
2268
- e[u] = d, e = e[u];
2269
- }
2270
- return e;
2271
- }
2272
- var gr = (e, t, r, n, s) => t ? {
2273
- ...r[e],
2274
- types: {
2275
- ...r[e] && r[e].types ? r[e].types : {},
2276
- [n]: s || !0
2277
- }
2278
- } : {}, $t = (e) => ({
2279
- isOnSubmit: !e || e === Z.onSubmit,
2280
- isOnBlur: e === Z.onBlur,
2281
- isOnChange: e === Z.onChange,
2282
- isOnAll: e === Z.all,
2283
- isOnTouch: e === Z.onTouched
2284
- }), jt = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((n) => e.startsWith(n) && /^\.\w+/.test(e.slice(n.length))));
2285
- const Ue = (e, t, r, n) => {
2286
- for (const s of r || Object.keys(e)) {
2287
- const a = x(e, s);
2288
- if (a) {
2289
- const { _f: i, ...u } = a;
2290
- if (i) {
2291
- if (i.refs && i.refs[0] && t(i.refs[0], s) && !n)
2292
- break;
2293
- if (i.ref && t(i.ref, i.name) && !n)
2294
- break;
2295
- } else
2296
- P(u) && Ue(u, t);
2297
- }
2298
- }
2299
- };
2300
- var Xn = (e, t, r) => {
2301
- const n = Pe(x(e, r));
2302
- return L(n, "root", t[r]), L(e, r, n), e;
2303
- }, xt = (e) => e.type === "file", de = (e) => typeof e == "function", He = (e) => {
2304
- if (!yt)
2305
- return !1;
2306
- const t = e ? e.ownerDocument : 0;
2307
- return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
2308
- }, qe = (e) => te(e), wt = (e) => e.type === "radio", We = (e) => e instanceof RegExp;
2309
- const zt = {
2310
- value: !1,
2311
- isValid: !1
2312
- }, Ut = { value: !0, isValid: !0 };
2313
- var br = (e) => {
2314
- if (Array.isArray(e)) {
2315
- if (e.length > 1) {
2316
- const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
2317
- return { value: t, isValid: !!t.length };
2318
- }
2319
- return e[0].checked && !e[0].disabled ? (
2320
- // @ts-expect-error expected to work in the browser
2321
- e[0].attributes && !O(e[0].attributes.value) ? O(e[0].value) || e[0].value === "" ? Ut : { value: e[0].value, isValid: !0 } : Ut
2322
- ) : zt;
2323
- }
2324
- return zt;
2325
- };
2326
- const qt = {
2327
- isValid: !1,
2328
- value: null
2329
- };
2330
- var yr = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
2331
- isValid: !0,
2332
- value: r.value
2333
- } : t, qt) : qt;
2334
- function Kt(e, t, r = "validate") {
2335
- if (qe(e) || Array.isArray(e) && e.every(qe) || ce(e) && !e)
2336
- return {
2337
- type: r,
2338
- message: qe(e) ? e : "",
2339
- ref: t
2340
- };
2341
- }
2342
- var _e = (e) => P(e) && !We(e) ? e : {
2343
- value: e,
2344
- message: ""
2345
- }, Gt = async (e, t, r, n, s) => {
2346
- const { ref: a, refs: i, required: u, maxLength: d, minLength: p, min: w, max: v, pattern: h, validate: _, name: y, valueAsNumber: A, mount: S, disabled: E } = e._f, g = x(t, y);
2347
- if (!S || E)
2348
- return {};
2349
- const F = i ? i[0] : a, j = (M) => {
2350
- n && F.reportValidity && (F.setCustomValidity(ce(M) ? "" : M || ""), F.reportValidity());
2351
- }, 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 = gr.bind(null, y, r, D), U = (M, V, R, K = ie.maxLength, W = ie.minLength) => {
2352
- const Q = M ? V : R;
2353
- D[y] = {
2354
- type: M ? K : W,
2355
- message: Q,
2356
- ref: a,
2357
- ...se(M ? K : W, Q)
2358
- };
2359
- };
2360
- if (s ? !Array.isArray(g) || !g.length : u && (!Ae && (H || q(g)) || ce(g) && !g || ue && !br(i).isValid || me && !yr(i).isValid)) {
2361
- const { value: M, message: V } = qe(u) ? { value: !!u, message: u } : _e(u);
2362
- if (M && (D[y] = {
2363
- type: ie.required,
2364
- message: V,
2365
- ref: F,
2366
- ...se(ie.required, V)
2367
- }, !r))
2368
- return j(V), D;
2369
- }
2370
- if (!H && (!q(w) || !q(v))) {
2371
- let M, V;
2372
- const R = _e(v), K = _e(w);
2373
- if (!q(g) && !isNaN(g)) {
2374
- const W = a.valueAsNumber || g && +g;
2375
- q(R.value) || (M = W > R.value), q(K.value) || (V = W < K.value);
2376
- } else {
2377
- 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";
2378
- 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));
2379
- }
2380
- if ((M || V) && (U(!!M, R.message, K.message, ie.max, ie.min), !r))
2381
- return j(D[y].message), D;
2382
- }
2383
- if ((d || p) && !H && (te(g) || s && Array.isArray(g))) {
2384
- const M = _e(d), V = _e(p), R = !q(M.value) && g.length > +M.value, K = !q(V.value) && g.length < +V.value;
2385
- if ((R || K) && (U(R, M.message, V.message), !r))
2386
- return j(D[y].message), D;
2387
- }
2388
- if (h && !H && te(g)) {
2389
- const { value: M, message: V } = _e(h);
2390
- if (We(M) && !g.match(M) && (D[y] = {
2391
- type: ie.pattern,
2392
- message: V,
2393
- ref: a,
2394
- ...se(ie.pattern, V)
2395
- }, !r))
2396
- return j(V), D;
2397
- }
2398
- if (_) {
2399
- if (de(_)) {
2400
- const M = await _(g, t), V = Kt(M, F);
2401
- if (V && (D[y] = {
2402
- ...V,
2403
- ...se(ie.validate, V.message)
2404
- }, !r))
2405
- return j(V.message), D;
2406
- } else if (P(_)) {
2407
- let M = {};
2408
- for (const V in _) {
2409
- if (!J(M) && !r)
2410
- break;
2411
- const R = Kt(await _[V](g, t), F, V);
2412
- R && (M = {
2413
- ...R,
2414
- ...se(V, R.message)
2415
- }, j(R.message), r && (D[y] = M));
2416
- }
2417
- if (!J(M) && (D[y] = {
2418
- ref: F,
2419
- ...M
2420
- }, !r))
2421
- return D;
2422
- }
2423
- }
2424
- return j(!0), D;
2425
- };
2426
- function Qn(e, t) {
2427
- const r = t.slice(0, -1).length;
2428
- let n = 0;
2429
- for (; n < r; )
2430
- e = O(e) ? n++ : e[t[n++]];
2431
- return e;
2432
- }
2433
- function Yn(e) {
2434
- for (const t in e)
2435
- if (e.hasOwnProperty(t) && !O(e[t]))
2436
- return !1;
2437
- return !0;
2438
- }
2439
- function $(e, t) {
2440
- const r = Array.isArray(t) ? t : vt(t) ? [t] : mr(t), n = r.length === 1 ? e : Qn(e, r), s = r.length - 1, a = r[s];
2441
- return n && delete n[a], s !== 0 && (P(n) && J(n) || Array.isArray(n) && Yn(n)) && $(e, r.slice(0, -1)), e;
2442
- }
2443
- function lt() {
2444
- let e = [];
2445
- return {
2446
- get observers() {
2447
- return e;
2448
- },
2449
- next: (s) => {
2450
- for (const a of e)
2451
- a.next && a.next(s);
2452
- },
2453
- subscribe: (s) => (e.push(s), {
2454
- unsubscribe: () => {
2455
- e = e.filter((a) => a !== s);
2456
- }
2457
- }),
2458
- unsubscribe: () => {
2459
- e = [];
2460
- }
2461
- };
2462
- }
2463
- var Je = (e) => q(e) || !pr(e);
2464
- function be(e, t) {
2465
- if (Je(e) || Je(t))
2466
- return e === t;
2467
- if (Se(e) && Se(t))
2468
- return e.getTime() === t.getTime();
2469
- const r = Object.keys(e), n = Object.keys(t);
2470
- if (r.length !== n.length)
2471
- return !1;
2472
- for (const s of r) {
2473
- const a = e[s];
2474
- if (!n.includes(s))
2475
- return !1;
2476
- if (s !== "ref") {
2477
- const i = t[s];
2478
- if (Se(a) && Se(i) || P(a) && P(i) || Array.isArray(a) && Array.isArray(i) ? !be(a, i) : a !== i)
2479
- return !1;
2480
- }
2481
- }
2482
- return !0;
2483
- }
2484
- var vr = (e) => e.type === "select-multiple", es = (e) => wt(e) || Be(e), ut = (e) => He(e) && e.isConnected, xr = (e) => {
2485
- for (const t in e)
2486
- if (de(e[t]))
2487
- return !0;
2488
- return !1;
2489
- };
2490
- function Ze(e, t = {}) {
2491
- const r = Array.isArray(e);
2492
- if (P(e) || r)
2493
- for (const n in e)
2494
- Array.isArray(e[n]) || P(e[n]) && !xr(e[n]) ? (t[n] = Array.isArray(e[n]) ? [] : {}, Ze(e[n], t[n])) : q(e[n]) || (t[n] = !0);
2495
- return t;
2496
- }
2497
- function wr(e, t, r) {
2498
- const n = Array.isArray(e);
2499
- if (P(e) || n)
2500
- for (const s in e)
2501
- Array.isArray(e[s]) || P(e[s]) && !xr(e[s]) ? O(t) || Je(r[s]) ? r[s] = Array.isArray(e[s]) ? Ze(e[s], []) : { ...Ze(e[s]) } : wr(e[s], q(t) ? {} : t[s], r[s]) : r[s] = !be(e[s], t[s]);
2502
- return r;
2503
- }
2504
- var ct = (e, t) => wr(e, t, Ze(t)), kr = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: n }) => O(e) ? e : t ? e === "" ? NaN : e && +e : r && te(e) ? new Date(e) : n ? n(e) : e;
2505
- function dt(e) {
2506
- const t = e.ref;
2507
- if (!(e.refs ? e.refs.every((r) => r.disabled) : t.disabled))
2508
- return xt(t) ? t.files : wt(t) ? yr(e.refs).value : vr(t) ? [...t.selectedOptions].map(({ value: r }) => r) : Be(t) ? br(e.refs).value : kr(O(t.value) ? e.ref.value : t.value, e);
2509
- }
2510
- var ts = (e, t, r, n) => {
2511
- const s = {};
2512
- for (const a of e) {
2513
- const i = x(t, a);
2514
- i && L(s, a, i._f);
2515
- }
2516
- return {
2517
- criteriaMode: r,
2518
- names: [...e],
2519
- fields: s,
2520
- shouldUseNativeValidation: n
2521
- };
2522
- }, Me = (e) => O(e) ? e : We(e) ? e.source : P(e) ? We(e.value) ? e.value.source : e.value : e, rs = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate);
2523
- function Ht(e, t, r) {
2524
- const n = x(e, r);
2525
- if (n || vt(r))
2526
- return {
2527
- error: n,
2528
- name: r
2529
- };
2530
- const s = r.split(".");
2531
- for (; s.length; ) {
2532
- const a = s.join("."), i = x(t, a), u = x(e, a);
2533
- if (i && !Array.isArray(i) && r !== a)
2534
- return { name: r };
2535
- if (u && u.type)
2536
- return {
2537
- name: a,
2538
- error: u
2539
- };
2540
- s.pop();
2541
- }
2542
- return {
2543
- name: r
2544
- };
2545
- }
2546
- var ns = (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, ss = (e, t) => !Pe(x(e, t)).length && $(e, t);
2547
- const as = {
2548
- mode: Z.onSubmit,
2549
- reValidateMode: Z.onChange,
2550
- shouldFocusError: !0
2551
- };
2552
- function is(e = {}, t) {
2553
- let r = {
2554
- ...as,
2555
- ...e
2556
- }, n = {
2557
- submitCount: 0,
2558
- isDirty: !1,
2559
- isLoading: de(r.defaultValues),
2560
- isValidating: !1,
2561
- isSubmitted: !1,
2562
- isSubmitting: !1,
2563
- isSubmitSuccessful: !1,
2564
- isValid: !1,
2565
- touchedFields: {},
2566
- dirtyFields: {},
2567
- errors: {},
2568
- disabled: !1
2569
- }, s = {}, a = P(r.defaultValues) || P(r.values) ? oe(r.defaultValues || r.values) || {} : {}, i = r.shouldUnregister ? {} : oe(a), u = {
2570
- action: !1,
2571
- mount: !1,
2572
- watch: !1
2573
- }, d = {
2574
- mount: /* @__PURE__ */ new Set(),
2575
- unMount: /* @__PURE__ */ new Set(),
2576
- array: /* @__PURE__ */ new Set(),
2577
- watch: /* @__PURE__ */ new Set()
2578
- }, p, w = 0;
2579
- const v = {
2580
- isDirty: !1,
2581
- dirtyFields: !1,
2582
- touchedFields: !1,
2583
- isValidating: !1,
2584
- isValid: !1,
2585
- errors: !1
2586
- }, h = {
2587
- values: lt(),
2588
- array: lt(),
2589
- state: lt()
2590
- }, _ = e.resetOptions && e.resetOptions.keepDirtyValues, y = $t(r.mode), A = $t(r.reValidateMode), S = r.criteriaMode === Z.all, E = (o) => (c) => {
2591
- clearTimeout(w), w = setTimeout(o, c);
2592
- }, g = async (o) => {
2593
- if (v.isValid || o) {
2594
- const c = r.resolver ? J((await H()).errors) : await U(s, !0);
2595
- c !== n.isValid && h.state.next({
2596
- isValid: c
2597
- });
2598
- }
2599
- }, F = (o) => v.isValidating && h.state.next({
2600
- isValidating: o
2601
- }), j = (o, c = [], f, k, b = !0, m = !0) => {
2602
- if (k && f) {
2603
- if (u.action = !0, m && Array.isArray(x(s, o))) {
2604
- const C = f(x(s, o), k.argA, k.argB);
2605
- b && L(s, o, C);
2606
- }
2607
- if (m && Array.isArray(x(n.errors, o))) {
2608
- const C = f(x(n.errors, o), k.argA, k.argB);
2609
- b && L(n.errors, o, C), ss(n.errors, o);
2610
- }
2611
- if (v.touchedFields && m && Array.isArray(x(n.touchedFields, o))) {
2612
- const C = f(x(n.touchedFields, o), k.argA, k.argB);
2613
- b && L(n.touchedFields, o, C);
2614
- }
2615
- v.dirtyFields && (n.dirtyFields = ct(a, i)), h.state.next({
2616
- name: o,
2617
- isDirty: V(o, c),
2618
- dirtyFields: n.dirtyFields,
2619
- errors: n.errors,
2620
- isValid: n.isValid
2621
- });
2622
- } else
2623
- L(i, o, c);
2624
- }, D = (o, c) => {
2625
- L(n.errors, o, c), h.state.next({
2626
- errors: n.errors
2627
- });
2628
- }, me = (o, c, f, k) => {
2629
- const b = x(s, o);
2630
- if (b) {
2631
- const m = x(i, o, O(f) ? x(a, o) : f);
2632
- O(m) || k && k.defaultChecked || c ? L(i, o, c ? m : dt(b._f)) : W(o, m), u.mount && g();
2633
- }
2634
- }, ue = (o, c, f, k, b) => {
2635
- let m = !1, C = !1;
2636
- const N = {
2637
- name: o
2638
- };
2639
- if (!f || k) {
2640
- v.isDirty && (C = n.isDirty, n.isDirty = N.isDirty = V(), m = C !== N.isDirty);
2641
- const B = be(x(a, o), c);
2642
- C = x(n.dirtyFields, o), B ? $(n.dirtyFields, o) : L(n.dirtyFields, o, !0), N.dirtyFields = n.dirtyFields, m = m || v.dirtyFields && C !== !B;
2643
- }
2644
- if (f) {
2645
- const B = x(n.touchedFields, o);
2646
- B || (L(n.touchedFields, o, f), N.touchedFields = n.touchedFields, m = m || v.touchedFields && B !== f);
2647
- }
2648
- return m && b && h.state.next(N), m ? N : {};
2649
- }, Ae = (o, c, f, k) => {
2650
- const b = x(n.errors, o), m = v.isValid && ce(c) && n.isValid !== c;
2651
- 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 ? !be(b, f) : b) || !J(k) || m) {
2652
- const C = {
2653
- ...k,
2654
- ...m && ce(c) ? { isValid: c } : {},
2655
- errors: n.errors,
2656
- name: o
2657
- };
2658
- n = {
2659
- ...n,
2660
- ...C
2661
- }, h.state.next(C);
2662
- }
2663
- F(!1);
2664
- }, H = async (o) => r.resolver(i, r.context, ts(o || d.mount, s, r.criteriaMode, r.shouldUseNativeValidation)), se = async (o) => {
2665
- const { errors: c } = await H(o);
2666
- if (o)
2667
- for (const f of o) {
2668
- const k = x(c, f);
2669
- k ? L(n.errors, f, k) : $(n.errors, f);
2670
- }
2671
- else
2672
- n.errors = c;
2673
- return c;
2674
- }, U = async (o, c, f = {
2675
- valid: !0
2676
- }) => {
2677
- for (const k in o) {
2678
- const b = o[k];
2679
- if (b) {
2680
- const { _f: m, ...C } = b;
2681
- if (m) {
2682
- const N = d.array.has(m.name), B = await Gt(b, i, S, r.shouldUseNativeValidation && !c, N);
2683
- if (B[m.name] && (f.valid = !1, c))
2684
- break;
2685
- !c && (x(B, m.name) ? N ? Xn(n.errors, B, m.name) : L(n.errors, m.name, B[m.name]) : $(n.errors, m.name));
2686
- }
2687
- C && await U(C, c, f);
2688
- }
2689
- }
2690
- return f.valid;
2691
- }, M = () => {
2692
- for (const o of d.unMount) {
2693
- const c = x(s, o);
2694
- c && (c._f.refs ? c._f.refs.every((f) => !ut(f)) : !ut(c._f.ref)) && rt(o);
2695
- }
2696
- d.unMount = /* @__PURE__ */ new Set();
2697
- }, V = (o, c) => (o && c && L(i, o, c), !be(kt(), a)), R = (o, c, f) => Zn(o, d, {
2698
- ...u.mount ? i : O(c) ? a : te(o) ? { [o]: c } : c
2699
- }, f, c), K = (o) => Pe(x(u.mount ? i : a, o, e.shouldUnregister ? x(a, o, []) : [])), W = (o, c, f = {}) => {
2700
- const k = x(s, o);
2701
- let b = c;
2702
- if (k) {
2703
- const m = k._f;
2704
- m && (!m.disabled && L(i, o, kr(c, m)), b = He(m.ref) && q(c) ? "" : c, vr(m.ref) ? [...m.ref.options].forEach((C) => C.selected = b.includes(C.value)) : m.refs ? Be(m.ref) ? m.refs.length > 1 ? m.refs.forEach((C) => (!C.defaultChecked || !C.disabled) && (C.checked = Array.isArray(b) ? !!b.find((N) => N === C.value) : b === C.value)) : m.refs[0] && (m.refs[0].checked = !!b) : m.refs.forEach((C) => C.checked = C.value === b) : xt(m.ref) ? m.ref.value = "" : (m.ref.value = b, m.ref.type || h.values.next({
2705
- name: o,
2706
- values: { ...i }
2707
- })));
2708
- }
2709
- (f.shouldDirty || f.shouldTouch) && ue(o, b, f.shouldTouch, f.shouldDirty, !0), f.shouldValidate && tt(o);
2710
- }, Q = (o, c, f) => {
2711
- for (const k in c) {
2712
- const b = c[k], m = `${o}.${k}`, C = x(s, m);
2713
- (d.array.has(o) || !Je(b) || C && !C._f) && !Se(b) ? Q(m, b, f) : W(m, b, f);
2714
- }
2715
- }, ge = (o, c, f = {}) => {
2716
- const k = x(s, o), b = d.array.has(o), m = oe(c);
2717
- L(i, o, m), b ? (h.array.next({
2718
- name: o,
2719
- values: { ...i }
2720
- }), (v.isDirty || v.dirtyFields) && f.shouldDirty && h.state.next({
2721
- name: o,
2722
- dirtyFields: ct(a, i),
2723
- isDirty: V(o, m)
2724
- })) : k && !k._f && !q(m) ? Q(o, m, f) : W(o, m, f), jt(o, d) && h.state.next({ ...n }), h.values.next({
2725
- name: o,
2726
- values: { ...i }
2727
- }), !u.mount && t();
2728
- }, Ve = async (o) => {
2729
- const c = o.target;
2730
- let f = c.name, k = !0;
2731
- const b = x(s, f), m = () => c.type ? dt(b._f) : Un(o), C = (N) => {
2732
- k = Number.isNaN(N) || N === x(i, f, N);
2733
- };
2734
- if (b) {
2735
- let N, B;
2736
- const je = m(), ke = o.type === Pt.BLUR || o.type === Pt.FOCUS_OUT, Vr = !rs(b._f) && !r.resolver && !x(n.errors, f) && !b._f.deps || ns(ke, x(n.touchedFields, f), n.isSubmitted, A, y), st = jt(f, d, ke);
2737
- L(i, f, je), ke ? (b._f.onBlur && b._f.onBlur(o), p && p(0)) : b._f.onChange && b._f.onChange(o);
2738
- const at = ue(f, je, ke, !1), Ir = !J(at) || st;
2739
- if (!ke && h.values.next({
2740
- name: f,
2741
- type: o.type,
2742
- values: { ...i }
2743
- }), Vr)
2744
- return v.isValid && g(), Ir && h.state.next({ name: f, ...st ? {} : at });
2745
- if (!ke && st && h.state.next({ ...n }), F(!0), r.resolver) {
2746
- const { errors: Mt } = await H([f]);
2747
- if (C(je), k) {
2748
- const Mr = Ht(n.errors, s, f), Ft = Ht(Mt, s, Mr.name || f);
2749
- N = Ft.error, f = Ft.name, B = J(Mt);
2750
- }
2751
- } else
2752
- N = (await Gt(b, i, S, r.shouldUseNativeValidation))[f], C(je), k && (N ? B = !1 : v.isValid && (B = await U(s, !0)));
2753
- k && (b._f.deps && tt(b._f.deps), Ae(f, B, N, at));
2754
- }
2755
- }, $e = (o, c) => {
2756
- if (x(n.errors, c) && o.focus)
2757
- return o.focus(), 1;
2758
- }, tt = async (o, c = {}) => {
2759
- let f, k;
2760
- const b = ot(o);
2761
- if (F(!0), r.resolver) {
2762
- const m = await se(O(o) ? o : b);
2763
- f = J(m), k = o ? !b.some((C) => x(m, C)) : f;
2764
- } else
2765
- o ? (k = (await Promise.all(b.map(async (m) => {
2766
- const C = x(s, m);
2767
- return await U(C && C._f ? { [m]: C } : C);
2768
- }))).every(Boolean), !(!k && !n.isValid) && g()) : k = f = await U(s);
2769
- return h.state.next({
2770
- ...!te(o) || v.isValid && f !== n.isValid ? {} : { name: o },
2771
- ...r.resolver || !o ? { isValid: f } : {},
2772
- errors: n.errors,
2773
- isValidating: !1
2774
- }), c.shouldFocus && !k && Ue(s, $e, o ? b : d.mount), k;
2775
- }, kt = (o) => {
2776
- const c = {
2777
- ...a,
2778
- ...u.mount ? i : {}
2779
- };
2780
- return O(o) ? c : te(o) ? x(c, o) : o.map((f) => x(c, f));
2781
- }, _t = (o, c) => ({
2782
- invalid: !!x((c || n).errors, o),
2783
- isDirty: !!x((c || n).dirtyFields, o),
2784
- isTouched: !!x((c || n).touchedFields, o),
2785
- error: x((c || n).errors, o)
2786
- }), Sr = (o) => {
2787
- o && ot(o).forEach((c) => $(n.errors, c)), h.state.next({
2788
- errors: o ? n.errors : {}
2789
- });
2790
- }, St = (o, c, f) => {
2791
- const k = (x(s, o, { _f: {} })._f || {}).ref;
2792
- L(n.errors, o, {
2793
- ...c,
2794
- ref: k
2795
- }), h.state.next({
2796
- name: o,
2797
- errors: n.errors,
2798
- isValid: !1
2799
- }), f && f.shouldFocus && k && k.focus && k.focus();
2800
- }, Cr = (o, c) => de(o) ? h.values.subscribe({
2801
- next: (f) => o(R(void 0, c), f)
2802
- }) : R(o, c, !0), rt = (o, c = {}) => {
2803
- for (const f of o ? ot(o) : d.mount)
2804
- 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);
2805
- h.values.next({
2806
- values: { ...i }
2807
- }), h.state.next({
2808
- ...n,
2809
- ...c.keepDirty ? { isDirty: V() } : {}
2810
- }), !c.keepIsValid && g();
2811
- }, Ct = ({ disabled: o, name: c, field: f, fields: k, value: b }) => {
2812
- if (ce(o)) {
2813
- const m = o ? void 0 : O(b) ? dt(f ? f._f : x(k, c)._f) : b;
2814
- L(i, c, m), ue(c, m, !1, !1, !0);
2815
- }
2816
- }, nt = (o, c = {}) => {
2817
- let f = x(s, o);
2818
- const k = ce(c.disabled);
2819
- return L(s, o, {
2820
- ...f || {},
2821
- _f: {
2822
- ...f && f._f ? f._f : { ref: { name: o } },
2823
- name: o,
2824
- mount: !0,
2825
- ...c
2826
- }
2827
- }), d.mount.add(o), f ? Ct({
2828
- field: f,
2829
- disabled: c.disabled,
2830
- name: o
2831
- }) : me(o, !0, c.value), {
2832
- ...k ? { disabled: c.disabled } : {},
2833
- ...r.progressive ? {
2834
- required: !!c.required,
2835
- min: Me(c.min),
2836
- max: Me(c.max),
2837
- minLength: Me(c.minLength),
2838
- maxLength: Me(c.maxLength),
2839
- pattern: Me(c.pattern)
2840
- } : {},
2841
- name: o,
2842
- onChange: Ve,
2843
- onBlur: Ve,
2844
- ref: (b) => {
2845
- if (b) {
2846
- nt(o, c), f = x(s, o);
2847
- const m = O(b.value) && b.querySelectorAll && b.querySelectorAll("input,select,textarea")[0] || b, C = es(m), N = f._f.refs || [];
2848
- if (C ? N.find((B) => B === m) : m === f._f.ref)
2849
- return;
2850
- L(s, o, {
2851
- _f: {
2852
- ...f._f,
2853
- ...C ? {
2854
- refs: [
2855
- ...N.filter(ut),
2856
- m,
2857
- ...Array.isArray(x(a, o)) ? [{}] : []
2858
- ],
2859
- ref: { type: m.type, name: o }
2860
- } : { ref: m }
2861
- }
2862
- }), me(o, !1, void 0, m);
2863
- } else
2864
- f = x(s, o, {}), f._f && (f._f.mount = !1), (r.shouldUnregister || c.shouldUnregister) && !(Kn(d.array, o) && u.action) && d.unMount.add(o);
2865
- }
2866
- };
2867
- }, Et = () => r.shouldFocusError && Ue(s, $e, d.mount), Er = (o) => {
2868
- ce(o) && (h.state.next({ disabled: o }), Ue(s, (c) => {
2869
- c.disabled = o;
2870
- }, 0, !1));
2871
- }, At = (o, c) => async (f) => {
2872
- f && (f.preventDefault && f.preventDefault(), f.persist && f.persist());
2873
- let k = oe(i);
2874
- if (h.state.next({
2875
- isSubmitting: !0
2876
- }), r.resolver) {
2877
- const { errors: b, values: m } = await H();
2878
- n.errors = b, k = m;
2879
- } else
2880
- await U(s);
2881
- $(n.errors, "root"), J(n.errors) ? (h.state.next({
2882
- errors: {}
2883
- }), await o(k, f)) : (c && await c({ ...n.errors }, f), Et(), setTimeout(Et)), h.state.next({
2884
- isSubmitted: !0,
2885
- isSubmitting: !1,
2886
- isSubmitSuccessful: J(n.errors),
2887
- submitCount: n.submitCount + 1,
2888
- errors: n.errors
2889
- });
2890
- }, Ar = (o, c = {}) => {
2891
- 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 }));
2892
- }, Vt = (o, c = {}) => {
2893
- const f = o ? oe(o) : a, k = oe(f), b = o && !J(o) ? k : a;
2894
- if (c.keepDefaultValues || (a = f), !c.keepValues) {
2895
- if (c.keepDirtyValues || _)
2896
- for (const m of d.mount)
2897
- x(n.dirtyFields, m) ? L(b, m, x(i, m)) : ge(m, x(b, m));
2898
- else {
2899
- if (yt && O(o))
2900
- for (const m of d.mount) {
2901
- const C = x(s, m);
2902
- if (C && C._f) {
2903
- const N = Array.isArray(C._f.refs) ? C._f.refs[0] : C._f.ref;
2904
- if (He(N)) {
2905
- const B = N.closest("form");
2906
- if (B) {
2907
- B.reset();
2908
- break;
2909
- }
2910
- }
2911
- }
2912
- }
2913
- s = {};
2914
- }
2915
- i = e.shouldUnregister ? c.keepDefaultValues ? oe(a) : {} : oe(b), h.array.next({
2916
- values: { ...b }
2917
- }), h.values.next({
2918
- values: { ...b }
2919
- });
2920
- }
2921
- d = {
2922
- mount: /* @__PURE__ */ new Set(),
2923
- unMount: /* @__PURE__ */ new Set(),
2924
- array: /* @__PURE__ */ new Set(),
2925
- watch: /* @__PURE__ */ new Set(),
2926
- watchAll: !1,
2927
- focus: ""
2928
- }, !u.mount && t(), u.mount = !v.isValid || !!c.keepIsValid, u.watch = !!e.shouldUnregister, h.state.next({
2929
- submitCount: c.keepSubmitCount ? n.submitCount : 0,
2930
- isDirty: c.keepDirty ? n.isDirty : !!(c.keepDefaultValues && !be(o, a)),
2931
- isSubmitted: c.keepIsSubmitted ? n.isSubmitted : !1,
2932
- dirtyFields: c.keepDirtyValues ? n.dirtyFields : c.keepDefaultValues && o ? ct(a, o) : {},
2933
- touchedFields: c.keepTouched ? n.touchedFields : {},
2934
- errors: c.keepErrors ? n.errors : {},
2935
- isSubmitSuccessful: c.keepIsSubmitSuccessful ? n.isSubmitSuccessful : !1,
2936
- isSubmitting: !1
2937
- });
2938
- }, It = (o, c) => Vt(de(o) ? o(i) : o, c);
2939
- return {
2940
- control: {
2941
- register: nt,
2942
- unregister: rt,
2943
- getFieldState: _t,
2944
- handleSubmit: At,
2945
- setError: St,
2946
- _executeSchema: H,
2947
- _getWatch: R,
2948
- _getDirty: V,
2949
- _updateValid: g,
2950
- _removeUnmounted: M,
2951
- _updateFieldArray: j,
2952
- _updateDisabledField: Ct,
2953
- _getFieldArray: K,
2954
- _reset: Vt,
2955
- _resetDefaultValues: () => de(r.defaultValues) && r.defaultValues().then((o) => {
2956
- It(o, r.resetOptions), h.state.next({
2957
- isLoading: !1
2958
- });
2959
- }),
2960
- _updateFormState: (o) => {
2961
- n = {
2962
- ...n,
2963
- ...o
2964
- };
2965
- },
2966
- _disableForm: Er,
2967
- _subjects: h,
2968
- _proxyFormState: v,
2969
- get _fields() {
2970
- return s;
2971
- },
2972
- get _formValues() {
2973
- return i;
2974
- },
2975
- get _state() {
2976
- return u;
2977
- },
2978
- set _state(o) {
2979
- u = o;
2980
- },
2981
- get _defaultValues() {
2982
- return a;
2983
- },
2984
- get _names() {
2985
- return d;
2986
- },
2987
- set _names(o) {
2988
- d = o;
2989
- },
2990
- get _formState() {
2991
- return n;
2992
- },
2993
- set _formState(o) {
2994
- n = o;
2995
- },
2996
- get _options() {
2997
- return r;
2998
- },
2999
- set _options(o) {
3000
- r = {
3001
- ...r,
3002
- ...o
3003
- };
3004
- }
3005
- },
3006
- trigger: tt,
3007
- register: nt,
3008
- handleSubmit: At,
3009
- watch: Cr,
3010
- setValue: ge,
3011
- getValues: kt,
3012
- reset: It,
3013
- resetField: Ar,
3014
- clearErrors: Sr,
3015
- unregister: rt,
3016
- setError: St,
3017
- setFocus: (o, c = {}) => {
3018
- const f = x(s, o), k = f && f._f;
3019
- if (k) {
3020
- const b = k.refs ? k.refs[0] : k.ref;
3021
- b.focus && (b.focus(), c.shouldSelect && b.select());
3022
- }
3023
- },
3024
- getFieldState: _t
3025
- };
3026
- }
3027
- function Ye(e = {}) {
3028
- const t = Y.useRef(), r = Y.useRef(), [n, s] = Y.useState({
3029
- isDirty: !1,
3030
- isValidating: !1,
3031
- isLoading: de(e.defaultValues),
3032
- isSubmitted: !1,
3033
- isSubmitting: !1,
3034
- isSubmitSuccessful: !1,
3035
- isValid: !1,
3036
- submitCount: 0,
3037
- dirtyFields: {},
3038
- touchedFields: {},
3039
- errors: {},
3040
- disabled: !1,
3041
- defaultValues: de(e.defaultValues) ? void 0 : e.defaultValues
3042
- });
3043
- t.current || (t.current = {
3044
- ...is(e, () => s((i) => ({ ...i }))),
3045
- formState: n
3046
- });
3047
- const a = t.current.control;
3048
- return a._options = e, Jn({
3049
- subject: a._subjects.state,
3050
- next: (i) => {
3051
- Wn(i, a._proxyFormState, a._updateFormState, !0) && s({ ...a._formState });
3052
- }
3053
- }), Y.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), Y.useEffect(() => {
3054
- if (a._proxyFormState.isDirty) {
3055
- const i = a._getDirty();
3056
- i !== n.isDirty && a._subjects.state.next({
3057
- isDirty: i
3058
- });
3059
- }
3060
- }, [a, n.isDirty]), Y.useEffect(() => {
3061
- e.values && !be(e.values, r.current) ? (a._reset(e.values, a._options.resetOptions), r.current = e.values) : a._resetDefaultValues();
3062
- }, [e.values, a]), Y.useEffect(() => {
3063
- a._state.mount || (a._updateValid(), a._state.mount = !0), a._state.watch && (a._state.watch = !1, a._subjects.state.next({ ...a._formState })), a._removeUnmounted();
3064
- }), t.current.formState = Hn(n, a), t.current;
3065
- }
3066
- var Wt = function(e, t, r) {
3067
- if (e && "reportValidity" in e) {
3068
- var n = x(r, t);
3069
- e.setCustomValidity(n && n.message || ""), e.reportValidity();
3070
- }
3071
- }, os = function(e, t) {
3072
- var r = function(s) {
3073
- var a = t.fields[s];
3074
- a && a.ref && "reportValidity" in a.ref ? Wt(a.ref, s, e) : a.refs && a.refs.forEach(function(i) {
3075
- return Wt(i, s, e);
3076
- });
3077
- };
3078
- for (var n in t.fields)
3079
- r(n);
3080
- }, ls = function(e, t) {
3081
- t.shouldUseNativeValidation && os(e, t);
3082
- var r = {};
3083
- for (var n in e) {
3084
- var s = x(t.fields, n), a = Object.assign(e[n] || {}, { ref: s && s.ref });
3085
- if (cs(t.names || Object.keys(e), n)) {
3086
- var i = Object.assign({}, us(x(r, n)));
3087
- L(i, "root", a), L(r, n, i);
3088
- } else
3089
- L(r, n, a);
3090
- }
3091
- return r;
3092
- }, us = function(e) {
3093
- return Array.isArray(e) ? e.filter(Boolean) : [];
3094
- }, cs = function(e, t) {
3095
- return e.some(function(r) {
3096
- return r.startsWith(t + ".");
3097
- });
3098
- }, ds = function(e, t) {
3099
- for (var r = {}; e.issues.length; ) {
3100
- var n = e.issues[0];
3101
- if (n.path) {
3102
- var s = n.path.map(function(u) {
3103
- return u.key;
3104
- }).join(".");
3105
- if (r[s] || (r[s] = { message: n.message, type: n.validation }), t) {
3106
- var a = r[s].types, i = a && a[n.validation];
3107
- r[s] = gr(s, t, r, n.validation, i ? [].concat(i, n.message) : n.message);
3108
- }
3109
- e.issues.shift();
3110
- }
3111
- }
3112
- return r;
3113
- }, et = function(e, t, r) {
3114
- return r === void 0 && (r = {}), function(n, s, a) {
3115
- try {
3116
- return Promise.resolve(function(i, u) {
3117
- try {
3118
- var d = function() {
3119
- function p(v) {
3120
- return { values: r.raw ? n : v, errors: {} };
3121
- }
3122
- var w = Object.assign({}, { abortEarly: !1, abortPipeEarly: !1 }, t);
3123
- return r.mode === "sync" ? p(sr(e, n, w)) : Promise.resolve(Or(e, n, w)).then(p);
3124
- }();
3125
- } catch (p) {
3126
- return u(p);
3127
- }
3128
- return d && d.then ? d.then(void 0, u) : d;
3129
- }(0, function(i) {
3130
- if (i instanceof Br)
3131
- return { values: {}, errors: ls(ds(i, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a) };
3132
- throw i;
3133
- }));
3134
- } catch (i) {
3135
- return Promise.reject(i);
3136
- }
3137
- };
3138
- };
3139
- const Jt = 27, Zt = 12, Xt = 10, fs = Ce("enum"), hs = (e, t) => {
3140
- const r = {
3141
- min: e.minSelected ?? 0,
3142
- max: e.maxSelected ?? e.options.length
3143
- };
3144
- return et(he({
3145
- checked: ye(Pr(X(), $r()), ar((n) => Object.entries(n).filter(([s, a]) => a).map(([s, a]) => s)), ze(r.max, t("validation_multiple_choice_max", {
3146
- count: r.max
3147
- })), De(r.min, t("validation_multiple_choice_min", {
3148
- count: r.min
3149
- })))
3150
- }));
3151
- }, ps = nr(({
3152
- option: e,
3153
- ...t
3154
- }, r) => l(ve, {
3155
- children: [l("input", {
3156
- class: "peer sr-only h-full",
3157
- type: "checkbox",
3158
- ...t,
3159
- ref: r
3160
- }), l("label", {
3161
- 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",
3162
- htmlFor: t.id,
3163
- children: e.label
3164
- })]
3165
- })), Qt = Xe("gutter-stable flex w-full flex-1 flex-wrap gap-2 overflow-y-auto rounded-xl p-2.5 pr-4", {
3166
- variants: {
3167
- variant: {
3168
- // In cases where there is only one option, we want to center it
3169
- singleOption: "justify-center",
3170
- // Two choices with exactly 1 min 1 max
3171
- booleanLike: cr
3172
- }
3173
- }
3174
- }), ms = ({
3175
- input: e,
3176
- onSubmitSuccess: t
3177
- }) => {
3178
- var w, v;
3179
- 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, {
3180
- t: a
3181
- } = G(), {
3182
- register: i,
3183
- handleSubmit: u,
3184
- formState: {
3185
- errors: d
3186
- }
3187
- } = Ye({
3188
- defaultValues: {
3189
- checked: n ? {} : fs(r) ? Object.fromEntries(r.value.map((h) => [h, !0])) : {}
3190
- },
3191
- resolver: hs(e.config, a)
3192
- }), p = bt();
3193
- return s ? l("ul", {
3194
- style: {
3195
- maxHeight: 6.5 * Jt + 5 * Zt + 2 * Xt
3196
- },
3197
- class: Qt({
3198
- variant: "booleanLike"
3199
- }),
3200
- children: e.config.options.map((h, _) => l("li", {
3201
- class: dr,
3202
- children: l(fr, {
3203
- type: "submit",
3204
- ref: (y) => {
3205
- y && _ === 0 && (p.current = y);
3206
- },
3207
- label: h.label,
3208
- value: "true",
3209
- onClick: () => t({
3210
- type: "enum",
3211
- value: [h.value]
3212
- })
3213
- })
3214
- }, h.value))
3215
- }) : l("form", {
3216
- noValidate: !0,
3217
- onSubmit: (h) => u((_) => {
3218
- const y = _.checked;
3219
- t({
3220
- type: "enum",
3221
- value: y
3222
- });
3223
- })(h),
3224
- children: [l("div", {
3225
- class: "flex items-center gap-1",
3226
- children: [l("ul", {
3227
- style: {
3228
- maxHeight: 6.5 * Jt + 5 * Zt + 2 * Xt
3229
- },
3230
- class: Qt({
3231
- variant: e.config.options.length === 1 ? "singleOption" : void 0
3232
- }),
3233
- children: e.config.options.map((h, _) => {
3234
- const y = `checked.${h.value}`, {
3235
- ref: A,
3236
- ...S
3237
- } = i(y);
3238
- return l("li", {
3239
- class: "relative",
3240
- children: l(ps, {
3241
- option: h,
3242
- autoFocus: _ === 0,
3243
- ref: (E) => {
3244
- E && _ === 0 && (p.current = E), A(E);
3245
- },
3246
- id: y,
3247
- ...S,
3248
- onClick: n ? () => t({
3249
- type: "enum",
3250
- value: [h.value]
3251
- }) : void 0
3252
- })
3253
- }, h.value);
3254
- })
3255
- }), l("div", {
3256
- class: "flex flex-col items-center gap-2 pr-2.5 pt-2.5",
3257
- children: [n ? null : l(xe, {}), e.config.minSelected === 0 && l(we, {
3258
- class: "relative",
3259
- type: "button",
3260
- onClick: () => t({
3261
- type: "enum",
3262
- value: []
3263
- })
3264
- })]
3265
- })]
3266
- }), l("div", {
3267
- class: "px-1",
3268
- children: l(Ee, {
3269
- error: (v = d.checked) == null ? void 0 : v.root
3270
- })
3271
- })]
3272
- });
3273
- }, gs = Ce("number"), bs = (e, t) => {
3274
- const r = e.min ?? Number.MIN_SAFE_INTEGER, n = e.max ?? Number.MAX_SAFE_INTEGER, s = e.decimalCases ?? 0;
3275
- return et(he({
3276
- number: ye(qr(t("validation_number")), Ur(r, t("validation_number_min", {
3277
- min: r
3278
- })), zr(n, t("validation_number_max", {
3279
- max: n
3280
- })), jr((a) => a === Number(a.toFixed(s)), t("validation_number_decimal_cases", {
3281
- count: s
3282
- })))
3283
- }));
3284
- }, ys = ({
3285
- input: e,
3286
- onSubmitSuccess: t
3287
- }) => {
3288
- var v;
3289
- const r = e.config.defaultValue, n = e.key ? (v = I.current$.value.flow) == null ? void 0 : v.data.submissions[e.key] : void 0, {
3290
- t: s
3291
- } = G(), {
3292
- register: a,
3293
- handleSubmit: i,
3294
- formState: {
3295
- errors: u
3296
- }
3297
- } = Ye({
3298
- defaultValues: {
3299
- number: r ? Number(r) : gs(n) ? n.value : void 0
3300
- },
3301
- resolver: bs(e.config, s)
3302
- }), {
3303
- ref: d,
3304
- ...p
3305
- } = a("number", {
3306
- required: !e.config.optional,
3307
- valueAsNumber: !0
3308
- }), w = re();
3309
- return pe(() => {
3310
- w.current && (w.current.focus(), w.current.select());
3311
- }, []), l("form", {
3312
- class: "flex flex-col gap-1 p-2.5",
3313
- onSubmit: i((h) => {
3314
- h.number !== void 0 && t({
3315
- type: "number",
3316
- value: h.number
3317
- });
3318
- }),
3319
- children: [l("div", {
3320
- class: "flex items-center gap-2",
3321
- children: [l("div", {
3322
- class: "relative min-w-0 flex-grow",
3323
- children: [l("input", {
3324
- ...p,
3325
- id: "chat-input",
3326
- autocomplete: "off",
3327
- autoCapitalize: "off",
3328
- autoCorrect: "off",
3329
- autoFocus: !0,
3330
- ref: (h) => {
3331
- h && (w.current = h), d(h);
3332
- },
3333
- type: "text",
3334
- min: e.config.min,
3335
- max: e.config.max,
3336
- class: Oe({
3337
- optional: e.config.optional,
3338
- className: "[type=number:-webkit-inner-spin-button] w-full rounded-full [-webkit-outer-spin-button:none]"
3339
- }),
3340
- placeholder: e.config.placeholder
3341
- }), e.config.optional && l(we, {
3342
- class: "absolute bottom-0 right-0.5 top-0",
3343
- onClick: () => t(null)
3344
- })]
3345
- }), l(xe, {})]
3346
- }), l(Ee, {
3347
- error: u.number
3348
- })]
3349
- });
3350
- }, vs = (e) => {
3351
- if (e === "")
3352
- return {
3353
- countryCode: "",
3354
- phoneNumber: ""
3355
- };
3356
- const t = Object.entries(gt).find((s) => e.startsWith(s[1])), r = t ? t[1] : "", n = e.replace(r, "");
3357
- return /^\d+$/.test(n) ? {
3358
- countryCode: r,
3359
- phoneNumber: n
3360
- } : {
3361
- countryCode: "",
3362
- phoneNumber: ""
3363
- };
3364
- }, xs = "44", ws = /^[0-9 ]+$/, ks = Ce("string"), _s = Ce("phone"), Ss = (e) => {
3365
- const t = ye(X(e("validation_country_code")), Kr(ws, e("validation_country_code"))), r = ye(X(e("validation_phone")), De(1, e("validation_phone")), ar((n) => n.replace(/[^0-9]/g, "")));
3366
- return et(he({
3367
- countryCode: t,
3368
- phoneNumber: r
3369
- }));
3370
- }, Cs = ({
3371
- input: e,
3372
- onSubmitSuccess: t
3373
- }) => {
3374
- var A;
3375
- const r = e.key ? (A = I.current$.value.flow) == null ? void 0 : A.data.submissions[e.key] : void 0, {
3376
- t: n
3377
- } = G(), [s, a] = ee(), i = ks(r) ? vs(r.value) : _s(r) ? r.value : void 0, {
3378
- register: u,
3379
- handleSubmit: d,
3380
- formState: {
3381
- errors: p
3382
- },
3383
- watch: w
3384
- } = Ye({
3385
- defaultValues: {
3386
- countryCode: (i == null ? void 0 : i.countryCode) ?? e.config.defaultValue.countryCode ?? xs,
3387
- phoneNumber: (i == null ? void 0 : i.phoneNumber) ?? e.config.defaultValue.phoneNumber ?? ""
3388
- },
3389
- resolver: Ss(n)
3390
- }), {
3391
- ref: v,
3392
- ...h
3393
- } = u("phoneNumber", {
3394
- required: !e.config.optional
3395
- }), _ = re(), y = w("countryCode");
3396
- return pe(() => {
3397
- _.current && (_.current.focus(), _.current.select());
3398
- }, []), l("form", {
3399
- noValidate: !0,
3400
- class: "flex flex-col gap-1 p-2.5",
3401
- onSubmit: d((S) => {
3402
- const E = S.phoneNumber.replace(/[^0-9]/g, ""), g = S.countryCode.replace(/[^0-9]/g, "");
3403
- a(void 0);
3404
- const F = e.config.minChars ?? 7;
3405
- if (E.length + g.length < F)
3406
- return a(n("validation_phone_min_chars", {
3407
- count: F
3408
- }));
3409
- e.config.submissionFormat === "phone" ? t({
3410
- type: "phone",
3411
- value: {
3412
- countryCode: g,
3413
- phoneNumber: E
3414
- }
3415
- }) : t({
3416
- type: "string",
3417
- value: y + S.phoneNumber
3418
- });
3419
- }),
3420
- children: [l("div", {
3421
- class: "flex items-center gap-2",
3422
- children: [l("div", {
3423
- class: "relative flex min-w-0 flex-1 flex-grow gap-2",
3424
- children: [l("label", {
3425
- 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",
3426
- htmlFor: `isdk_phone_${e.key}`,
3427
- children: [l("span", {
3428
- children: ["+", y]
3429
- }), l("select", {
3430
- ...u("countryCode", {}),
3431
- id: `isdk_phone_${e.key}`,
3432
- class: "absolute inset-0 opacity-0",
3433
- children: Object.entries(gt).map(([S, E]) => l("option", {
3434
- value: E,
3435
- children: [S, " (+", E, ")"]
3436
- }, S))
3437
- })]
3438
- }), l("input", {
3439
- ...h,
3440
- id: "chat-input",
3441
- type: "tel",
3442
- inputMode: "tel",
3443
- autocomplete: "off",
3444
- autoCapitalize: "off",
3445
- autoCorrect: "off",
3446
- autoFocus: !0,
3447
- ref: (S) => {
3448
- S && (_.current = S), v(S);
3449
- },
3450
- class: Oe({
3451
- optional: e.config.optional,
3452
- className: "min-w-0 flex-1 rounded-r-full"
3453
- }),
3454
- placeholder: e.config.placeholder
3455
- }), e.config.optional && l(we, {
3456
- class: "absolute bottom-0 right-1 top-0",
3457
- onClick: () => t(null)
3458
- })]
3459
- }), l(xe, {})]
3460
- }), l(Ee, {
3461
- error: p.countryCode || p.phoneNumber || {
3462
- message: s
3463
- }
3464
- })]
3465
- });
3466
- }, Es = ({
3467
- input: e,
3468
- onSubmitSuccess: t
3469
- }) => l("div", {
3470
- class: "flex flex-col items-center py-3",
3471
- children: l("button", {
3472
- 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",
3473
- name: e.key,
3474
- onClick: () => {
3475
- t(null);
3476
- },
3477
- children: l("span", {
3478
- class: "flex items-center gap-1.5",
3479
- children: [l("span", {
3480
- class: "inline-flex items-center text-sm font-medium",
3481
- children: e.config.label || "Submit"
3482
- }), l("svg", {
3483
- stroke: "currentColor",
3484
- "stroke-width": "1.5",
3485
- width: "16",
3486
- height: "16",
3487
- viewBox: "0 0 16 16",
3488
- fill: "none",
3489
- xmlns: "http://www.w3.org/2000/svg",
3490
- children: [l("path", {
3491
- d: "M4 8L8 4L12 8"
3492
- }), l("path", {
3493
- d: "M8 4V13"
3494
- })]
3495
- })]
3496
- })
3497
- })
3498
- }), As = {
3499
- email: {
3500
- type: "email",
3501
- inputMode: "email",
3502
- formNoValidate: !0
3503
- },
3504
- text: {
3505
- type: "text",
3506
- inputMode: "text"
3507
- },
3508
- url: {
3509
- type: "url",
3510
- inputMode: "url",
3511
- formNoValidate: !0
3512
- }
3513
- }, Vs = Ce("string"), Is = (e, t) => {
3514
- const r = {
3515
- maxLength: t("validation_max_chars", {
3516
- count: e.maxChars ?? 999
3517
- }),
3518
- minLength: t("validation_min_chars", {
3519
- count: e.minChars ?? 1
3520
- })
3521
- };
3522
- return et(he({
3523
- text: {
3524
- email: ye(X(t("validation_email")), Gr(t("validation_email")), De(e.minChars ?? 1, r.minLength), ze(e.maxChars ?? 1 / 0, r.maxLength)),
3525
- text: ye(X(), De(e.minChars ?? 1, r.minLength), ze(e.maxChars ?? 1 / 0, r.maxLength)),
3526
- url: ye(X(t("validation_url")), Hr(t("validation_url")), De(e.minChars ?? 1, r.minLength), ze(e.maxChars ?? 1 / 0, r.maxLength))
3527
- }[e.format]
3528
- }));
3529
- }, Ms = ({
3530
- input: e,
3531
- onSubmitSuccess: t
3532
- }) => {
3533
- var v;
3534
- const {
3535
- t: r
3536
- } = G(), n = e.key ? (v = I.current$.value.flow) == null ? void 0 : v.data.submissions[e.key] : void 0, s = e.config.defaultValue, {
3537
- register: a,
3538
- handleSubmit: i,
3539
- formState: {
3540
- errors: u
3541
- }
3542
- } = Ye({
3543
- defaultValues: {
3544
- text: s || (Vs(n) ? n.value : "")
3545
- },
3546
- resolver: Is(e.config, r)
3547
- }), {
3548
- ref: d,
3549
- ...p
3550
- } = a("text", {
3551
- required: !e.config.optional
3552
- }), w = re();
3553
- return pe(() => {
3554
- w.current && (w.current.focus(), w.current.select());
3555
- }, []), l("form", {
3556
- noValidate: !0,
3557
- class: "flex flex-col gap-1 p-2.5",
3558
- onSubmit: i((h) => {
3559
- t({
3560
- type: "string",
3561
- value: h.text
3562
- });
3563
- }),
3564
- children: [l("div", {
3565
- class: "flex items-center gap-2",
3566
- children: [l("div", {
3567
- class: "relative min-w-0 flex-1",
3568
- children: [l("input", {
3569
- id: "chat-input",
3570
- ...p,
3571
- ...As[e.config.format],
3572
- autocomplete: "off",
3573
- autoCapitalize: "off",
3574
- autoCorrect: "off",
3575
- autoFocus: !0,
3576
- ref: (h) => {
3577
- h && (w.current = h), d(h);
3578
- },
3579
- placeholder: e.config.placeholder,
3580
- class: Oe({
3581
- optional: !!e.config.optional,
3582
- className: "w-full rounded-full"
3583
- })
3584
- }), e.config.optional && l(we, {
3585
- class: "absolute bottom-0 right-0.5 top-0",
3586
- onClick: () => t(null)
3587
- })]
3588
- }), l(xe, {})]
3589
- }), l(Ee, {
3590
- error: u.text
3591
- })]
3592
- });
3593
- }, Fs = {
3594
- text: Ms,
3595
- phone: Cs,
3596
- "multiple-choice": ms,
3597
- boolean: Dn,
3598
- file: zn,
3599
- submit: Es,
3600
- address: Fn,
3601
- number: ys
3602
- }, Ls = ({
3603
- logger: e
3604
- }) => {
3605
- var a;
3606
- const t = (a = I.current$.value.flow) == null ? void 0 : a.data.currentInput, [r, n] = vn(), s = re(null);
3607
- return I.inputHeight$.value = n.height, le(() => {
3608
- const i = s.current;
3609
- if (i)
3610
- return i.addEventListener("transitionstart", z.scrollToEnd.smooth), i.addEventListener("transitioncancel", z.scrollToEnd.smooth), i.addEventListener("transitionend", z.scrollToEnd.smooth), () => {
3611
- i.removeEventListener("transitionstart", z.scrollToEnd.smooth), i.removeEventListener("transitioncancel", z.scrollToEnd.smooth), i.removeEventListener("transitionend", z.scrollToEnd.smooth);
3612
- };
3613
- }, []), l("div", {
3614
- ref: s,
3615
- class: "ease-expo-out absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-xl transition-all duration-700 will-change-[height]",
3616
- style: {
3617
- height: n.height
3618
- },
3619
- children: l("div", {
3620
- ref: r,
3621
- class: "border-divider flex flex-col justify-end border-t",
3622
- children: t ? (() => {
3623
- const i = Fs[t.type];
3624
- return l(i, {
3625
- logger: e,
3626
- onSubmitSuccess: z.onSubmitSuccessFn$.value,
3627
- input: t
3628
- });
3629
- })() : l("div", {
3630
- class: "flex items-center gap-2 p-2.5",
3631
- children: [l("input", {
3632
- "aria-hidden": "true",
3633
- id: "chat-input",
3634
- class: Oe({
3635
- optional: !1,
3636
- className: "flex-grow rounded-full"
3637
- }),
3638
- disabled: !0
3639
- }), l(xe, {
3640
- disabled: !0,
3641
- "aria-hidden": "true",
3642
- tabIndex: -1
3643
- })]
3644
- })
3645
- })
3646
- });
3647
- };
3648
- var Ns = function(e) {
3649
- return e instanceof RegExp;
3650
- }, Ts = function(t) {
3651
- var r = /[\\^$.*+?()[\]{}|]/g, n = RegExp(r.source);
3652
- return t && n.test(t) ? t.replace(r, "\\$&") : t;
3653
- }, _r = function(e) {
3654
- return typeof e == "string";
3655
- }, Ds = function(e) {
3656
- var t = [];
3657
- return e.forEach(function(r) {
3658
- Array.isArray(r) ? t = t.concat(r) : t.push(r);
3659
- }), t;
3660
- };
3661
- function Rs(e, t, r) {
3662
- var n = 0, s = 0;
3663
- if (e === "")
3664
- return e;
3665
- if (!e || !_r(e))
3666
- throw new TypeError("First argument to react-string-replace#replaceString must be a string");
3667
- var a = t;
3668
- Ns(a) || (a = new RegExp("(" + Ts(a) + ")", "gi"));
3669
- for (var i = e.split(a), u = 1, d = i.length; u < d; u += 2) {
3670
- if (i[u] === void 0 || i[u - 1] === void 0) {
3671
- console.warn("reactStringReplace: Encountered undefined value during string replacement. Your RegExp may not be working the way you expect.");
3672
- continue;
3673
- }
3674
- s = i[u].length, n += i[u - 1].length, i[u] = r(i[u], u, n), n += s;
3675
- }
3676
- return i;
3677
- }
3678
- var Os = function(t, r, n) {
3679
- return Array.isArray(t) || (t = [t]), Ds(t.map(function(s) {
3680
- return _r(s) ? Rs(s, r, n) : s;
3681
- }));
3682
- };
3683
- const Fe = /* @__PURE__ */ rr(Os), Bs = /(\[[^\]]+\]\([^)]+\))/g, Ps = /\[([^\]]+)\]\(([^)]+)\)/, $s = /(https?:\/\/[^\s]+)/g, js = /_(.*?)_/g, zs = /\*\*(.*?)\*\*/g, Us = /\\n|\n/g, Yt = "text-accent-10 hover:text-accent-11 no-underline underline-offset-2 hover:underline", qs = (e) => {
3684
- const t = Fe(e, Bs, (i, u) => {
3685
- const [, d, p] = i.match(Ps) ?? [];
3686
- return p ? l("a", {
3687
- class: Yt,
3688
- href: p,
3689
- children: d ?? p
3690
- }, p + u) : l("span", {
3691
- children: "INVALID LINK"
3692
- });
3693
- }), r = Fe(t, $s, (i, u) => l("a", {
3694
- class: Yt,
3695
- href: i,
3696
- children: i
3697
- }, i + u)), n = Fe(r, js, (i, u) => l("em", {
3698
- children: i
3699
- }, i + u)), s = Fe(n, zs, (i, u) => l("strong", {
3700
- children: i
3701
- }, i + u));
3702
- return Fe(s, Us, (i, u) => l("br", {}, `br-${u}`));
3703
- }, Ks = 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", {
3704
- variants: {
3705
- side: {
3706
- left: "bg-bubble-weak-bg text-neutral-12 shadow-surface-sm outline outline-1 outline-bubble-weak rounded-bl-md",
3707
- right: "ml-auto bg-accent-9 text-white rounded-br-md shadow-surface-sm shadow-bubble-strong-shadow"
3708
- },
3709
- animate: {
3710
- true: "animate-bubble-in",
3711
- false: ""
3712
- }
3713
- },
3714
- defaultVariants: {
3715
- side: "left"
3716
- }
3717
- }), Gs = ({
3718
- children: e,
3719
- className: t,
3720
- animate: r,
3721
- side: n,
3722
- ...s
3723
- }) => l("p", {
3724
- style: {
3725
- transformOrigin: n === "left" ? "0% 50%" : "100% 50%"
3726
- },
3727
- class: Ks({
3728
- className: t,
3729
- side: n,
3730
- animate: r
3731
- }),
3732
- ...s,
3733
- children: e
3734
- }), Hs = ({
3735
- message: e
3736
- }) => l("div", {
3737
- class: "bg-accent-3 flex w-full items-center justify-center overflow-hidden rounded-xl px-2 py-2",
3738
- children: l("a", {
3739
- onClick: e.onClick,
3740
- 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",
3741
- target: "_blank",
3742
- href: e.href,
3743
- children: [e.text, l("svg", {
3744
- class: "flex-none",
3745
- width: "15",
3746
- height: "15",
3747
- viewBox: "0 0 15 15",
3748
- fill: "none",
3749
- xmlns: "http://www.w3.org/2000/svg",
3750
- children: l("path", {
3751
- 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",
3752
- fill: "currentColor",
3753
- "fill-rule": "evenodd",
3754
- "clip-rule": "evenodd"
3755
- })
3756
- })]
3757
- })
3758
- }), Ws = ({
3759
- className: e,
3760
- ...t
3761
- }) => (le(() => {
3762
- z.scrollToEnd.smooth();
3763
- }), l("div", {
3764
- "aria-hidden": !0,
3765
- children: z.isBotTyping$.value === !0 ? l("div", {
3766
- "aria-label": "Typing…",
3767
- class: Re("flex gap-1 p-4", e),
3768
- ...t,
3769
- children: Array.from({
3770
- length: 3
3771
- }, (r, n) => l("div", {
3772
- class: "bg-accent-9 h-1.5 w-1.5 animate-bounce rounded-full",
3773
- style: {
3774
- animationDelay: `${-n * 200}ms`
3775
- }
3776
- }))
3777
- }) : void 0
3778
- })), Js = {
3779
- bot: "left",
3780
- user: "right"
3781
- }, Zs = 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)]", {
3782
- variants: {
3783
- variant: {
3784
- info: "text-neutral-8",
3785
- warning: "text-[#FFC107]",
3786
- error: "text-error-9",
3787
- success: "text-[#4CAF50]"
3788
- }
3789
- }
3790
- }), Xs = ({
3791
- lastSentMessageFooter: e
3792
- }) => {
3793
- var r;
3794
- const t = ((r = I.current$.value.flow) == null ? void 0 : r.data.messages) ?? [];
3795
- return le(() => {
3796
- z.scrollToEnd.smooth();
3797
- }, [t.length]), l("ol", {
3798
- "aria-label": "Chat messages",
3799
- class: "mt-auto flex flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",
3800
- children: [t.map((n, s) => l(ve, {
3801
- children: l("li", {
3802
- class: "flex",
3803
- children: Ge(n).with({
3804
- type: "system"
3805
- }, (a) => l("p", {
3806
- class: Zs({
3807
- variant: a.variant
3808
- }),
3809
- children: a.text
3810
- })).with({
3811
- type: "text",
3812
- author: T.union("bot", "user")
3813
- }, (a) => {
3814
- 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" ? qs(a.text) : a.text;
3815
- return l(ve, {
3816
- children: [i ? e : null, l(Gs, {
3817
- animate: u,
3818
- side: Js[a.author],
3819
- children: d
3820
- }, s)]
3821
- });
3822
- }).with({
3823
- type: "link"
3824
- }, (a) => l(Hs, {
3825
- message: a
3826
- })).with({
3827
- type: "image"
3828
- }, (a) => l("img", {
3829
- class: "shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",
3830
- src: a.url,
3831
- style: {
3832
- aspectRatio: a.width / a.height
3833
- }
3834
- })).with({
3835
- type: "file"
3836
- }, (a) => l(Pn, {
3837
- class: a.author === "bot" ? void 0 : "ml-auto",
3838
- file: {
3839
- name: a.fileName,
3840
- sizeKb: a.fileSizeKb
3841
- }
3842
- })).with({
3843
- type: "loading"
3844
- }, (a) => {
3845
- const i = t[t.length - 1];
3846
- return !(a === i) || z.isBotTyping$.value ? null : l("div", {
3847
- class: "flex flex-grow flex-col items-center justify-center",
3848
- children: l(Wr, {
3849
- class: "text-neutral-6 h-8 w-8"
3850
- })
3851
- });
3852
- }).exhaustive()
3853
- })
3854
- }, s)), l(Ws, {}, "typing")]
3855
- });
3856
- }, ia = ({
3857
- logger: e,
3858
- apiClient: t,
3859
- analytics: r
3860
- }) => {
3861
- const {
3862
- flow: n
3863
- } = I.current$.value;
3864
- fe(n, "Flow is required to exist to show chatbot body");
3865
- const s = I.viewState$.value, {
3866
- chatRef: a,
3867
- chatService: i
3868
- } = Cn(), {
3869
- t: u
3870
- } = G(), [d, p] = ee();
3871
- return pe(() => {
3872
- s === "maximised" && z.scrollToEnd.instant();
3873
- }, [s]), pe(() => {
3874
- var S, E;
3875
- const {
3876
- state: w,
3877
- flow: v
3878
- } = I.current$.peek();
3879
- if (w !== "loaded")
3880
- throw new Error(u("invalid_state"));
3881
- let h = v.data.nodeHistory.at(-1);
3882
- if (z.scrollToEnd.instant(), I.setInput(void 0), v.data.isFinished)
3883
- return;
3884
- h === void 0 ? (h = tr(n.nodes).id, I.setCurrentNodeId(h), r.log({
3885
- event: "FLOW_START",
3886
- properties: {
3887
- flow_id: n.id,
3888
- flow_version: n.version,
3889
- flow_session_id: v.data.flowSessionId,
3890
- flow_build: n.build,
3891
- job: n.job
3892
- },
3893
- customProperties: (S = n.analytics) == null ? void 0 : S.customProperties
3894
- })) : I.removeMessagesSentByNodeIds([h]);
3895
- const {
3896
- interpret: _,
3897
- abort: y,
3898
- undo: A
3899
- } = Qr({
3900
- context: n.context,
3901
- analytics: {
3902
- service: r,
3903
- customProperties: (E = n.analytics) == null ? void 0 : E.customProperties
3904
- },
3905
- apiClient: t,
3906
- logger: e,
3907
- flow: n,
3908
- chatService: i,
3909
- t: u,
3910
- // We need to get fresh submissions, that’s why we call `peek` here.
3911
- getSubmissions: () => {
3912
- var g;
3913
- return (g = I.current$.peek().flow) == null ? void 0 : g.data.submissions;
3914
- },
3915
- onInterpret: (g) => I.setCurrentNodeId(g.id),
3916
- onFlowEnd: async () => {
3917
- var F;
3918
- I.markAsFinished();
3919
- const g = I.current$.peek().flow;
3920
- fe(g), r.log({
3921
- event: "FLOW_END",
3922
- properties: {
3923
- flow_id: n.id,
3924
- flow_version: n.version,
3925
- flow_session_id: g.data.flowSessionId,
3926
- flow_build: n.build,
3927
- job: n.job
3928
- },
3929
- customProperties: (F = n.analytics) == null ? void 0 : F.customProperties
3930
- });
3931
- }
3932
- });
3933
- return p(() => A), _(h), y;
3934
- }, [r, t, i, e, n, u]), l(ve, {
3935
- children: [l("div", {
3936
- ref: a,
3937
- className: "hide-scrollbars relative flex w-full max-w-full flex-grow flex-col overflow-y-scroll",
3938
- style: {
3939
- WebkitOverflowScrolling: "touch",
3940
- paddingBottom: I.inputHeight$.value
3941
- },
3942
- children: l(Xs, {
3943
- lastSentMessageFooter: n.data.isFinished || !d ? null : l(Ys, {
3944
- undoFn: d
3945
- })
3946
- })
3947
- }), l(Ls, {
3948
- logger: e
3949
- })]
3950
- });
3951
- }, Qs = (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") : [], Ys = ({
3952
- undoFn: e
3953
- }) => {
3954
- const {
3955
- t
3956
- } = G();
3957
- return l(Jr, {
3958
- onClick: async () => {
3959
- const {
3960
- flow: r
3961
- } = I.current$.peek();
3962
- fe(r);
3963
- const {
3964
- removed: n
3965
- } = e(r.data.nodeHistory), s = r.data.nodeHistory.splice(-n);
3966
- 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(Qs).forEach((a) => delete r.data.submissions[a]), I.current$.value = {
3967
- ...I.current$.value
3968
- });
3969
- },
3970
- children: [l("title", {
3971
- children: t("undo")
3972
- }), l("path", {
3973
- 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"
3974
- })]
3975
- });
3976
- };
3977
- export {
3978
- ia as ChatbotBody
3979
- };