@inploi/plugin-chatbot 3.2.4 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2912 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const framerMotion = require("framer-motion");
4
+ const index = require("./index-4a06c2aa.cjs");
5
+ require("@inploi/sdk");
6
+ const followNodes = ({
7
+ node,
8
+ nodes,
9
+ stopWhen
10
+ }) => {
11
+ if ((stopWhen == null ? void 0 : stopWhen(node)) === true)
12
+ return node;
13
+ const nextNode = node.nextId ? nodes.find((n2) => n2.id === node.nextId) : void 0;
14
+ if (!nextNode)
15
+ return;
16
+ return followNodes({
17
+ node: nextNode,
18
+ nodes,
19
+ stopWhen
20
+ });
21
+ };
22
+ const fallthroughBranch = ({
23
+ childNode,
24
+ nodes
25
+ }) => {
26
+ const branches = nodes.filter((node) => node.type === "if-block");
27
+ const branch = branches.find((branchNode) => {
28
+ if (!branchNode.branchId)
29
+ return false;
30
+ const nodeToFollow = nodes.find((n2) => n2.id === branchNode.branchId);
31
+ if (!nodeToFollow)
32
+ return false;
33
+ const node = followNodes({
34
+ node: nodeToFollow,
35
+ nodes,
36
+ stopWhen: (n2) => n2.id === childNode.id
37
+ });
38
+ if (!node || node.id !== childNode.id)
39
+ return false;
40
+ return true;
41
+ });
42
+ if (!(branch == null ? void 0 : branch.nextId))
43
+ return;
44
+ return nodes.find((n2) => n2.id === branch.nextId);
45
+ };
46
+ const createFlowInterpreter = ({
47
+ flow,
48
+ analytics,
49
+ logger,
50
+ context,
51
+ apiClient,
52
+ getSubmissions,
53
+ chatService,
54
+ onFlowEnd,
55
+ onInterpret
56
+ }) => {
57
+ const controller = new AbortController();
58
+ const interpretNode = async (node, prevNode) => {
59
+ const submissions = getSubmissions();
60
+ onInterpret == null ? void 0 : onInterpret(node, prevNode);
61
+ try {
62
+ await interpret({
63
+ analytics,
64
+ logger,
65
+ apiClient,
66
+ context,
67
+ node,
68
+ submissions,
69
+ chat: {
70
+ sendMessage: async (message) => chatService.send({
71
+ groupId: node.id,
72
+ message,
73
+ signal: controller.signal
74
+ }),
75
+ userInput: async (input) => chatService.input({
76
+ input,
77
+ signal: controller.signal
78
+ })
79
+ },
80
+ next: (nodeId) => {
81
+ const nextNode = nodeId ? flow.find((node2) => node2.id === nodeId) : fallthroughBranch({
82
+ childNode: node,
83
+ nodes: flow
84
+ });
85
+ if (!nextNode)
86
+ return onFlowEnd == null ? void 0 : onFlowEnd(node);
87
+ return interpretNode(nextNode, node);
88
+ }
89
+ });
90
+ } catch (e) {
91
+ if (e instanceof index.AbortedError)
92
+ return;
93
+ throw e;
94
+ }
95
+ };
96
+ return {
97
+ interpret: async (startFromNodeId) => {
98
+ const startNode = flow.find((node) => node.id === startFromNodeId) ?? index.getHeadOrThrow(flow);
99
+ return interpretNode(startNode);
100
+ },
101
+ abort: () => {
102
+ controller.abort();
103
+ }
104
+ };
105
+ };
106
+ async function interpret(params) {
107
+ return await index.N(params).with({
108
+ node: {
109
+ type: "text"
110
+ }
111
+ }, interpretTextNode).with({
112
+ node: {
113
+ type: "image"
114
+ }
115
+ }, interpretImageNode).with({
116
+ node: {
117
+ type: "question-text"
118
+ }
119
+ }, interpretQuestionTextNode).with({
120
+ node: {
121
+ type: "question-enum"
122
+ }
123
+ }, interpretQuestionEnumNode).with({
124
+ node: {
125
+ type: "question-number"
126
+ }
127
+ }, interpretQuestionNumberNode).with({
128
+ node: {
129
+ type: "question-boolean"
130
+ }
131
+ }, interpretQuestionBooleanNode).with({
132
+ node: {
133
+ type: "question-file"
134
+ }
135
+ }, interpretQuestionFileNode).with({
136
+ node: {
137
+ type: "question-address"
138
+ }
139
+ }, interpretQuestionAddressNode).with({
140
+ node: {
141
+ type: "end-flow"
142
+ }
143
+ }, interpretEndFlowNode).with({
144
+ node: {
145
+ type: "if-block"
146
+ }
147
+ }, interpretIfBlockNode).with({
148
+ node: {
149
+ type: "jump"
150
+ }
151
+ }, ({
152
+ node,
153
+ next
154
+ }) => next(node.data.targetId)).with({
155
+ node: {
156
+ type: "link"
157
+ }
158
+ }, interpretLinkNode).with({
159
+ node: {
160
+ type: "submit"
161
+ }
162
+ }, interpretSubmitNode).exhaustive();
163
+ }
164
+ async function interpretSubmitNode({
165
+ chat,
166
+ next,
167
+ node,
168
+ logger,
169
+ apiClient,
170
+ submissions,
171
+ context
172
+ }) {
173
+ await chat.userInput({
174
+ type: "multiple-choice",
175
+ key: void 0,
176
+ config: {
177
+ options: [{
178
+ label: "Submit my application",
179
+ value: "submit"
180
+ }],
181
+ maxSelected: 1,
182
+ minSelected: 1
183
+ }
184
+ });
185
+ await chat.sendMessage({
186
+ type: "system",
187
+ variant: "info",
188
+ text: "Submitting your application…"
189
+ });
190
+ const response = await apiClient.fetch(`/flow/apply`, {
191
+ method: "POST",
192
+ body: JSON.stringify({
193
+ ...context,
194
+ submissions: index.getApplicationSubmissionsPayload(submissions || {})
195
+ })
196
+ }).catch((e) => e);
197
+ await index.N(response).with({
198
+ redirect_url: index._.string
199
+ }, async (response2) => {
200
+ await chat.sendMessage({
201
+ type: "text",
202
+ author: "bot",
203
+ text: "Almost there! Please finalise your application on our partner’s website."
204
+ });
205
+ await chat.sendMessage({
206
+ type: "link",
207
+ href: response2.redirect_url,
208
+ text: "Finalise application on partner"
209
+ });
210
+ }).with({
211
+ message: "Success"
212
+ }, async () => {
213
+ await chat.sendMessage({
214
+ type: "system",
215
+ variant: "success",
216
+ text: "Application submitted"
217
+ });
218
+ next(node.nextId);
219
+ }).otherwise(async (response2) => {
220
+ logger.error(response2);
221
+ await chat.sendMessage({
222
+ type: "system",
223
+ variant: "error",
224
+ text: "Failed to submit application"
225
+ });
226
+ next(node.id);
227
+ });
228
+ }
229
+ async function interpretLinkNode({
230
+ chat,
231
+ next,
232
+ node
233
+ }) {
234
+ await chat.sendMessage({
235
+ type: "link",
236
+ href: node.data.href,
237
+ text: node.data.cta
238
+ });
239
+ next(node.nextId);
240
+ }
241
+ async function interpretIfBlockNode({
242
+ submissions,
243
+ next,
244
+ node
245
+ }) {
246
+ const nextId = isIfBlockConditionMet(node, submissions) ? node.branchId : node.nextId;
247
+ next(nextId);
248
+ }
249
+ async function interpretTextNode({
250
+ chat,
251
+ next,
252
+ node
253
+ }) {
254
+ await chat.sendMessage({
255
+ author: "bot",
256
+ type: "text",
257
+ text: node.data.text
258
+ });
259
+ next(node.nextId);
260
+ }
261
+ async function interpretImageNode({
262
+ chat,
263
+ next,
264
+ node
265
+ }) {
266
+ await chat.sendMessage({
267
+ author: "bot",
268
+ type: "image",
269
+ url: node.data.url,
270
+ height: node.data.height,
271
+ width: node.data.width
272
+ });
273
+ next(node.nextId);
274
+ }
275
+ async function interpretQuestionTextNode({
276
+ chat,
277
+ next,
278
+ node
279
+ }) {
280
+ await chat.sendMessage({
281
+ author: "bot",
282
+ type: "text",
283
+ text: node.data.question
284
+ });
285
+ const reply = await chat.userInput({
286
+ key: node.data.key,
287
+ type: "text",
288
+ config: {
289
+ placeholder: node.data.placeholder,
290
+ format: node.data.format
291
+ }
292
+ });
293
+ await chat.sendMessage({
294
+ author: "user",
295
+ type: "text",
296
+ text: reply.value
297
+ });
298
+ next(node.nextId);
299
+ }
300
+ async function interpretQuestionNumberNode({
301
+ chat,
302
+ next,
303
+ node
304
+ }) {
305
+ await chat.sendMessage({
306
+ author: "bot",
307
+ type: "text",
308
+ text: node.data.question
309
+ });
310
+ const reply = await chat.userInput({
311
+ key: node.data.key,
312
+ type: "text",
313
+ config: {
314
+ placeholder: node.data.placeholder,
315
+ format: "text"
316
+ }
317
+ });
318
+ await chat.sendMessage({
319
+ author: "user",
320
+ type: "text",
321
+ text: reply.value
322
+ });
323
+ next(node.nextId);
324
+ }
325
+ async function interpretQuestionEnumNode({
326
+ chat,
327
+ next,
328
+ node
329
+ }) {
330
+ await chat.sendMessage({
331
+ author: "bot",
332
+ type: "text",
333
+ text: node.data.question
334
+ });
335
+ const reply = await chat.userInput({
336
+ key: node.data.key,
337
+ type: "multiple-choice",
338
+ config: node.data
339
+ });
340
+ await chat.sendMessage({
341
+ author: "user",
342
+ type: "text",
343
+ text: reply.value.join(", ")
344
+ });
345
+ next(node.nextId);
346
+ }
347
+ async function interpretQuestionBooleanNode({
348
+ chat,
349
+ next,
350
+ node
351
+ }) {
352
+ await chat.sendMessage({
353
+ author: "bot",
354
+ type: "text",
355
+ text: node.data.question
356
+ });
357
+ const input = await chat.userInput({
358
+ key: node.data.key,
359
+ type: "boolean",
360
+ config: {
361
+ labels: {
362
+ true: node.data.trueLabel,
363
+ false: node.data.falseLabel
364
+ }
365
+ }
366
+ });
367
+ const reply = input.value;
368
+ const labelMap = {
369
+ true: node.data.trueLabel,
370
+ false: node.data.falseLabel
371
+ };
372
+ await chat.sendMessage({
373
+ author: "user",
374
+ type: "text",
375
+ text: labelMap[reply]
376
+ });
377
+ next(node.nextId);
378
+ }
379
+ async function interpretQuestionAddressNode({
380
+ chat,
381
+ next,
382
+ node
383
+ }) {
384
+ await chat.sendMessage({
385
+ author: "bot",
386
+ type: "text",
387
+ text: "Address questions are not implemented yet"
388
+ });
389
+ next(node.nextId);
390
+ }
391
+ async function interpretQuestionFileNode({
392
+ node,
393
+ chat,
394
+ next
395
+ }) {
396
+ await chat.sendMessage({
397
+ author: "bot",
398
+ type: "text",
399
+ text: node.data.question
400
+ });
401
+ const files = await chat.userInput({
402
+ key: node.data.key,
403
+ type: "file",
404
+ config: {
405
+ extensions: node.data.extensions,
406
+ fileSizeLimitKib: node.data.maxSizeKb,
407
+ allowMultiple: node.data.multiple === true
408
+ }
409
+ });
410
+ for await (const file of files.value) {
411
+ await chat.sendMessage({
412
+ author: "user",
413
+ type: "file",
414
+ fileName: file.name,
415
+ fileSizeKb: file.sizeKb
416
+ });
417
+ }
418
+ next(node.nextId);
419
+ }
420
+ async function interpretEndFlowNode({
421
+ chat,
422
+ next,
423
+ node
424
+ }) {
425
+ await chat.sendMessage({
426
+ type: "system",
427
+ variant: "info",
428
+ text: node.data.systemMessage || "Conversation finished"
429
+ });
430
+ next(void 0);
431
+ }
432
+ const stringOrStringArray = index._.union(index._.string, index._.array(index._.string));
433
+ const isIfBlockConditionMet = (ifBlock, submissions) => {
434
+ const answer = submissions == null ? void 0 : submissions[ifBlock.data.compareKey];
435
+ if (!answer)
436
+ return false;
437
+ return index.N({
438
+ ...ifBlock.data,
439
+ answer
440
+ }).with({
441
+ compare: "equals"
442
+ }, ({
443
+ compareValue
444
+ }) => {
445
+ if (typeof answer.value === "string" || typeof answer.value === "boolean")
446
+ return compareValue === answer.value.toString();
447
+ return false;
448
+ }).with({
449
+ compare: "notEquals"
450
+ }, ({
451
+ compareValue
452
+ }) => {
453
+ if (typeof answer.value === "string" || typeof answer.value === "boolean")
454
+ return compareValue !== answer.value.toString();
455
+ return false;
456
+ }).with({
457
+ compare: "contains",
458
+ answer: {
459
+ value: stringOrStringArray
460
+ }
461
+ }, ({
462
+ compareValue,
463
+ answer: answer2
464
+ }) => answer2.value.includes(compareValue)).with({
465
+ compare: "notContains",
466
+ answer: {
467
+ value: stringOrStringArray
468
+ }
469
+ }, ({
470
+ compareValue,
471
+ answer: answer2
472
+ }) => !answer2.value.includes(compareValue)).with({
473
+ answer: {
474
+ type: "file"
475
+ }
476
+ }, () => false).exhaustive();
477
+ };
478
+ const SendButton = ({
479
+ class: className,
480
+ ...props
481
+ }) => index.o("button", {
482
+ class: index.clsx("bg-accent-7 active:bg-accent-10 active:text-accent-2 text-lowest pointer-coarse:touch-hitbox focus-visible:ring-accent-7/50 flex-shrink-0 rounded-full p-2 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", className),
483
+ ...props,
484
+ children: index.o("svg", {
485
+ class: "block",
486
+ width: "16",
487
+ height: "16",
488
+ viewBox: "0 0 16 16",
489
+ fill: "transparent",
490
+ stroke: "currentColor",
491
+ "stroke-linecap": "round",
492
+ "stroke-width": "2",
493
+ children: [index.o("title", {
494
+ children: "Send"
495
+ }), index.o("path", {
496
+ d: "M3.5 7.5L8 3L12.5 7.5"
497
+ }), index.o("path", {
498
+ d: "M8 4V13"
499
+ })]
500
+ })
501
+ });
502
+ const useFocusOnMount = () => {
503
+ const focusRef = index._$1(null);
504
+ index.p(() => {
505
+ var _a;
506
+ (_a = focusRef.current) == null ? void 0 : _a.focus();
507
+ }, []);
508
+ return focusRef;
509
+ };
510
+ const options = ["true", "false"];
511
+ const AnswerSchema = index.picklist(options);
512
+ const FIELD_NAME = "answer";
513
+ const ChatInputBoolean = ({
514
+ input,
515
+ onSubmitSuccess,
516
+ onHeightChange
517
+ }) => {
518
+ const focusRef = useFocusOnMount();
519
+ onHeightChange();
520
+ return index.o("form", {
521
+ noValidate: true,
522
+ class: "flex items-center gap-2",
523
+ onSubmit: (e) => {
524
+ e.preventDefault();
525
+ const value = index.N(e).with({
526
+ nativeEvent: {
527
+ submitter: index._.select(index._.union(index._.instanceOf(HTMLButtonElement), index._.instanceOf(HTMLInputElement)))
528
+ }
529
+ }, (submitter) => {
530
+ return submitter.value;
531
+ }).otherwise(() => {
532
+ throw new Error("invalid form");
533
+ });
534
+ const answer = index.parse(AnswerSchema, value);
535
+ onSubmitSuccess(answer);
536
+ },
537
+ children: options.map((value, i2) => {
538
+ return index.o("button", {
539
+ ref: i2 === 0 ? focusRef : null,
540
+ type: "submit",
541
+ name: FIELD_NAME,
542
+ value,
543
+ class: "bg-lowest ease-expo-out ring-neutral-12/5 text-neutral-12 active:ring-accent-7 active:bg-accent-2 active:text-accent-11 fr block flex-1 overflow-hidden rounded-2xl px-2.5 py-2.5 ring-2 transition-all duration-300 selection:bg-transparent",
544
+ children: index.o("p", {
545
+ class: "truncate text-center text-base",
546
+ children: input.config.labels[value]
547
+ })
548
+ });
549
+ })
550
+ });
551
+ };
552
+ const InputError = ({
553
+ error,
554
+ onAnimationComplete
555
+ }) => {
556
+ return index.o(framerMotion.AnimatePresence, {
557
+ children: error && index.o(framerMotion.m.div, {
558
+ initial: {
559
+ height: 0,
560
+ opacity: 0
561
+ },
562
+ animate: {
563
+ height: "auto",
564
+ opacity: 1
565
+ },
566
+ exit: {
567
+ height: 0,
568
+ opacity: 0
569
+ },
570
+ onAnimationComplete,
571
+ role: "alert",
572
+ class: "text-error-11 flex max-w-full items-center gap-1 overflow-hidden rounded-full p-0.5 px-1 opacity-0",
573
+ children: [index.o("svg", {
574
+ class: "text-error-10",
575
+ width: "16",
576
+ height: "16",
577
+ viewBox: "0 0 16 16",
578
+ fill: "none",
579
+ xmlns: "http://www.w3.org/2000/svg",
580
+ children: [index.o("circle", {
581
+ cx: "8",
582
+ cy: "8",
583
+ r: "6.3",
584
+ stroke: "currentColor",
585
+ "stroke-width": "1.4"
586
+ }), index.o("rect", {
587
+ x: "7",
588
+ y: "4",
589
+ width: "2",
590
+ height: "5",
591
+ fill: "currentColor"
592
+ }), index.o("rect", {
593
+ x: "7",
594
+ y: "10",
595
+ width: "2",
596
+ height: "2",
597
+ fill: "currentColor"
598
+ })]
599
+ }), index.o("p", {
600
+ class: "truncate pr-1 text-sm",
601
+ children: error.message
602
+ })]
603
+ })
604
+ });
605
+ };
606
+ const toBase64 = (file) => new Promise((resolve, reject) => {
607
+ const reader = new FileReader();
608
+ reader.readAsDataURL(file);
609
+ reader.onload = () => {
610
+ if (!reader.result)
611
+ return reject("No result from reader");
612
+ return resolve(reader.result.toString());
613
+ };
614
+ reader.onerror = reject;
615
+ });
616
+ const kbToReadableSize = (kb) => index.N(kb).with(index._.number.lte(1e3), () => `${Math.round(kb)}KB`).with(index._.number.lt(1e3 * 10), () => `${(kb / 1e3).toFixed(1)}MB`).otherwise(() => `${Math.round(kb / 1e3)}MB`);
617
+ const addFileSizesKb = (files) => files.reduce((acc, cur) => acc + cur.sizeKb, 0);
618
+ const isFileSubmission = index.isSubmissionOfType("file");
619
+ const FILENAMES_TO_SHOW_QTY = 3;
620
+ const FileThumbnail = ({
621
+ file,
622
+ class: className,
623
+ ...props
624
+ }) => {
625
+ const extension = file.name.split(".").pop();
626
+ const fileName = file.name.replace(new RegExp(`.${extension}$`), "");
627
+ return index.o("div", {
628
+ class: index.clsx("bg-accent-1 outline-neutral-4 flex max-w-full gap-2 overflow-hidden rounded-lg px-3 py-2 text-sm outline", className),
629
+ ...props,
630
+ children: [index.o("p", {
631
+ "aria-label": "File name",
632
+ class: "text-accent-12 flex flex-grow overflow-hidden",
633
+ children: [index.o("span", {
634
+ class: "block truncate",
635
+ children: fileName
636
+ }), index.o("span", {
637
+ children: [".", extension]
638
+ })]
639
+ }), index.o("p", {
640
+ "aria-label": "File size",
641
+ class: "text-neutral-10",
642
+ children: kbToReadableSize(file.sizeKb)
643
+ })]
644
+ });
645
+ };
646
+ const FilenameBadge = ({
647
+ class: className,
648
+ ...props
649
+ }) => index.o("li", {
650
+ class: index.clsx("outline-neutral-6 text-neutral-11 bg-neutral-1 block rounded-md px-1 py-0.5 text-xs outline outline-1", className),
651
+ ...props
652
+ });
653
+ const ChatInputFile = ({
654
+ input,
655
+ onSubmitSuccess,
656
+ onHeightChange
657
+ }) => {
658
+ var _a;
659
+ const submission = (_a = index.application.current$.value.application) == null ? void 0 : _a.data.submissions[input.key];
660
+ const [files, setFiles] = index.h(isFileSubmission(submission) ? submission.value : []);
661
+ const [error, setError] = index.h();
662
+ const hiddenFileCount = files.length - FILENAMES_TO_SHOW_QTY;
663
+ const totalSize = addFileSizesKb(files);
664
+ const focusRef = useFocusOnMount();
665
+ return index.o("form", {
666
+ class: "flex flex-col gap-1",
667
+ onSubmit: (e) => {
668
+ e.preventDefault();
669
+ setError(void 0);
670
+ if (files.length === 0) {
671
+ setError({
672
+ type: "required",
673
+ message: "Please select a file"
674
+ });
675
+ }
676
+ if (input.config.fileSizeLimitKib && totalSize > input.config.fileSizeLimitKib) {
677
+ setError({
678
+ type: "max",
679
+ message: `File size exceeds limit of ${kbToReadableSize(input.config.fileSizeLimitKib)}`
680
+ });
681
+ }
682
+ return onSubmitSuccess(files);
683
+ },
684
+ children: [index.o("div", {
685
+ class: "flex items-center gap-2",
686
+ children: [index.o("label", {
687
+ ref: focusRef,
688
+ for: "dropzone-file",
689
+ 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",
690
+ children: [files.length > 0 ? index.o(index.k, {
691
+ children: [index.o("ul", {
692
+ class: "flex max-w-full flex-wrap justify-center gap-1 overflow-hidden p-1",
693
+ children: [files.slice(0, FILENAMES_TO_SHOW_QTY).map((file) => {
694
+ const extension = file.name.split(".").pop();
695
+ const fileName = file.name.replace(new RegExp(`.${extension}$`), "");
696
+ return index.o(FilenameBadge, {
697
+ class: "flex overflow-hidden",
698
+ children: [index.o("span", {
699
+ class: "block truncate",
700
+ children: fileName
701
+ }), index.o("span", {
702
+ children: [".", extension]
703
+ })]
704
+ });
705
+ }), hiddenFileCount > 0 ? index.o(FilenameBadge, {
706
+ children: ["+", hiddenFileCount, " file", hiddenFileCount !== 1 ? "s" : ""]
707
+ }) : null]
708
+ }), index.o("p", {
709
+ class: "text-neutral-11 text-xs",
710
+ children: [kbToReadableSize(totalSize), " ", files.length > 1 ? "total" : ""]
711
+ })]
712
+ }) : index.o("div", {
713
+ class: "flex flex-col justify-center gap-4 pb-6 pt-5",
714
+ children: [index.o("header", {
715
+ class: "flex flex-col items-center gap-0",
716
+ children: [index.o("svg", {
717
+ class: "text-neutral-11 mb-1 h-8 w-8",
718
+ "aria-hidden": "true",
719
+ xmlns: "http://www.w3.org/2000/svg",
720
+ fill: "none",
721
+ viewBox: "0 0 20 16",
722
+ children: index.o("path", {
723
+ stroke: "currentColor",
724
+ "stroke-linecap": "round",
725
+ "stroke-linejoin": "round",
726
+ "stroke-width": "1.5",
727
+ 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"
728
+ })
729
+ }), index.o("p", {
730
+ class: "text-neutral-12 tracking-[-0.01em] dark:text-gray-400",
731
+ children: [input.config.allowMultiple ? "Select files" : "Select a file", " to upload"]
732
+ }), input.config.fileSizeLimitKib ? index.o("p", {
733
+ class: "text-neutral-10 text-xs",
734
+ children: ["(max ", kbToReadableSize(input.config.fileSizeLimitKib), ")"]
735
+ }) : null]
736
+ }), index.o("aside", {
737
+ class: "flex flex-col items-center gap-2",
738
+ children: [index.o("p", {
739
+ id: "accepted-filetypes",
740
+ class: "sr-only",
741
+ children: "Accepted file extensions"
742
+ }), index.o("ul", {
743
+ "aria-describedby": "accepted-filetypes",
744
+ class: "flex flex-wrap justify-center gap-2",
745
+ children: input.config.extensions.map((ext) => index.o("li", {
746
+ 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",
747
+ children: ext.replace(".", "")
748
+ }))
749
+ })]
750
+ })]
751
+ }), index.o("input", {
752
+ id: "dropzone-file",
753
+ onInput: async (e) => {
754
+ index.invariant(e.target instanceof HTMLInputElement);
755
+ const files2 = e.target.files ? Array.from(e.target.files) : [];
756
+ const filesToUpload = await Promise.allSettled(files2.map(async (file) => {
757
+ const data = await toBase64(file);
758
+ return {
759
+ name: file.name,
760
+ data,
761
+ sizeKb: file.size / 1e3
762
+ };
763
+ }));
764
+ if (filesToUpload.some(({
765
+ status
766
+ }) => status === "rejected")) {
767
+ return setError({
768
+ type: "invalid",
769
+ message: "Invalid file"
770
+ });
771
+ }
772
+ const validFiles = filesToUpload.map((promise) => promise.status === "fulfilled" ? promise.value : null).filter(Boolean);
773
+ setFiles(validFiles);
774
+ },
775
+ multiple: input.config.allowMultiple,
776
+ type: "file",
777
+ class: "sr-only"
778
+ })]
779
+ }), index.o(SendButton, {
780
+ disabled: files.length === 0
781
+ })]
782
+ }), error && index.o(InputError, {
783
+ onAnimationComplete: onHeightChange,
784
+ error
785
+ })]
786
+ });
787
+ };
788
+ var isCheckBoxInput = (element) => element.type === "checkbox";
789
+ var isDateObject = (value) => value instanceof Date;
790
+ var isNullOrUndefined = (value) => value == null;
791
+ const isObjectType = (value) => typeof value === "object";
792
+ var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
793
+ var getEventValue = (event) => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
794
+ var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
795
+ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
796
+ var isPlainObject = (tempObject) => {
797
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
798
+ return isObject(prototypeCopy) && prototypeCopy.hasOwnProperty("isPrototypeOf");
799
+ };
800
+ var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
801
+ function cloneObject(data) {
802
+ let copy;
803
+ const isArray = Array.isArray(data);
804
+ if (data instanceof Date) {
805
+ copy = new Date(data);
806
+ } else if (data instanceof Set) {
807
+ copy = new Set(data);
808
+ } else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) && (isArray || isObject(data))) {
809
+ copy = isArray ? [] : {};
810
+ if (!isArray && !isPlainObject(data)) {
811
+ copy = data;
812
+ } else {
813
+ for (const key in data) {
814
+ if (data.hasOwnProperty(key)) {
815
+ copy[key] = cloneObject(data[key]);
816
+ }
817
+ }
818
+ }
819
+ } else {
820
+ return data;
821
+ }
822
+ return copy;
823
+ }
824
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
825
+ var isUndefined = (val) => val === void 0;
826
+ var get = (obj, path, defaultValue) => {
827
+ if (!path || !isObject(obj)) {
828
+ return defaultValue;
829
+ }
830
+ const result = compact(path.split(/[,[\].]+?/)).reduce((result2, key) => isNullOrUndefined(result2) ? result2 : result2[key], obj);
831
+ return isUndefined(result) || result === obj ? isUndefined(obj[path]) ? defaultValue : obj[path] : result;
832
+ };
833
+ var isBoolean = (value) => typeof value === "boolean";
834
+ const EVENTS = {
835
+ BLUR: "blur",
836
+ FOCUS_OUT: "focusout",
837
+ CHANGE: "change"
838
+ };
839
+ const VALIDATION_MODE = {
840
+ onBlur: "onBlur",
841
+ onChange: "onChange",
842
+ onSubmit: "onSubmit",
843
+ onTouched: "onTouched",
844
+ all: "all"
845
+ };
846
+ const INPUT_VALIDATION_RULES = {
847
+ max: "max",
848
+ min: "min",
849
+ maxLength: "maxLength",
850
+ minLength: "minLength",
851
+ pattern: "pattern",
852
+ required: "required",
853
+ validate: "validate"
854
+ };
855
+ index.Cn.createContext(null);
856
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
857
+ const result = {
858
+ defaultValues: control._defaultValues
859
+ };
860
+ for (const key in formState) {
861
+ Object.defineProperty(result, key, {
862
+ get: () => {
863
+ const _key = key;
864
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
865
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
866
+ }
867
+ localProxyFormState && (localProxyFormState[_key] = true);
868
+ return formState[_key];
869
+ }
870
+ });
871
+ }
872
+ return result;
873
+ };
874
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
875
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
876
+ updateFormState(formStateData);
877
+ const { name, ...formState } = formStateData;
878
+ return isEmptyObject(formState) || Object.keys(formState).length >= Object.keys(_proxyFormState).length || Object.keys(formState).find((key) => _proxyFormState[key] === (!isRoot || VALIDATION_MODE.all));
879
+ };
880
+ var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
881
+ function useSubscribe(props) {
882
+ const _props = index.Cn.useRef(props);
883
+ _props.current = props;
884
+ index.Cn.useEffect(() => {
885
+ const subscription = !props.disabled && _props.current.subject && _props.current.subject.subscribe({
886
+ next: _props.current.next
887
+ });
888
+ return () => {
889
+ subscription && subscription.unsubscribe();
890
+ };
891
+ }, [props.disabled]);
892
+ }
893
+ var isString = (value) => typeof value === "string";
894
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
895
+ if (isString(names)) {
896
+ isGlobal && _names.watch.add(names);
897
+ return get(formValues, names, defaultValue);
898
+ }
899
+ if (Array.isArray(names)) {
900
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
901
+ }
902
+ isGlobal && (_names.watchAll = true);
903
+ return formValues;
904
+ };
905
+ var isKey = (value) => /^\w*$/.test(value);
906
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
907
+ function set(object, path, value) {
908
+ let index2 = -1;
909
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
910
+ const length = tempPath.length;
911
+ const lastIndex = length - 1;
912
+ while (++index2 < length) {
913
+ const key = tempPath[index2];
914
+ let newValue = value;
915
+ if (index2 !== lastIndex) {
916
+ const objValue = object[key];
917
+ newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index2 + 1]) ? [] : {};
918
+ }
919
+ object[key] = newValue;
920
+ object = object[key];
921
+ }
922
+ return object;
923
+ }
924
+ var appendErrors = (name, validateAllFieldCriteria, errors2, type, message) => validateAllFieldCriteria ? {
925
+ ...errors2[name],
926
+ types: {
927
+ ...errors2[name] && errors2[name].types ? errors2[name].types : {},
928
+ [type]: message || true
929
+ }
930
+ } : {};
931
+ var getValidationModes = (mode) => ({
932
+ isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
933
+ isOnBlur: mode === VALIDATION_MODE.onBlur,
934
+ isOnChange: mode === VALIDATION_MODE.onChange,
935
+ isOnAll: mode === VALIDATION_MODE.all,
936
+ isOnTouch: mode === VALIDATION_MODE.onTouched
937
+ });
938
+ var isWatched = (name, _names, isBlurEvent) => !isBlurEvent && (_names.watchAll || _names.watch.has(name) || [..._names.watch].some((watchName) => name.startsWith(watchName) && /^\.\w+/.test(name.slice(watchName.length))));
939
+ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
940
+ for (const key of fieldsNames || Object.keys(fields)) {
941
+ const field = get(fields, key);
942
+ if (field) {
943
+ const { _f, ...currentField } = field;
944
+ if (_f) {
945
+ if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
946
+ break;
947
+ } else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
948
+ break;
949
+ }
950
+ } else if (isObject(currentField)) {
951
+ iterateFieldsByAction(currentField, action);
952
+ }
953
+ }
954
+ }
955
+ };
956
+ var updateFieldArrayRootError = (errors2, error, name) => {
957
+ const fieldArrayErrors = compact(get(errors2, name));
958
+ set(fieldArrayErrors, "root", error[name]);
959
+ set(errors2, name, fieldArrayErrors);
960
+ return errors2;
961
+ };
962
+ var isFileInput = (element) => element.type === "file";
963
+ var isFunction = (value) => typeof value === "function";
964
+ var isHTMLElement = (value) => {
965
+ if (!isWeb) {
966
+ return false;
967
+ }
968
+ const owner = value ? value.ownerDocument : 0;
969
+ return value instanceof (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement);
970
+ };
971
+ var isMessage = (value) => isString(value);
972
+ var isRadioInput = (element) => element.type === "radio";
973
+ var isRegex = (value) => value instanceof RegExp;
974
+ const defaultResult = {
975
+ value: false,
976
+ isValid: false
977
+ };
978
+ const validResult = { value: true, isValid: true };
979
+ var getCheckboxValue = (options2) => {
980
+ if (Array.isArray(options2)) {
981
+ if (options2.length > 1) {
982
+ const values = options2.filter((option) => option && option.checked && !option.disabled).map((option) => option.value);
983
+ return { value: values, isValid: !!values.length };
984
+ }
985
+ return options2[0].checked && !options2[0].disabled ? (
986
+ // @ts-expect-error expected to work in the browser
987
+ options2[0].attributes && !isUndefined(options2[0].attributes.value) ? isUndefined(options2[0].value) || options2[0].value === "" ? validResult : { value: options2[0].value, isValid: true } : validResult
988
+ ) : defaultResult;
989
+ }
990
+ return defaultResult;
991
+ };
992
+ const defaultReturn = {
993
+ isValid: false,
994
+ value: null
995
+ };
996
+ var getRadioValue = (options2) => Array.isArray(options2) ? options2.reduce((previous, option) => option && option.checked && !option.disabled ? {
997
+ isValid: true,
998
+ value: option.value
999
+ } : previous, defaultReturn) : defaultReturn;
1000
+ function getValidateError(result, ref, type = "validate") {
1001
+ if (isMessage(result) || Array.isArray(result) && result.every(isMessage) || isBoolean(result) && !result) {
1002
+ return {
1003
+ type,
1004
+ message: isMessage(result) ? result : "",
1005
+ ref
1006
+ };
1007
+ }
1008
+ }
1009
+ var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData) ? validationData : {
1010
+ value: validationData,
1011
+ message: ""
1012
+ };
1013
+ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
1014
+ const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled } = field._f;
1015
+ const inputValue = get(formValues, name);
1016
+ if (!mount || disabled) {
1017
+ return {};
1018
+ }
1019
+ const inputRef = refs ? refs[0] : ref;
1020
+ const setCustomValidity = (message) => {
1021
+ if (shouldUseNativeValidation && inputRef.reportValidity) {
1022
+ inputRef.setCustomValidity(isBoolean(message) ? "" : message || "");
1023
+ inputRef.reportValidity();
1024
+ }
1025
+ };
1026
+ const error = {};
1027
+ const isRadio = isRadioInput(ref);
1028
+ const isCheckBox = isCheckBoxInput(ref);
1029
+ const isRadioOrCheckbox2 = isRadio || isCheckBox;
1030
+ const isEmpty = (valueAsNumber || isFileInput(ref)) && isUndefined(ref.value) && isUndefined(inputValue) || isHTMLElement(ref) && ref.value === "" || inputValue === "" || Array.isArray(inputValue) && !inputValue.length;
1031
+ const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
1032
+ const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
1033
+ const message = exceedMax ? maxLengthMessage : minLengthMessage;
1034
+ error[name] = {
1035
+ type: exceedMax ? maxType : minType,
1036
+ message,
1037
+ ref,
1038
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message)
1039
+ };
1040
+ };
1041
+ if (isFieldArray ? !Array.isArray(inputValue) || !inputValue.length : required && (!isRadioOrCheckbox2 && (isEmpty || isNullOrUndefined(inputValue)) || isBoolean(inputValue) && !inputValue || isCheckBox && !getCheckboxValue(refs).isValid || isRadio && !getRadioValue(refs).isValid)) {
1042
+ const { value, message } = isMessage(required) ? { value: !!required, message: required } : getValueAndMessage(required);
1043
+ if (value) {
1044
+ error[name] = {
1045
+ type: INPUT_VALIDATION_RULES.required,
1046
+ message,
1047
+ ref: inputRef,
1048
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message)
1049
+ };
1050
+ if (!validateAllFieldCriteria) {
1051
+ setCustomValidity(message);
1052
+ return error;
1053
+ }
1054
+ }
1055
+ }
1056
+ if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
1057
+ let exceedMax;
1058
+ let exceedMin;
1059
+ const maxOutput = getValueAndMessage(max);
1060
+ const minOutput = getValueAndMessage(min);
1061
+ if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
1062
+ const valueNumber = ref.valueAsNumber || (inputValue ? +inputValue : inputValue);
1063
+ if (!isNullOrUndefined(maxOutput.value)) {
1064
+ exceedMax = valueNumber > maxOutput.value;
1065
+ }
1066
+ if (!isNullOrUndefined(minOutput.value)) {
1067
+ exceedMin = valueNumber < minOutput.value;
1068
+ }
1069
+ } else {
1070
+ const valueDate = ref.valueAsDate || new Date(inputValue);
1071
+ const convertTimeToDate = (time) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + time);
1072
+ const isTime = ref.type == "time";
1073
+ const isWeek = ref.type == "week";
1074
+ if (isString(maxOutput.value) && inputValue) {
1075
+ exceedMax = isTime ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value) : isWeek ? inputValue > maxOutput.value : valueDate > new Date(maxOutput.value);
1076
+ }
1077
+ if (isString(minOutput.value) && inputValue) {
1078
+ exceedMin = isTime ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value) : isWeek ? inputValue < minOutput.value : valueDate < new Date(minOutput.value);
1079
+ }
1080
+ }
1081
+ if (exceedMax || exceedMin) {
1082
+ getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
1083
+ if (!validateAllFieldCriteria) {
1084
+ setCustomValidity(error[name].message);
1085
+ return error;
1086
+ }
1087
+ }
1088
+ }
1089
+ if ((maxLength || minLength) && !isEmpty && (isString(inputValue) || isFieldArray && Array.isArray(inputValue))) {
1090
+ const maxLengthOutput = getValueAndMessage(maxLength);
1091
+ const minLengthOutput = getValueAndMessage(minLength);
1092
+ const exceedMax = !isNullOrUndefined(maxLengthOutput.value) && inputValue.length > +maxLengthOutput.value;
1093
+ const exceedMin = !isNullOrUndefined(minLengthOutput.value) && inputValue.length < +minLengthOutput.value;
1094
+ if (exceedMax || exceedMin) {
1095
+ getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
1096
+ if (!validateAllFieldCriteria) {
1097
+ setCustomValidity(error[name].message);
1098
+ return error;
1099
+ }
1100
+ }
1101
+ }
1102
+ if (pattern && !isEmpty && isString(inputValue)) {
1103
+ const { value: patternValue, message } = getValueAndMessage(pattern);
1104
+ if (isRegex(patternValue) && !inputValue.match(patternValue)) {
1105
+ error[name] = {
1106
+ type: INPUT_VALIDATION_RULES.pattern,
1107
+ message,
1108
+ ref,
1109
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message)
1110
+ };
1111
+ if (!validateAllFieldCriteria) {
1112
+ setCustomValidity(message);
1113
+ return error;
1114
+ }
1115
+ }
1116
+ }
1117
+ if (validate) {
1118
+ if (isFunction(validate)) {
1119
+ const result = await validate(inputValue, formValues);
1120
+ const validateError = getValidateError(result, inputRef);
1121
+ if (validateError) {
1122
+ error[name] = {
1123
+ ...validateError,
1124
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message)
1125
+ };
1126
+ if (!validateAllFieldCriteria) {
1127
+ setCustomValidity(validateError.message);
1128
+ return error;
1129
+ }
1130
+ }
1131
+ } else if (isObject(validate)) {
1132
+ let validationResult = {};
1133
+ for (const key in validate) {
1134
+ if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
1135
+ break;
1136
+ }
1137
+ const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
1138
+ if (validateError) {
1139
+ validationResult = {
1140
+ ...validateError,
1141
+ ...appendErrorsCurry(key, validateError.message)
1142
+ };
1143
+ setCustomValidity(validateError.message);
1144
+ if (validateAllFieldCriteria) {
1145
+ error[name] = validationResult;
1146
+ }
1147
+ }
1148
+ }
1149
+ if (!isEmptyObject(validationResult)) {
1150
+ error[name] = {
1151
+ ref: inputRef,
1152
+ ...validationResult
1153
+ };
1154
+ if (!validateAllFieldCriteria) {
1155
+ return error;
1156
+ }
1157
+ }
1158
+ }
1159
+ }
1160
+ setCustomValidity(true);
1161
+ return error;
1162
+ };
1163
+ function baseGet(object, updatePath) {
1164
+ const length = updatePath.slice(0, -1).length;
1165
+ let index2 = 0;
1166
+ while (index2 < length) {
1167
+ object = isUndefined(object) ? index2++ : object[updatePath[index2++]];
1168
+ }
1169
+ return object;
1170
+ }
1171
+ function isEmptyArray(obj) {
1172
+ for (const key in obj) {
1173
+ if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
1174
+ return false;
1175
+ }
1176
+ }
1177
+ return true;
1178
+ }
1179
+ function unset(object, path) {
1180
+ const paths = Array.isArray(path) ? path : isKey(path) ? [path] : stringToPath(path);
1181
+ const childObject = paths.length === 1 ? object : baseGet(object, paths);
1182
+ const index2 = paths.length - 1;
1183
+ const key = paths[index2];
1184
+ if (childObject) {
1185
+ delete childObject[key];
1186
+ }
1187
+ if (index2 !== 0 && (isObject(childObject) && isEmptyObject(childObject) || Array.isArray(childObject) && isEmptyArray(childObject))) {
1188
+ unset(object, paths.slice(0, -1));
1189
+ }
1190
+ return object;
1191
+ }
1192
+ function createSubject() {
1193
+ let _observers = [];
1194
+ const next = (value) => {
1195
+ for (const observer of _observers) {
1196
+ observer.next && observer.next(value);
1197
+ }
1198
+ };
1199
+ const subscribe = (observer) => {
1200
+ _observers.push(observer);
1201
+ return {
1202
+ unsubscribe: () => {
1203
+ _observers = _observers.filter((o2) => o2 !== observer);
1204
+ }
1205
+ };
1206
+ };
1207
+ const unsubscribe = () => {
1208
+ _observers = [];
1209
+ };
1210
+ return {
1211
+ get observers() {
1212
+ return _observers;
1213
+ },
1214
+ next,
1215
+ subscribe,
1216
+ unsubscribe
1217
+ };
1218
+ }
1219
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
1220
+ function deepEqual(object1, object2) {
1221
+ if (isPrimitive(object1) || isPrimitive(object2)) {
1222
+ return object1 === object2;
1223
+ }
1224
+ if (isDateObject(object1) && isDateObject(object2)) {
1225
+ return object1.getTime() === object2.getTime();
1226
+ }
1227
+ const keys1 = Object.keys(object1);
1228
+ const keys2 = Object.keys(object2);
1229
+ if (keys1.length !== keys2.length) {
1230
+ return false;
1231
+ }
1232
+ for (const key of keys1) {
1233
+ const val1 = object1[key];
1234
+ if (!keys2.includes(key)) {
1235
+ return false;
1236
+ }
1237
+ if (key !== "ref") {
1238
+ const val2 = object2[key];
1239
+ if (isDateObject(val1) && isDateObject(val2) || isObject(val1) && isObject(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2) : val1 !== val2) {
1240
+ return false;
1241
+ }
1242
+ }
1243
+ }
1244
+ return true;
1245
+ }
1246
+ var isMultipleSelect = (element) => element.type === `select-multiple`;
1247
+ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
1248
+ var live = (ref) => isHTMLElement(ref) && ref.isConnected;
1249
+ var objectHasFunction = (data) => {
1250
+ for (const key in data) {
1251
+ if (isFunction(data[key])) {
1252
+ return true;
1253
+ }
1254
+ }
1255
+ return false;
1256
+ };
1257
+ function markFieldsDirty(data, fields = {}) {
1258
+ const isParentNodeArray = Array.isArray(data);
1259
+ if (isObject(data) || isParentNodeArray) {
1260
+ for (const key in data) {
1261
+ if (Array.isArray(data[key]) || isObject(data[key]) && !objectHasFunction(data[key])) {
1262
+ fields[key] = Array.isArray(data[key]) ? [] : {};
1263
+ markFieldsDirty(data[key], fields[key]);
1264
+ } else if (!isNullOrUndefined(data[key])) {
1265
+ fields[key] = true;
1266
+ }
1267
+ }
1268
+ }
1269
+ return fields;
1270
+ }
1271
+ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
1272
+ const isParentNodeArray = Array.isArray(data);
1273
+ if (isObject(data) || isParentNodeArray) {
1274
+ for (const key in data) {
1275
+ if (Array.isArray(data[key]) || isObject(data[key]) && !objectHasFunction(data[key])) {
1276
+ if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
1277
+ dirtyFieldsFromValues[key] = Array.isArray(data[key]) ? markFieldsDirty(data[key], []) : { ...markFieldsDirty(data[key]) };
1278
+ } else {
1279
+ getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
1280
+ }
1281
+ } else {
1282
+ dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
1283
+ }
1284
+ }
1285
+ }
1286
+ return dirtyFieldsFromValues;
1287
+ }
1288
+ var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
1289
+ var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value) ? value : valueAsNumber ? value === "" ? NaN : value ? +value : value : valueAsDate && isString(value) ? new Date(value) : setValueAs ? setValueAs(value) : value;
1290
+ function getFieldValue(_f) {
1291
+ const ref = _f.ref;
1292
+ if (_f.refs ? _f.refs.every((ref2) => ref2.disabled) : ref.disabled) {
1293
+ return;
1294
+ }
1295
+ if (isFileInput(ref)) {
1296
+ return ref.files;
1297
+ }
1298
+ if (isRadioInput(ref)) {
1299
+ return getRadioValue(_f.refs).value;
1300
+ }
1301
+ if (isMultipleSelect(ref)) {
1302
+ return [...ref.selectedOptions].map(({ value }) => value);
1303
+ }
1304
+ if (isCheckBoxInput(ref)) {
1305
+ return getCheckboxValue(_f.refs).value;
1306
+ }
1307
+ return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
1308
+ }
1309
+ var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
1310
+ const fields = {};
1311
+ for (const name of fieldsNames) {
1312
+ const field = get(_fields, name);
1313
+ field && set(fields, name, field._f);
1314
+ }
1315
+ return {
1316
+ criteriaMode,
1317
+ names: [...fieldsNames],
1318
+ fields,
1319
+ shouldUseNativeValidation
1320
+ };
1321
+ };
1322
+ var getRuleValue = (rule) => isUndefined(rule) ? rule : isRegex(rule) ? rule.source : isObject(rule) ? isRegex(rule.value) ? rule.value.source : rule.value : rule;
1323
+ var hasValidation = (options2) => options2.mount && (options2.required || options2.min || options2.max || options2.maxLength || options2.minLength || options2.pattern || options2.validate);
1324
+ function schemaErrorLookup(errors2, _fields, name) {
1325
+ const error = get(errors2, name);
1326
+ if (error || isKey(name)) {
1327
+ return {
1328
+ error,
1329
+ name
1330
+ };
1331
+ }
1332
+ const names = name.split(".");
1333
+ while (names.length) {
1334
+ const fieldName = names.join(".");
1335
+ const field = get(_fields, fieldName);
1336
+ const foundError = get(errors2, fieldName);
1337
+ if (field && !Array.isArray(field) && name !== fieldName) {
1338
+ return { name };
1339
+ }
1340
+ if (foundError && foundError.type) {
1341
+ return {
1342
+ name: fieldName,
1343
+ error: foundError
1344
+ };
1345
+ }
1346
+ names.pop();
1347
+ }
1348
+ return {
1349
+ name
1350
+ };
1351
+ }
1352
+ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
1353
+ if (mode.isOnAll) {
1354
+ return false;
1355
+ } else if (!isSubmitted && mode.isOnTouch) {
1356
+ return !(isTouched || isBlurEvent);
1357
+ } else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
1358
+ return !isBlurEvent;
1359
+ } else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
1360
+ return isBlurEvent;
1361
+ }
1362
+ return true;
1363
+ };
1364
+ var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
1365
+ const defaultOptions = {
1366
+ mode: VALIDATION_MODE.onSubmit,
1367
+ reValidateMode: VALIDATION_MODE.onChange,
1368
+ shouldFocusError: true
1369
+ };
1370
+ function createFormControl(props = {}, flushRootRender) {
1371
+ let _options = {
1372
+ ...defaultOptions,
1373
+ ...props
1374
+ };
1375
+ let _formState = {
1376
+ submitCount: 0,
1377
+ isDirty: false,
1378
+ isLoading: isFunction(_options.defaultValues),
1379
+ isValidating: false,
1380
+ isSubmitted: false,
1381
+ isSubmitting: false,
1382
+ isSubmitSuccessful: false,
1383
+ isValid: false,
1384
+ touchedFields: {},
1385
+ dirtyFields: {},
1386
+ errors: {},
1387
+ disabled: false
1388
+ };
1389
+ let _fields = {};
1390
+ let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values) ? cloneObject(_options.defaultValues || _options.values) || {} : {};
1391
+ let _formValues = _options.shouldUnregister ? {} : cloneObject(_defaultValues);
1392
+ let _state = {
1393
+ action: false,
1394
+ mount: false,
1395
+ watch: false
1396
+ };
1397
+ let _names = {
1398
+ mount: /* @__PURE__ */ new Set(),
1399
+ unMount: /* @__PURE__ */ new Set(),
1400
+ array: /* @__PURE__ */ new Set(),
1401
+ watch: /* @__PURE__ */ new Set()
1402
+ };
1403
+ let delayErrorCallback;
1404
+ let timer = 0;
1405
+ const _proxyFormState = {
1406
+ isDirty: false,
1407
+ dirtyFields: false,
1408
+ touchedFields: false,
1409
+ isValidating: false,
1410
+ isValid: false,
1411
+ errors: false
1412
+ };
1413
+ const _subjects = {
1414
+ values: createSubject(),
1415
+ array: createSubject(),
1416
+ state: createSubject()
1417
+ };
1418
+ const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
1419
+ const validationModeBeforeSubmit = getValidationModes(_options.mode);
1420
+ const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1421
+ const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
1422
+ const debounce = (callback) => (wait) => {
1423
+ clearTimeout(timer);
1424
+ timer = setTimeout(callback, wait);
1425
+ };
1426
+ const _updateValid = async (shouldUpdateValid) => {
1427
+ if (_proxyFormState.isValid || shouldUpdateValid) {
1428
+ const isValid = _options.resolver ? isEmptyObject((await _executeSchema()).errors) : await executeBuiltInValidation(_fields, true);
1429
+ if (isValid !== _formState.isValid) {
1430
+ _subjects.state.next({
1431
+ isValid
1432
+ });
1433
+ }
1434
+ }
1435
+ };
1436
+ const _updateIsValidating = (value) => _proxyFormState.isValidating && _subjects.state.next({
1437
+ isValidating: value
1438
+ });
1439
+ const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1440
+ if (args && method) {
1441
+ _state.action = true;
1442
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1443
+ const fieldValues = method(get(_fields, name), args.argA, args.argB);
1444
+ shouldSetValues && set(_fields, name, fieldValues);
1445
+ }
1446
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_formState.errors, name))) {
1447
+ const errors2 = method(get(_formState.errors, name), args.argA, args.argB);
1448
+ shouldSetValues && set(_formState.errors, name, errors2);
1449
+ unsetEmptyArray(_formState.errors, name);
1450
+ }
1451
+ if (_proxyFormState.touchedFields && shouldUpdateFieldsAndState && Array.isArray(get(_formState.touchedFields, name))) {
1452
+ const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
1453
+ shouldSetValues && set(_formState.touchedFields, name, touchedFields);
1454
+ }
1455
+ if (_proxyFormState.dirtyFields) {
1456
+ _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
1457
+ }
1458
+ _subjects.state.next({
1459
+ name,
1460
+ isDirty: _getDirty(name, values),
1461
+ dirtyFields: _formState.dirtyFields,
1462
+ errors: _formState.errors,
1463
+ isValid: _formState.isValid
1464
+ });
1465
+ } else {
1466
+ set(_formValues, name, values);
1467
+ }
1468
+ };
1469
+ const updateErrors = (name, error) => {
1470
+ set(_formState.errors, name, error);
1471
+ _subjects.state.next({
1472
+ errors: _formState.errors
1473
+ });
1474
+ };
1475
+ const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
1476
+ const field = get(_fields, name);
1477
+ if (field) {
1478
+ const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
1479
+ isUndefined(defaultValue) || ref && ref.defaultChecked || shouldSkipSetValueAs ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f)) : setFieldValue(name, defaultValue);
1480
+ _state.mount && _updateValid();
1481
+ }
1482
+ };
1483
+ const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
1484
+ let shouldUpdateField = false;
1485
+ let isPreviousDirty = false;
1486
+ const output = {
1487
+ name
1488
+ };
1489
+ if (!isBlurEvent || shouldDirty) {
1490
+ if (_proxyFormState.isDirty) {
1491
+ isPreviousDirty = _formState.isDirty;
1492
+ _formState.isDirty = output.isDirty = _getDirty();
1493
+ shouldUpdateField = isPreviousDirty !== output.isDirty;
1494
+ }
1495
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1496
+ isPreviousDirty = get(_formState.dirtyFields, name);
1497
+ isCurrentFieldPristine ? unset(_formState.dirtyFields, name) : set(_formState.dirtyFields, name, true);
1498
+ output.dirtyFields = _formState.dirtyFields;
1499
+ shouldUpdateField = shouldUpdateField || _proxyFormState.dirtyFields && isPreviousDirty !== !isCurrentFieldPristine;
1500
+ }
1501
+ if (isBlurEvent) {
1502
+ const isPreviousFieldTouched = get(_formState.touchedFields, name);
1503
+ if (!isPreviousFieldTouched) {
1504
+ set(_formState.touchedFields, name, isBlurEvent);
1505
+ output.touchedFields = _formState.touchedFields;
1506
+ shouldUpdateField = shouldUpdateField || _proxyFormState.touchedFields && isPreviousFieldTouched !== isBlurEvent;
1507
+ }
1508
+ }
1509
+ shouldUpdateField && shouldRender && _subjects.state.next(output);
1510
+ return shouldUpdateField ? output : {};
1511
+ };
1512
+ const shouldRenderByError = (name, isValid, error, fieldState) => {
1513
+ const previousFieldError = get(_formState.errors, name);
1514
+ const shouldUpdateValid = _proxyFormState.isValid && isBoolean(isValid) && _formState.isValid !== isValid;
1515
+ if (props.delayError && error) {
1516
+ delayErrorCallback = debounce(() => updateErrors(name, error));
1517
+ delayErrorCallback(props.delayError);
1518
+ } else {
1519
+ clearTimeout(timer);
1520
+ delayErrorCallback = null;
1521
+ error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
1522
+ }
1523
+ if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) || !isEmptyObject(fieldState) || shouldUpdateValid) {
1524
+ const updatedFormState = {
1525
+ ...fieldState,
1526
+ ...shouldUpdateValid && isBoolean(isValid) ? { isValid } : {},
1527
+ errors: _formState.errors,
1528
+ name
1529
+ };
1530
+ _formState = {
1531
+ ..._formState,
1532
+ ...updatedFormState
1533
+ };
1534
+ _subjects.state.next(updatedFormState);
1535
+ }
1536
+ _updateIsValidating(false);
1537
+ };
1538
+ const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1539
+ const executeSchemaAndUpdateState = async (names) => {
1540
+ const { errors: errors2 } = await _executeSchema(names);
1541
+ if (names) {
1542
+ for (const name of names) {
1543
+ const error = get(errors2, name);
1544
+ error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
1545
+ }
1546
+ } else {
1547
+ _formState.errors = errors2;
1548
+ }
1549
+ return errors2;
1550
+ };
1551
+ const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
1552
+ valid: true
1553
+ }) => {
1554
+ for (const name in fields) {
1555
+ const field = fields[name];
1556
+ if (field) {
1557
+ const { _f, ...fieldValue } = field;
1558
+ if (_f) {
1559
+ const isFieldArrayRoot = _names.array.has(_f.name);
1560
+ const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1561
+ if (fieldError[_f.name]) {
1562
+ context.valid = false;
1563
+ if (shouldOnlyCheckValid) {
1564
+ break;
1565
+ }
1566
+ }
1567
+ !shouldOnlyCheckValid && (get(fieldError, _f.name) ? isFieldArrayRoot ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name) : set(_formState.errors, _f.name, fieldError[_f.name]) : unset(_formState.errors, _f.name));
1568
+ }
1569
+ fieldValue && await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context);
1570
+ }
1571
+ }
1572
+ return context.valid;
1573
+ };
1574
+ const _removeUnmounted = () => {
1575
+ for (const name of _names.unMount) {
1576
+ const field = get(_fields, name);
1577
+ field && (field._f.refs ? field._f.refs.every((ref) => !live(ref)) : !live(field._f.ref)) && unregister(name);
1578
+ }
1579
+ _names.unMount = /* @__PURE__ */ new Set();
1580
+ };
1581
+ const _getDirty = (name, data) => (name && data && set(_formValues, name, data), !deepEqual(getValues(), _defaultValues));
1582
+ const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1583
+ ..._state.mount ? _formValues : isUndefined(defaultValue) ? _defaultValues : isString(names) ? { [names]: defaultValue } : defaultValue
1584
+ }, isGlobal, defaultValue);
1585
+ const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
1586
+ const setFieldValue = (name, value, options2 = {}) => {
1587
+ const field = get(_fields, name);
1588
+ let fieldValue = value;
1589
+ if (field) {
1590
+ const fieldReference = field._f;
1591
+ if (fieldReference) {
1592
+ !fieldReference.disabled && set(_formValues, name, getFieldValueAs(value, fieldReference));
1593
+ fieldValue = isHTMLElement(fieldReference.ref) && isNullOrUndefined(value) ? "" : value;
1594
+ if (isMultipleSelect(fieldReference.ref)) {
1595
+ [...fieldReference.ref.options].forEach((optionRef) => optionRef.selected = fieldValue.includes(optionRef.value));
1596
+ } else if (fieldReference.refs) {
1597
+ if (isCheckBoxInput(fieldReference.ref)) {
1598
+ fieldReference.refs.length > 1 ? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) && (checkboxRef.checked = Array.isArray(fieldValue) ? !!fieldValue.find((data) => data === checkboxRef.value) : fieldValue === checkboxRef.value)) : fieldReference.refs[0] && (fieldReference.refs[0].checked = !!fieldValue);
1599
+ } else {
1600
+ fieldReference.refs.forEach((radioRef) => radioRef.checked = radioRef.value === fieldValue);
1601
+ }
1602
+ } else if (isFileInput(fieldReference.ref)) {
1603
+ fieldReference.ref.value = "";
1604
+ } else {
1605
+ fieldReference.ref.value = fieldValue;
1606
+ if (!fieldReference.ref.type) {
1607
+ _subjects.values.next({
1608
+ name,
1609
+ values: { ..._formValues }
1610
+ });
1611
+ }
1612
+ }
1613
+ }
1614
+ }
1615
+ (options2.shouldDirty || options2.shouldTouch) && updateTouchAndDirty(name, fieldValue, options2.shouldTouch, options2.shouldDirty, true);
1616
+ options2.shouldValidate && trigger(name);
1617
+ };
1618
+ const setValues = (name, value, options2) => {
1619
+ for (const fieldKey in value) {
1620
+ const fieldValue = value[fieldKey];
1621
+ const fieldName = `${name}.${fieldKey}`;
1622
+ const field = get(_fields, fieldName);
1623
+ (_names.array.has(name) || !isPrimitive(fieldValue) || field && !field._f) && !isDateObject(fieldValue) ? setValues(fieldName, fieldValue, options2) : setFieldValue(fieldName, fieldValue, options2);
1624
+ }
1625
+ };
1626
+ const setValue = (name, value, options2 = {}) => {
1627
+ const field = get(_fields, name);
1628
+ const isFieldArray = _names.array.has(name);
1629
+ const cloneValue = cloneObject(value);
1630
+ set(_formValues, name, cloneValue);
1631
+ if (isFieldArray) {
1632
+ _subjects.array.next({
1633
+ name,
1634
+ values: { ..._formValues }
1635
+ });
1636
+ if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) && options2.shouldDirty) {
1637
+ _subjects.state.next({
1638
+ name,
1639
+ dirtyFields: getDirtyFields(_defaultValues, _formValues),
1640
+ isDirty: _getDirty(name, cloneValue)
1641
+ });
1642
+ }
1643
+ } else {
1644
+ field && !field._f && !isNullOrUndefined(cloneValue) ? setValues(name, cloneValue, options2) : setFieldValue(name, cloneValue, options2);
1645
+ }
1646
+ isWatched(name, _names) && _subjects.state.next({ ..._formState });
1647
+ _subjects.values.next({
1648
+ name,
1649
+ values: { ..._formValues }
1650
+ });
1651
+ !_state.mount && flushRootRender();
1652
+ };
1653
+ const onChange = async (event) => {
1654
+ const target = event.target;
1655
+ let name = target.name;
1656
+ let isFieldValueUpdated = true;
1657
+ const field = get(_fields, name);
1658
+ const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1659
+ const _updateIsFieldValueUpdated = (fieldValue) => {
1660
+ isFieldValueUpdated = Number.isNaN(fieldValue) || fieldValue === get(_formValues, name, fieldValue);
1661
+ };
1662
+ if (field) {
1663
+ let error;
1664
+ let isValid;
1665
+ const fieldValue = getCurrentFieldValue();
1666
+ const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1667
+ const shouldSkipValidation = !hasValidation(field._f) && !_options.resolver && !get(_formState.errors, name) && !field._f.deps || skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
1668
+ const watched = isWatched(name, _names, isBlurEvent);
1669
+ set(_formValues, name, fieldValue);
1670
+ if (isBlurEvent) {
1671
+ field._f.onBlur && field._f.onBlur(event);
1672
+ delayErrorCallback && delayErrorCallback(0);
1673
+ } else if (field._f.onChange) {
1674
+ field._f.onChange(event);
1675
+ }
1676
+ const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
1677
+ const shouldRender = !isEmptyObject(fieldState) || watched;
1678
+ !isBlurEvent && _subjects.values.next({
1679
+ name,
1680
+ type: event.type,
1681
+ values: { ..._formValues }
1682
+ });
1683
+ if (shouldSkipValidation) {
1684
+ _proxyFormState.isValid && _updateValid();
1685
+ return shouldRender && _subjects.state.next({ name, ...watched ? {} : fieldState });
1686
+ }
1687
+ !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1688
+ _updateIsValidating(true);
1689
+ if (_options.resolver) {
1690
+ const { errors: errors2 } = await _executeSchema([name]);
1691
+ _updateIsFieldValueUpdated(fieldValue);
1692
+ if (isFieldValueUpdated) {
1693
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1694
+ const errorLookupResult = schemaErrorLookup(errors2, _fields, previousErrorLookupResult.name || name);
1695
+ error = errorLookupResult.error;
1696
+ name = errorLookupResult.name;
1697
+ isValid = isEmptyObject(errors2);
1698
+ }
1699
+ } else {
1700
+ error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1701
+ _updateIsFieldValueUpdated(fieldValue);
1702
+ if (isFieldValueUpdated) {
1703
+ if (error) {
1704
+ isValid = false;
1705
+ } else if (_proxyFormState.isValid) {
1706
+ isValid = await executeBuiltInValidation(_fields, true);
1707
+ }
1708
+ }
1709
+ }
1710
+ if (isFieldValueUpdated) {
1711
+ field._f.deps && trigger(field._f.deps);
1712
+ shouldRenderByError(name, isValid, error, fieldState);
1713
+ }
1714
+ }
1715
+ };
1716
+ const _focusInput = (ref, key) => {
1717
+ if (get(_formState.errors, key) && ref.focus) {
1718
+ ref.focus();
1719
+ return 1;
1720
+ }
1721
+ return;
1722
+ };
1723
+ const trigger = async (name, options2 = {}) => {
1724
+ let isValid;
1725
+ let validationResult;
1726
+ const fieldNames = convertToArrayPayload(name);
1727
+ _updateIsValidating(true);
1728
+ if (_options.resolver) {
1729
+ const errors2 = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1730
+ isValid = isEmptyObject(errors2);
1731
+ validationResult = name ? !fieldNames.some((name2) => get(errors2, name2)) : isValid;
1732
+ } else if (name) {
1733
+ validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
1734
+ const field = get(_fields, fieldName);
1735
+ return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
1736
+ }))).every(Boolean);
1737
+ !(!validationResult && !_formState.isValid) && _updateValid();
1738
+ } else {
1739
+ validationResult = isValid = await executeBuiltInValidation(_fields);
1740
+ }
1741
+ _subjects.state.next({
1742
+ ...!isString(name) || _proxyFormState.isValid && isValid !== _formState.isValid ? {} : { name },
1743
+ ..._options.resolver || !name ? { isValid } : {},
1744
+ errors: _formState.errors,
1745
+ isValidating: false
1746
+ });
1747
+ options2.shouldFocus && !validationResult && iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
1748
+ return validationResult;
1749
+ };
1750
+ const getValues = (fieldNames) => {
1751
+ const values = {
1752
+ ..._defaultValues,
1753
+ ..._state.mount ? _formValues : {}
1754
+ };
1755
+ return isUndefined(fieldNames) ? values : isString(fieldNames) ? get(values, fieldNames) : fieldNames.map((name) => get(values, name));
1756
+ };
1757
+ const getFieldState = (name, formState) => ({
1758
+ invalid: !!get((formState || _formState).errors, name),
1759
+ isDirty: !!get((formState || _formState).dirtyFields, name),
1760
+ isTouched: !!get((formState || _formState).touchedFields, name),
1761
+ error: get((formState || _formState).errors, name)
1762
+ });
1763
+ const clearErrors = (name) => {
1764
+ name && convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
1765
+ _subjects.state.next({
1766
+ errors: name ? _formState.errors : {}
1767
+ });
1768
+ };
1769
+ const setError = (name, error, options2) => {
1770
+ const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1771
+ set(_formState.errors, name, {
1772
+ ...error,
1773
+ ref
1774
+ });
1775
+ _subjects.state.next({
1776
+ name,
1777
+ errors: _formState.errors,
1778
+ isValid: false
1779
+ });
1780
+ options2 && options2.shouldFocus && ref && ref.focus && ref.focus();
1781
+ };
1782
+ const watch = (name, defaultValue) => isFunction(name) ? _subjects.values.subscribe({
1783
+ next: (payload) => name(_getWatch(void 0, defaultValue), payload)
1784
+ }) : _getWatch(name, defaultValue, true);
1785
+ const unregister = (name, options2 = {}) => {
1786
+ for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
1787
+ _names.mount.delete(fieldName);
1788
+ _names.array.delete(fieldName);
1789
+ if (!options2.keepValue) {
1790
+ unset(_fields, fieldName);
1791
+ unset(_formValues, fieldName);
1792
+ }
1793
+ !options2.keepError && unset(_formState.errors, fieldName);
1794
+ !options2.keepDirty && unset(_formState.dirtyFields, fieldName);
1795
+ !options2.keepTouched && unset(_formState.touchedFields, fieldName);
1796
+ !_options.shouldUnregister && !options2.keepDefaultValue && unset(_defaultValues, fieldName);
1797
+ }
1798
+ _subjects.values.next({
1799
+ values: { ..._formValues }
1800
+ });
1801
+ _subjects.state.next({
1802
+ ..._formState,
1803
+ ...!options2.keepDirty ? {} : { isDirty: _getDirty() }
1804
+ });
1805
+ !options2.keepIsValid && _updateValid();
1806
+ };
1807
+ const _updateDisabledField = ({ disabled, name, field, fields, value }) => {
1808
+ if (isBoolean(disabled)) {
1809
+ const inputValue = disabled ? void 0 : isUndefined(value) ? getFieldValue(field ? field._f : get(fields, name)._f) : value;
1810
+ set(_formValues, name, inputValue);
1811
+ updateTouchAndDirty(name, inputValue, false, false, true);
1812
+ }
1813
+ };
1814
+ const register = (name, options2 = {}) => {
1815
+ let field = get(_fields, name);
1816
+ const disabledIsDefined = isBoolean(options2.disabled);
1817
+ set(_fields, name, {
1818
+ ...field || {},
1819
+ _f: {
1820
+ ...field && field._f ? field._f : { ref: { name } },
1821
+ name,
1822
+ mount: true,
1823
+ ...options2
1824
+ }
1825
+ });
1826
+ _names.mount.add(name);
1827
+ if (field) {
1828
+ _updateDisabledField({
1829
+ field,
1830
+ disabled: options2.disabled,
1831
+ name
1832
+ });
1833
+ } else {
1834
+ updateValidAndValue(name, true, options2.value);
1835
+ }
1836
+ return {
1837
+ ...disabledIsDefined ? { disabled: options2.disabled } : {},
1838
+ ..._options.progressive ? {
1839
+ required: !!options2.required,
1840
+ min: getRuleValue(options2.min),
1841
+ max: getRuleValue(options2.max),
1842
+ minLength: getRuleValue(options2.minLength),
1843
+ maxLength: getRuleValue(options2.maxLength),
1844
+ pattern: getRuleValue(options2.pattern)
1845
+ } : {},
1846
+ name,
1847
+ onChange,
1848
+ onBlur: onChange,
1849
+ ref: (ref) => {
1850
+ if (ref) {
1851
+ register(name, options2);
1852
+ field = get(_fields, name);
1853
+ const fieldRef = isUndefined(ref.value) ? ref.querySelectorAll ? ref.querySelectorAll("input,select,textarea")[0] || ref : ref : ref;
1854
+ const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
1855
+ const refs = field._f.refs || [];
1856
+ if (radioOrCheckbox ? refs.find((option) => option === fieldRef) : fieldRef === field._f.ref) {
1857
+ return;
1858
+ }
1859
+ set(_fields, name, {
1860
+ _f: {
1861
+ ...field._f,
1862
+ ...radioOrCheckbox ? {
1863
+ refs: [
1864
+ ...refs.filter(live),
1865
+ fieldRef,
1866
+ ...Array.isArray(get(_defaultValues, name)) ? [{}] : []
1867
+ ],
1868
+ ref: { type: fieldRef.type, name }
1869
+ } : { ref: fieldRef }
1870
+ }
1871
+ });
1872
+ updateValidAndValue(name, false, void 0, fieldRef);
1873
+ } else {
1874
+ field = get(_fields, name, {});
1875
+ if (field._f) {
1876
+ field._f.mount = false;
1877
+ }
1878
+ (_options.shouldUnregister || options2.shouldUnregister) && !(isNameInFieldArray(_names.array, name) && _state.action) && _names.unMount.add(name);
1879
+ }
1880
+ }
1881
+ };
1882
+ };
1883
+ const _focusError = () => _options.shouldFocusError && iterateFieldsByAction(_fields, _focusInput, _names.mount);
1884
+ const _disableForm = (disabled) => {
1885
+ if (isBoolean(disabled)) {
1886
+ _subjects.state.next({ disabled });
1887
+ iterateFieldsByAction(_fields, (ref) => {
1888
+ ref.disabled = disabled;
1889
+ }, 0, false);
1890
+ }
1891
+ };
1892
+ const handleSubmit = (onValid, onInvalid) => async (e) => {
1893
+ if (e) {
1894
+ e.preventDefault && e.preventDefault();
1895
+ e.persist && e.persist();
1896
+ }
1897
+ let fieldValues = cloneObject(_formValues);
1898
+ _subjects.state.next({
1899
+ isSubmitting: true
1900
+ });
1901
+ if (_options.resolver) {
1902
+ const { errors: errors2, values } = await _executeSchema();
1903
+ _formState.errors = errors2;
1904
+ fieldValues = values;
1905
+ } else {
1906
+ await executeBuiltInValidation(_fields);
1907
+ }
1908
+ unset(_formState.errors, "root");
1909
+ if (isEmptyObject(_formState.errors)) {
1910
+ _subjects.state.next({
1911
+ errors: {}
1912
+ });
1913
+ await onValid(fieldValues, e);
1914
+ } else {
1915
+ if (onInvalid) {
1916
+ await onInvalid({ ..._formState.errors }, e);
1917
+ }
1918
+ _focusError();
1919
+ setTimeout(_focusError);
1920
+ }
1921
+ _subjects.state.next({
1922
+ isSubmitted: true,
1923
+ isSubmitting: false,
1924
+ isSubmitSuccessful: isEmptyObject(_formState.errors),
1925
+ submitCount: _formState.submitCount + 1,
1926
+ errors: _formState.errors
1927
+ });
1928
+ };
1929
+ const resetField = (name, options2 = {}) => {
1930
+ if (get(_fields, name)) {
1931
+ if (isUndefined(options2.defaultValue)) {
1932
+ setValue(name, get(_defaultValues, name));
1933
+ } else {
1934
+ setValue(name, options2.defaultValue);
1935
+ set(_defaultValues, name, options2.defaultValue);
1936
+ }
1937
+ if (!options2.keepTouched) {
1938
+ unset(_formState.touchedFields, name);
1939
+ }
1940
+ if (!options2.keepDirty) {
1941
+ unset(_formState.dirtyFields, name);
1942
+ _formState.isDirty = options2.defaultValue ? _getDirty(name, get(_defaultValues, name)) : _getDirty();
1943
+ }
1944
+ if (!options2.keepError) {
1945
+ unset(_formState.errors, name);
1946
+ _proxyFormState.isValid && _updateValid();
1947
+ }
1948
+ _subjects.state.next({ ..._formState });
1949
+ }
1950
+ };
1951
+ const _reset = (formValues, keepStateOptions = {}) => {
1952
+ const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
1953
+ const cloneUpdatedValues = cloneObject(updatedValues);
1954
+ const values = formValues && !isEmptyObject(formValues) ? cloneUpdatedValues : _defaultValues;
1955
+ if (!keepStateOptions.keepDefaultValues) {
1956
+ _defaultValues = updatedValues;
1957
+ }
1958
+ if (!keepStateOptions.keepValues) {
1959
+ if (keepStateOptions.keepDirtyValues || shouldCaptureDirtyFields) {
1960
+ for (const fieldName of _names.mount) {
1961
+ get(_formState.dirtyFields, fieldName) ? set(values, fieldName, get(_formValues, fieldName)) : setValue(fieldName, get(values, fieldName));
1962
+ }
1963
+ } else {
1964
+ if (isWeb && isUndefined(formValues)) {
1965
+ for (const name of _names.mount) {
1966
+ const field = get(_fields, name);
1967
+ if (field && field._f) {
1968
+ const fieldReference = Array.isArray(field._f.refs) ? field._f.refs[0] : field._f.ref;
1969
+ if (isHTMLElement(fieldReference)) {
1970
+ const form = fieldReference.closest("form");
1971
+ if (form) {
1972
+ form.reset();
1973
+ break;
1974
+ }
1975
+ }
1976
+ }
1977
+ }
1978
+ }
1979
+ _fields = {};
1980
+ }
1981
+ _formValues = props.shouldUnregister ? keepStateOptions.keepDefaultValues ? cloneObject(_defaultValues) : {} : cloneObject(values);
1982
+ _subjects.array.next({
1983
+ values: { ...values }
1984
+ });
1985
+ _subjects.values.next({
1986
+ values: { ...values }
1987
+ });
1988
+ }
1989
+ _names = {
1990
+ mount: /* @__PURE__ */ new Set(),
1991
+ unMount: /* @__PURE__ */ new Set(),
1992
+ array: /* @__PURE__ */ new Set(),
1993
+ watch: /* @__PURE__ */ new Set(),
1994
+ watchAll: false,
1995
+ focus: ""
1996
+ };
1997
+ !_state.mount && flushRootRender();
1998
+ _state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
1999
+ _state.watch = !!props.shouldUnregister;
2000
+ _subjects.state.next({
2001
+ submitCount: keepStateOptions.keepSubmitCount ? _formState.submitCount : 0,
2002
+ isDirty: keepStateOptions.keepDirty ? _formState.isDirty : !!(keepStateOptions.keepDefaultValues && !deepEqual(formValues, _defaultValues)),
2003
+ isSubmitted: keepStateOptions.keepIsSubmitted ? _formState.isSubmitted : false,
2004
+ dirtyFields: keepStateOptions.keepDirtyValues ? _formState.dirtyFields : keepStateOptions.keepDefaultValues && formValues ? getDirtyFields(_defaultValues, formValues) : {},
2005
+ touchedFields: keepStateOptions.keepTouched ? _formState.touchedFields : {},
2006
+ errors: keepStateOptions.keepErrors ? _formState.errors : {},
2007
+ isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful ? _formState.isSubmitSuccessful : false,
2008
+ isSubmitting: false
2009
+ });
2010
+ };
2011
+ const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ? formValues(_formValues) : formValues, keepStateOptions);
2012
+ const setFocus = (name, options2 = {}) => {
2013
+ const field = get(_fields, name);
2014
+ const fieldReference = field && field._f;
2015
+ if (fieldReference) {
2016
+ const fieldRef = fieldReference.refs ? fieldReference.refs[0] : fieldReference.ref;
2017
+ if (fieldRef.focus) {
2018
+ fieldRef.focus();
2019
+ options2.shouldSelect && fieldRef.select();
2020
+ }
2021
+ }
2022
+ };
2023
+ const _updateFormState = (updatedFormState) => {
2024
+ _formState = {
2025
+ ..._formState,
2026
+ ...updatedFormState
2027
+ };
2028
+ };
2029
+ const _resetDefaultValues = () => isFunction(_options.defaultValues) && _options.defaultValues().then((values) => {
2030
+ reset(values, _options.resetOptions);
2031
+ _subjects.state.next({
2032
+ isLoading: false
2033
+ });
2034
+ });
2035
+ return {
2036
+ control: {
2037
+ register,
2038
+ unregister,
2039
+ getFieldState,
2040
+ handleSubmit,
2041
+ setError,
2042
+ _executeSchema,
2043
+ _getWatch,
2044
+ _getDirty,
2045
+ _updateValid,
2046
+ _removeUnmounted,
2047
+ _updateFieldArray,
2048
+ _updateDisabledField,
2049
+ _getFieldArray,
2050
+ _reset,
2051
+ _resetDefaultValues,
2052
+ _updateFormState,
2053
+ _disableForm,
2054
+ _subjects,
2055
+ _proxyFormState,
2056
+ get _fields() {
2057
+ return _fields;
2058
+ },
2059
+ get _formValues() {
2060
+ return _formValues;
2061
+ },
2062
+ get _state() {
2063
+ return _state;
2064
+ },
2065
+ set _state(value) {
2066
+ _state = value;
2067
+ },
2068
+ get _defaultValues() {
2069
+ return _defaultValues;
2070
+ },
2071
+ get _names() {
2072
+ return _names;
2073
+ },
2074
+ set _names(value) {
2075
+ _names = value;
2076
+ },
2077
+ get _formState() {
2078
+ return _formState;
2079
+ },
2080
+ set _formState(value) {
2081
+ _formState = value;
2082
+ },
2083
+ get _options() {
2084
+ return _options;
2085
+ },
2086
+ set _options(value) {
2087
+ _options = {
2088
+ ..._options,
2089
+ ...value
2090
+ };
2091
+ }
2092
+ },
2093
+ trigger,
2094
+ register,
2095
+ handleSubmit,
2096
+ watch,
2097
+ setValue,
2098
+ getValues,
2099
+ reset,
2100
+ resetField,
2101
+ clearErrors,
2102
+ unregister,
2103
+ setError,
2104
+ setFocus,
2105
+ getFieldState
2106
+ };
2107
+ }
2108
+ function useForm(props = {}) {
2109
+ const _formControl = index.Cn.useRef();
2110
+ const _values = index.Cn.useRef();
2111
+ const [formState, updateFormState] = index.Cn.useState({
2112
+ isDirty: false,
2113
+ isValidating: false,
2114
+ isLoading: isFunction(props.defaultValues),
2115
+ isSubmitted: false,
2116
+ isSubmitting: false,
2117
+ isSubmitSuccessful: false,
2118
+ isValid: false,
2119
+ submitCount: 0,
2120
+ dirtyFields: {},
2121
+ touchedFields: {},
2122
+ errors: {},
2123
+ disabled: false,
2124
+ defaultValues: isFunction(props.defaultValues) ? void 0 : props.defaultValues
2125
+ });
2126
+ if (!_formControl.current) {
2127
+ _formControl.current = {
2128
+ ...createFormControl(props, () => updateFormState((formState2) => ({ ...formState2 }))),
2129
+ formState
2130
+ };
2131
+ }
2132
+ const control = _formControl.current.control;
2133
+ control._options = props;
2134
+ useSubscribe({
2135
+ subject: control._subjects.state,
2136
+ next: (value) => {
2137
+ if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
2138
+ updateFormState({ ...control._formState });
2139
+ }
2140
+ }
2141
+ });
2142
+ index.Cn.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
2143
+ index.Cn.useEffect(() => {
2144
+ if (control._proxyFormState.isDirty) {
2145
+ const isDirty = control._getDirty();
2146
+ if (isDirty !== formState.isDirty) {
2147
+ control._subjects.state.next({
2148
+ isDirty
2149
+ });
2150
+ }
2151
+ }
2152
+ }, [control, formState.isDirty]);
2153
+ index.Cn.useEffect(() => {
2154
+ if (props.values && !deepEqual(props.values, _values.current)) {
2155
+ control._reset(props.values, control._options.resetOptions);
2156
+ _values.current = props.values;
2157
+ } else {
2158
+ control._resetDefaultValues();
2159
+ }
2160
+ }, [props.values, control]);
2161
+ index.Cn.useEffect(() => {
2162
+ if (!control._state.mount) {
2163
+ control._updateValid();
2164
+ control._state.mount = true;
2165
+ }
2166
+ if (control._state.watch) {
2167
+ control._state.watch = false;
2168
+ control._subjects.state.next({ ...control._formState });
2169
+ }
2170
+ control._removeUnmounted();
2171
+ });
2172
+ _formControl.current.formState = getProxyFormState(formState, control);
2173
+ return _formControl.current;
2174
+ }
2175
+ var t = function(e, t2, i2) {
2176
+ if (e && "reportValidity" in e) {
2177
+ var n2 = get(i2, t2);
2178
+ e.setCustomValidity(n2 && n2.message || ""), e.reportValidity();
2179
+ }
2180
+ }, i$1 = function(r, e) {
2181
+ var i2 = function(i3) {
2182
+ var n3 = e.fields[i3];
2183
+ n3 && n3.ref && "reportValidity" in n3.ref ? t(n3.ref, i3, r) : n3.refs && n3.refs.forEach(function(e2) {
2184
+ return t(e2, i3, r);
2185
+ });
2186
+ };
2187
+ for (var n2 in e.fields)
2188
+ i2(n2);
2189
+ }, n = function(t2, n2) {
2190
+ n2.shouldUseNativeValidation && i$1(t2, n2);
2191
+ var f = {};
2192
+ for (var s in t2) {
2193
+ var u = get(n2.fields, s), c = Object.assign(t2[s] || {}, { ref: u && u.ref });
2194
+ if (a$1(n2.names || Object.keys(t2), s)) {
2195
+ var l = Object.assign({}, o(get(f, s)));
2196
+ set(l, "root", c), set(f, s, l);
2197
+ } else
2198
+ set(f, s, c);
2199
+ }
2200
+ return f;
2201
+ }, o = function(r) {
2202
+ return Array.isArray(r) ? r.filter(Boolean) : [];
2203
+ }, a$1 = function(r, e) {
2204
+ return r.some(function(r2) {
2205
+ return r2.startsWith(e + ".");
2206
+ });
2207
+ };
2208
+ var a = function(r, e) {
2209
+ for (var t2 = {}; r.issues.length; ) {
2210
+ var o2 = r.issues[0];
2211
+ if (o2.path) {
2212
+ var a2 = o2.path.map(function(r2) {
2213
+ return r2.key;
2214
+ }).join(".");
2215
+ if (t2[a2] || (t2[a2] = { message: o2.message, type: o2.validation }), e) {
2216
+ var i2 = t2[a2].types, s = i2 && i2[o2.validation];
2217
+ t2[a2] = appendErrors(a2, e, t2, o2.validation, s ? [].concat(s, o2.message) : o2.message);
2218
+ }
2219
+ r.issues.shift();
2220
+ }
2221
+ }
2222
+ return t2;
2223
+ }, i = function(n$1, i2, s) {
2224
+ return void 0 === s && (s = {}), function(u, c, f) {
2225
+ try {
2226
+ return Promise.resolve(function(r, o2) {
2227
+ try {
2228
+ var a2 = function() {
2229
+ function r2(r3) {
2230
+ return { values: s.raw ? u : r3, errors: {} };
2231
+ }
2232
+ var o3 = Object.assign({}, { abortEarly: false, abortPipeEarly: false }, i2);
2233
+ return "sync" === s.mode ? r2(index.parse(n$1, u, o3)) : Promise.resolve(index.parseAsync(n$1, u, o3)).then(r2);
2234
+ }();
2235
+ } catch (r2) {
2236
+ return o2(r2);
2237
+ }
2238
+ return a2 && a2.then ? a2.then(void 0, o2) : a2;
2239
+ }(0, function(e) {
2240
+ if (e instanceof index.ValiError)
2241
+ return { values: {}, errors: n(a(e, !f.shouldUseNativeValidation && "all" === f.criteriaMode), f) };
2242
+ throw e;
2243
+ }));
2244
+ } catch (r) {
2245
+ return Promise.reject(r);
2246
+ }
2247
+ };
2248
+ };
2249
+ const submitIfSingleChecked = (form) => {
2250
+ const formObj = Object.fromEntries(new FormData(form).entries());
2251
+ const isSingleChecked = Object.keys(formObj).length;
2252
+ if (!isSingleChecked)
2253
+ return;
2254
+ form.dispatchEvent(new Event("submit", {
2255
+ bubbles: true
2256
+ }));
2257
+ };
2258
+ const isMultipleChoiceSubmission = index.isSubmissionOfType("multiple-choice");
2259
+ const getResolver$1 = (config) => {
2260
+ const length = {
2261
+ min: config.minSelected ?? 0,
2262
+ max: config.maxSelected ?? config.options.length
2263
+ };
2264
+ return i(index.object({
2265
+ checked: index.transform(index.record(index.boolean()), (o2) => Object.entries(o2).filter(([_, v]) => v).map(([k, _]) => k), [index.maxLength(length.max, `Please select at most ${length.max} option${length.max !== 1 ? "s" : ""}`), index.minLength(length.min, `Please select at least ${length.min} option${length.min !== 1 ? "s" : ""}`)])
2266
+ }));
2267
+ };
2268
+ const ChatInputMultipleChoice = ({
2269
+ input,
2270
+ onSubmitSuccess,
2271
+ onHeightChange
2272
+ }) => {
2273
+ var _a, _b;
2274
+ const submission = input.key ? (_a = index.application.current$.value.application) == null ? void 0 : _a.data.submissions[input.key] : void 0;
2275
+ const {
2276
+ register,
2277
+ handleSubmit,
2278
+ formState: {
2279
+ errors: errors2
2280
+ }
2281
+ } = useForm({
2282
+ defaultValues: {
2283
+ checked: isMultipleChoiceSubmission(submission) ? Object.fromEntries(submission.value.map((key) => [key, true])) : {}
2284
+ },
2285
+ resolver: getResolver$1(input.config)
2286
+ });
2287
+ const focusRef = useFocusOnMount();
2288
+ const isSingleChoice = input.config.minSelected === 1 && input.config.maxSelected === 1;
2289
+ return index.o("form", {
2290
+ noValidate: true,
2291
+ class: "flex flex-col gap-1",
2292
+ onChange: (e) => {
2293
+ if (isSingleChoice) {
2294
+ submitIfSingleChecked(e.currentTarget);
2295
+ }
2296
+ },
2297
+ onSubmit: handleSubmit((submission2) => {
2298
+ const checked = submission2.checked;
2299
+ onSubmitSuccess(checked);
2300
+ }),
2301
+ children: [index.o("div", {
2302
+ class: "flex items-center gap-2",
2303
+ children: [index.o("div", {
2304
+ class: index.clsx("flex w-full flex-1 flex-wrap gap-3 p-1", {
2305
+ "justify-center": input.config.options.length === 1
2306
+ }),
2307
+ children: input.config.options.map((option, i2) => {
2308
+ const id = `checked.${option.value}`;
2309
+ const {
2310
+ ref: setRef,
2311
+ ...props
2312
+ } = register(id);
2313
+ return index.o("div", {
2314
+ children: [index.o("input", {
2315
+ autoFocus: i2 === 0,
2316
+ ref: (e) => {
2317
+ if (e && i2 === 0) {
2318
+ focusRef.current = e;
2319
+ }
2320
+ setRef(e);
2321
+ },
2322
+ id,
2323
+ ...props,
2324
+ class: "peer sr-only",
2325
+ type: "checkbox"
2326
+ }), index.o("label", {
2327
+ class: "bg-lowest peer-focus-visible:ring-accent-7 active:outline-neutral-10 ease-expo-out outline-neutral-12/5 text-neutral-11 peer-checked:outline-accent-7 peer-checked:bg-accent-2 peer-checked:text-accent-9 block rounded-2xl px-2.5 py-1 outline outline-2 ring-0 ring-transparent transition-all duration-300 selection:bg-transparent peer-focus-visible:ring-4 peer-focus-visible:ring-offset-2",
2328
+ htmlFor: id,
2329
+ children: option.label
2330
+ })]
2331
+ }, option.value);
2332
+ })
2333
+ }), !isSingleChoice && index.o(SendButton, {})]
2334
+ }), index.o(InputError, {
2335
+ onAnimationComplete: onHeightChange,
2336
+ error: (_b = errors2.checked) == null ? void 0 : _b.root
2337
+ })]
2338
+ });
2339
+ };
2340
+ const errors = {
2341
+ email: "That doesn’t look like a valid email address",
2342
+ phone: "That doesn’t look like a valid phone number"
2343
+ };
2344
+ const PhoneSchema = index.string(errors.phone, [index.regex(/^\+?[0-9 -]+$/, errors.phone)]);
2345
+ const inputFormatToSchema = {
2346
+ email: index.string(errors.email, [index.email(errors.email)]),
2347
+ phone: index.transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, "")),
2348
+ text: index.string([index.minLength(1, "Please enter some text")]),
2349
+ url: index.string([index.url("That doesn’t look like a valid URL")])
2350
+ };
2351
+ const inputFormatToProps = {
2352
+ email: {
2353
+ type: "email",
2354
+ inputMode: "email",
2355
+ formNoValidate: true
2356
+ },
2357
+ phone: {
2358
+ type: "tel",
2359
+ inputMode: "tel"
2360
+ },
2361
+ text: {
2362
+ type: "text",
2363
+ inputMode: "text"
2364
+ },
2365
+ url: {
2366
+ type: "url",
2367
+ inputMode: "url",
2368
+ formNoValidate: true
2369
+ }
2370
+ };
2371
+ const isTextSubmission = index.isSubmissionOfType("text");
2372
+ const getResolver = (config) => i(index.object({
2373
+ text: inputFormatToSchema[config.format]
2374
+ }));
2375
+ const ChatInputText = ({
2376
+ input,
2377
+ onSubmitSuccess,
2378
+ onHeightChange
2379
+ }) => {
2380
+ var _a;
2381
+ const submission = input.key ? (_a = index.application.current$.value.application) == null ? void 0 : _a.data.submissions[input.key] : void 0;
2382
+ const {
2383
+ register,
2384
+ handleSubmit,
2385
+ formState: {
2386
+ errors: errors2
2387
+ }
2388
+ } = useForm({
2389
+ defaultValues: {
2390
+ text: isTextSubmission(submission) ? submission.value : ""
2391
+ },
2392
+ resolver: getResolver(input.config)
2393
+ });
2394
+ const {
2395
+ ref: setRef,
2396
+ ...props
2397
+ } = register("text", {
2398
+ required: true
2399
+ });
2400
+ const ref = index._$1();
2401
+ index.y(() => {
2402
+ if (ref.current) {
2403
+ ref.current.focus();
2404
+ ref.current.select();
2405
+ }
2406
+ }, []);
2407
+ return index.o("form", {
2408
+ noValidate: true,
2409
+ class: "flex flex-col gap-1",
2410
+ onSubmit: handleSubmit((submission2) => {
2411
+ onSubmitSuccess(submission2.text);
2412
+ }),
2413
+ children: [index.o("div", {
2414
+ class: "flex items-center gap-2",
2415
+ children: [index.o("input", {
2416
+ id: "chat-input",
2417
+ ...props,
2418
+ ...inputFormatToProps[input.config.format],
2419
+ autocomplete: "off",
2420
+ autoCapitalize: "off",
2421
+ autoCorrect: "off",
2422
+ autoFocus: true,
2423
+ ref: (e) => {
2424
+ if (e) {
2425
+ ref.current = e;
2426
+ }
2427
+ setRef(e);
2428
+ },
2429
+ class: "outline-neutral-12/5 ease-expo-out placeholder:text-neutral-5 focus-visible:outline-accent-7 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2 transition-all duration-300",
2430
+ placeholder: input.config.placeholder
2431
+ }), index.o(SendButton, {})]
2432
+ }), index.o(InputError, {
2433
+ onAnimationComplete: onHeightChange,
2434
+ error: errors2.text
2435
+ })]
2436
+ });
2437
+ };
2438
+ const ChatInput = ({
2439
+ onSubmit,
2440
+ onInputChange,
2441
+ input
2442
+ }) => {
2443
+ const inputWrapperRef = index._$1(null);
2444
+ const updateHeight = index.T(() => {
2445
+ if (inputWrapperRef.current) {
2446
+ index.inputHeight.value = inputWrapperRef.current.getBoundingClientRect().height;
2447
+ }
2448
+ }, []);
2449
+ index.p(() => {
2450
+ updateHeight();
2451
+ onInputChange(input == null ? void 0 : input.type);
2452
+ }, [input == null ? void 0 : input.type, onInputChange, updateHeight]);
2453
+ const handleSubmitSuccess = (type) => (value) => onSubmit({
2454
+ type,
2455
+ value
2456
+ });
2457
+ return index.o(framerMotion.m.div, {
2458
+ initial: {
2459
+ height: 0
2460
+ },
2461
+ animate: {
2462
+ height: index.inputHeight.value
2463
+ },
2464
+ exit: {
2465
+ height: 0,
2466
+ opacity: 0
2467
+ },
2468
+ class: "bg-neutral-2/80 absolute bottom-0 w-full overflow-hidden rounded-b-3xl backdrop-blur-md backdrop-saturate-150",
2469
+ children: index.o("div", {
2470
+ ref: inputWrapperRef,
2471
+ class: "border-neutral-12/5 border-t p-2.5",
2472
+ children: index.N({
2473
+ application: index.application,
2474
+ input,
2475
+ onHeightChange: updateHeight
2476
+ }).with({
2477
+ input: index._.nullish
2478
+ }, () => index.o("div", {
2479
+ class: "flex items-center gap-2",
2480
+ children: [index.o("input", {
2481
+ "aria-hidden": "true",
2482
+ id: "chat-input",
2483
+ class: "outline-neutral-12/5 placeholder:text-neutral-4 focus-visible:outline-accent-9 caret-accent-9 flex-grow rounded-full px-3 py-1 text-base outline outline-2",
2484
+ disabled: true
2485
+ }), index.o(SendButton, {
2486
+ disabled: true,
2487
+ "aria-hidden": "true",
2488
+ tabIndex: -1
2489
+ })]
2490
+ })).with({
2491
+ input: {
2492
+ type: "text"
2493
+ }
2494
+ }, (props) => index.o(ChatInputText, {
2495
+ onSubmitSuccess: handleSubmitSuccess(props.input.type),
2496
+ ...props
2497
+ })).with({
2498
+ input: {
2499
+ type: "multiple-choice"
2500
+ }
2501
+ }, (props) => index.o(ChatInputMultipleChoice, {
2502
+ onSubmitSuccess: handleSubmitSuccess(props.input.type),
2503
+ ...props
2504
+ })).with({
2505
+ input: {
2506
+ type: "boolean"
2507
+ }
2508
+ }, (props) => index.o(ChatInputBoolean, {
2509
+ onSubmitSuccess: handleSubmitSuccess(props.input.type),
2510
+ ...props
2511
+ })).with({
2512
+ input: {
2513
+ type: "file"
2514
+ }
2515
+ }, (props) => index.o(ChatInputFile, {
2516
+ onSubmitSuccess: handleSubmitSuccess(props.input.type),
2517
+ ...props
2518
+ })).exhaustive()
2519
+ })
2520
+ });
2521
+ };
2522
+ const falsyToString = (value) => typeof value === "boolean" ? "".concat(value) : value === 0 ? "0" : value;
2523
+ const cx = index.clsx;
2524
+ const cva = (base, config) => {
2525
+ return (props) => {
2526
+ var ref;
2527
+ if ((config === null || config === void 0 ? void 0 : config.variants) == null)
2528
+ return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
2529
+ const { variants, defaultVariants } = config;
2530
+ const getVariantClassNames = Object.keys(variants).map((variant) => {
2531
+ const variantProp = props === null || props === void 0 ? void 0 : props[variant];
2532
+ const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
2533
+ if (variantProp === null)
2534
+ return null;
2535
+ const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
2536
+ return variants[variant][variantKey];
2537
+ });
2538
+ const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
2539
+ let [key, value] = param;
2540
+ if (value === void 0) {
2541
+ return acc;
2542
+ }
2543
+ acc[key] = value;
2544
+ return acc;
2545
+ }, {});
2546
+ const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1) => {
2547
+ let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param1;
2548
+ return Object.entries(compoundVariantOptions).every((param) => {
2549
+ let [key, value] = param;
2550
+ return Array.isArray(value) ? value.includes({
2551
+ ...defaultVariants,
2552
+ ...propsWithoutUndefined
2553
+ }[key]) : {
2554
+ ...defaultVariants,
2555
+ ...propsWithoutUndefined
2556
+ }[key] === value;
2557
+ }) ? [
2558
+ ...acc,
2559
+ cvClass,
2560
+ cvClassName
2561
+ ] : acc;
2562
+ }, []);
2563
+ return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
2564
+ };
2565
+ };
2566
+ const chatBubbleVariants = cva("max-w-[min(100%,24rem)] [text-wrap:pretty] leading-snug flex-shrink-1 min-w-[2rem] text-md py-2 px-3 rounded-[18px] min-h-[36px] break-words", {
2567
+ variants: {
2568
+ side: {
2569
+ left: "bg-lowest text-neutral-12 shadow-surface-sm outline outline-1 outline-neutral-11/[.08] rounded-bl-md",
2570
+ right: "ml-auto bg-accent-7 text-lowest rounded-br-md bubble-right"
2571
+ },
2572
+ transitionState: {
2573
+ entering: "opacity-0 translate-y-8",
2574
+ entered: "opacity-100 translate-y-0",
2575
+ exiting: "opacity-0 scale-0",
2576
+ exited: ""
2577
+ }
2578
+ },
2579
+ defaultVariants: {
2580
+ side: "left"
2581
+ }
2582
+ });
2583
+ const motionVariants = {
2584
+ hidden: {
2585
+ y: "100%",
2586
+ scale: 0.75
2587
+ },
2588
+ shown: {
2589
+ y: 0,
2590
+ scale: 1
2591
+ }
2592
+ };
2593
+ const ChatBubble = ({
2594
+ children,
2595
+ className,
2596
+ transitionState,
2597
+ side,
2598
+ ...props
2599
+ }) => {
2600
+ return index.o(framerMotion.m.p, {
2601
+ variants: motionVariants,
2602
+ initial: "hidden",
2603
+ animate: "shown",
2604
+ transition: {
2605
+ type: "spring",
2606
+ damping: 25,
2607
+ stiffness: 500
2608
+ },
2609
+ "data-transition": transitionState,
2610
+ style: {
2611
+ transformOrigin: side === "left" ? "0% 50%" : "100% 50%"
2612
+ },
2613
+ class: chatBubbleVariants({
2614
+ className,
2615
+ side,
2616
+ transitionState
2617
+ }),
2618
+ ...props,
2619
+ children
2620
+ });
2621
+ };
2622
+ const TypingIndicator = ({
2623
+ className,
2624
+ ...props
2625
+ }) => {
2626
+ return index.o("div", {
2627
+ class: index.clsx("flex gap-1 p-4", className),
2628
+ ...props,
2629
+ children: Array.from({
2630
+ length: 3
2631
+ }, (_, i2) => index.o("div", {
2632
+ class: "bg-accent-7 h-1.5 w-1.5 animate-bounce rounded-full",
2633
+ style: {
2634
+ animationDelay: `${-i2 * 200}ms`
2635
+ }
2636
+ }))
2637
+ });
2638
+ };
2639
+ const authorToSide = {
2640
+ bot: "left",
2641
+ user: "right"
2642
+ };
2643
+ const systemMessageStyle = cva("w-full select-none py-2 text-center text-[10px] uppercase tracking-widest drop-shadow-[0_1.5px_white]", {
2644
+ variants: {
2645
+ variant: {
2646
+ info: "text-neutral-8",
2647
+ warning: "text-[#FFC107]",
2648
+ error: "text-error-9",
2649
+ success: "text-[#4CAF50]"
2650
+ }
2651
+ }
2652
+ });
2653
+ const JobApplicationMessages = ({
2654
+ messages,
2655
+ isBotTyping
2656
+ }) => {
2657
+ return index.o("ol", {
2658
+ "aria-label": "Chat messages",
2659
+ class: "flex flex-grow flex-col justify-end gap-2 p-2 pt-[calc(var(--header-height)+1rem)]",
2660
+ children: [index.o(framerMotion.AnimatePresence, {
2661
+ initial: false,
2662
+ children: messages.map((message, i2) => index.o("li", {
2663
+ class: "flex",
2664
+ children: index.N(message).with({
2665
+ type: "system"
2666
+ }, (message2) => index.o("p", {
2667
+ class: systemMessageStyle({
2668
+ variant: message2.variant
2669
+ }),
2670
+ children: message2.text
2671
+ })).with({
2672
+ type: "text",
2673
+ author: index._.union("bot", "user")
2674
+ }, (message2) => {
2675
+ return index.o(ChatBubble, {
2676
+ side: authorToSide[message2.author],
2677
+ children: message2.text
2678
+ }, i2);
2679
+ }).with({
2680
+ type: "link"
2681
+ }, (message2) => {
2682
+ return index.o("div", {
2683
+ class: "bg-accent-8/5 flex w-full items-center justify-center overflow-hidden rounded-xl py-2",
2684
+ children: index.o("a", {
2685
+ class: "bg-lowest shadow-surface-sm ring-accent-8/20 hover:ring-accent-8 active:bg-accent-2 active:text-accent-10 text-accent-9 focus-visible:ring-accent-7/50 flex items-center gap-1.5 truncate rounded-full py-2 pl-4 pr-2.5 no-underline ring-1 transition-all focus:outline-none focus-visible:ring-4 focus-visible:ring-offset-2",
2686
+ target: "_blank",
2687
+ href: message2.href,
2688
+ children: [message2.text, index.o("svg", {
2689
+ width: "15",
2690
+ height: "15",
2691
+ viewBox: "0 0 15 15",
2692
+ fill: "none",
2693
+ xmlns: "http://www.w3.org/2000/svg",
2694
+ children: index.o("path", {
2695
+ 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",
2696
+ fill: "currentColor",
2697
+ "fill-rule": "evenodd",
2698
+ "clip-rule": "evenodd"
2699
+ })
2700
+ })]
2701
+ })
2702
+ });
2703
+ }).with({
2704
+ type: "image"
2705
+ }, (image) => index.o("img", {
2706
+ class: "shadow-surface-md w-full max-w-[min(100%,24rem)] rounded-2xl",
2707
+ src: image.url,
2708
+ style: {
2709
+ aspectRatio: image.width / image.height
2710
+ }
2711
+ })).with({
2712
+ type: "file"
2713
+ }, (file) => {
2714
+ return index.o(FileThumbnail, {
2715
+ class: file.author === "bot" ? "" : "ml-auto",
2716
+ file: {
2717
+ name: file.fileName,
2718
+ sizeKb: file.fileSizeKb
2719
+ }
2720
+ });
2721
+ }).exhaustive()
2722
+ }, i2))
2723
+ }), index.o("aside", {
2724
+ "aria-hidden": true,
2725
+ children: isBotTyping && index.o(TypingIndicator, {})
2726
+ })]
2727
+ });
2728
+ };
2729
+ const TYPING_SPEED_MS_PER_CHARACTER = 25;
2730
+ const useChatService = () => {
2731
+ const chatRef = index._$1(null);
2732
+ const [isBotTyping, setIsBotTyping] = index.h(false);
2733
+ const [onSubmitSuccessFn, setOnSubmitSuccessFn] = index.h(() => () => {
2734
+ });
2735
+ const scrollToEnd = index.F(() => (options2) => {
2736
+ var _a;
2737
+ return (_a = chatRef.current) == null ? void 0 : _a.scrollTo({
2738
+ top: chatRef.current.scrollHeight,
2739
+ ...options2
2740
+ });
2741
+ }, [chatRef]);
2742
+ const chatService = index.F(() => ({
2743
+ send: async ({
2744
+ message,
2745
+ signal,
2746
+ groupId
2747
+ }) => {
2748
+ await index.N(message).with({
2749
+ author: "bot",
2750
+ type: "text"
2751
+ }, async (message2) => {
2752
+ if (signal == null ? void 0 : signal.aborted)
2753
+ throw new index.AbortedError();
2754
+ setIsBotTyping(true);
2755
+ const typingTime = Math.max(20, message2.text.length) * TYPING_SPEED_MS_PER_CHARACTER;
2756
+ await new Promise((resolve) => {
2757
+ return setTimeout(resolve, typingTime, {
2758
+ signal
2759
+ });
2760
+ });
2761
+ setIsBotTyping(false);
2762
+ }).otherwise(async () => void 0);
2763
+ if (signal == null ? void 0 : signal.aborted)
2764
+ throw new index.AbortedError();
2765
+ index.application.addMessage(message, groupId);
2766
+ },
2767
+ input: async ({
2768
+ input,
2769
+ signal
2770
+ }) => {
2771
+ if (signal == null ? void 0 : signal.aborted)
2772
+ throw new index.AbortedError();
2773
+ index.application.setInput(input);
2774
+ return await new Promise((resolve) => {
2775
+ const submitFunction = (submission) => {
2776
+ if (signal == null ? void 0 : signal.aborted)
2777
+ throw new index.AbortedError();
2778
+ index.application.setInput(void 0);
2779
+ if (input.key) {
2780
+ index.application.setSubmission(input.key, submission);
2781
+ }
2782
+ resolve(submission);
2783
+ };
2784
+ setOnSubmitSuccessFn(() => submitFunction);
2785
+ });
2786
+ }
2787
+ }), []);
2788
+ return {
2789
+ chatRef,
2790
+ chatService,
2791
+ isBotTyping,
2792
+ onSubmitSuccessFn,
2793
+ scrollToEnd
2794
+ };
2795
+ };
2796
+ const JobApplicationContent = ({
2797
+ currentApplication,
2798
+ logger,
2799
+ apiClient,
2800
+ analytics
2801
+ }) => {
2802
+ const {
2803
+ chatRef,
2804
+ chatService,
2805
+ isBotTyping,
2806
+ onSubmitSuccessFn,
2807
+ scrollToEnd
2808
+ } = useChatService();
2809
+ const view = index.viewState.value;
2810
+ const flow = currentApplication.flow;
2811
+ const job = currentApplication.job;
2812
+ index.y(() => {
2813
+ if (view === "maximised")
2814
+ scrollToEnd({
2815
+ behavior: "instant"
2816
+ });
2817
+ }, [scrollToEnd, view]);
2818
+ index.p(() => {
2819
+ scrollToEnd({
2820
+ behavior: "smooth"
2821
+ });
2822
+ }, [currentApplication.data.messages, scrollToEnd]);
2823
+ index.y(() => {
2824
+ const {
2825
+ state,
2826
+ application: currentApplication2
2827
+ } = index.application.current$.peek();
2828
+ if (state !== "loaded")
2829
+ throw new Error(index.ERROR_MESSAGES.invalid_state);
2830
+ const fromNodeId = currentApplication2.data.currentNodeId;
2831
+ scrollToEnd({
2832
+ behavior: "instant"
2833
+ });
2834
+ index.application.setInput(void 0);
2835
+ if (currentApplication2.data.isFinished)
2836
+ return;
2837
+ const fromBeginning = currentApplication2.data.messages.length === 0;
2838
+ if (fromBeginning) {
2839
+ analytics.log({
2840
+ event: "APPLY_START",
2841
+ properties: {
2842
+ job_id: job.id
2843
+ },
2844
+ customProperties: {
2845
+ flow_id: flow.id
2846
+ }
2847
+ });
2848
+ }
2849
+ index.application.removeLastGroupMessagesById(fromNodeId);
2850
+ const {
2851
+ interpret: interpret2,
2852
+ abort
2853
+ } = createFlowInterpreter({
2854
+ context: {
2855
+ jobId: job.id,
2856
+ flowId: flow.id
2857
+ },
2858
+ analytics,
2859
+ apiClient,
2860
+ logger,
2861
+ flow: flow.nodes,
2862
+ chatService,
2863
+ // We need to get fresh submissions, that’s why we call `peek` here.
2864
+ getSubmissions: () => {
2865
+ var _a;
2866
+ return (_a = index.application.current$.peek().application) == null ? void 0 : _a.data.submissions;
2867
+ },
2868
+ onInterpret: (node, prevNode) => {
2869
+ analytics.log({
2870
+ event: "FLOW_NODE",
2871
+ properties: {
2872
+ flow_id: flow.id,
2873
+ flow_version: flow.version,
2874
+ job_id: job.id,
2875
+ from_node_id: prevNode ? prevNode.id : null,
2876
+ to_node_id: node.id,
2877
+ sequence: 1
2878
+ }
2879
+ });
2880
+ index.application.setCurrentNodeId(node.id);
2881
+ },
2882
+ onFlowEnd: async () => {
2883
+ index.application.markAsFinished();
2884
+ }
2885
+ });
2886
+ interpret2(fromNodeId);
2887
+ return abort;
2888
+ }, [analytics, apiClient, chatService, logger, scrollToEnd, flow, job.id, currentApplication.startedAt]);
2889
+ return index.o(index.k, {
2890
+ children: [index.o("div", {
2891
+ ref: chatRef,
2892
+ className: "hide-scrollbars relative flex max-w-full flex-grow flex-col overflow-y-scroll",
2893
+ style: {
2894
+ WebkitOverflowScrolling: "touch",
2895
+ paddingBottom: index.inputHeight.value
2896
+ },
2897
+ children: index.o(framerMotion.AnimatePresence, {
2898
+ children: index.o(JobApplicationMessages, {
2899
+ isBotTyping,
2900
+ messages: currentApplication.data.messages
2901
+ })
2902
+ })
2903
+ }), index.o(ChatInput, {
2904
+ input: currentApplication.data.currentInput,
2905
+ onInputChange: () => scrollToEnd({
2906
+ behavior: "smooth"
2907
+ }),
2908
+ onSubmit: onSubmitSuccessFn
2909
+ })]
2910
+ });
2911
+ };
2912
+ exports.JobApplicationContent = JobApplicationContent;