@inploi/plugin-chatbot 3.2.5 → 3.2.7

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