@bigbinary/neeto-form-frontend 4.4.27 → 4.4.29

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.
Files changed (109) hide show
  1. package/dist/.ready +1 -1
  2. package/dist/BuildForm.js +12 -11
  3. package/dist/BuildForm.js.map +1 -1
  4. package/dist/ExternalForm.js +8 -6
  5. package/dist/ExternalForm.js.map +1 -1
  6. package/dist/Submission.js +1 -1
  7. package/dist/UrlBuilder.js +4 -4
  8. package/dist/{buildForm-CrOWLvLE.js → buildForm-DZ6Bl-ye.js} +2 -2
  9. package/dist/{buildForm-CrOWLvLE.js.map → buildForm-DZ6Bl-ye.js.map} +1 -1
  10. package/dist/cjs/BuildForm.js +12 -11
  11. package/dist/cjs/BuildForm.js.map +1 -1
  12. package/dist/cjs/ExternalForm.js +8 -6
  13. package/dist/cjs/ExternalForm.js.map +1 -1
  14. package/dist/cjs/Submission.js +1 -1
  15. package/dist/cjs/UrlBuilder.js +4 -4
  16. package/dist/{buildForm-DfMpfuSp.js → cjs/buildForm-CC9itFZl.js} +2 -2
  17. package/dist/cjs/buildForm-CC9itFZl.js.map +1 -0
  18. package/dist/{constants-D5JlvWws.js → cjs/constants-BMSFHZ0w.js} +13 -13
  19. package/dist/cjs/constants-BMSFHZ0w.js.map +1 -0
  20. package/dist/cjs/hooks.js +4 -4
  21. package/dist/{index-Beo6ztaM.js → cjs/index-BQ76EIiQ.js} +2 -2
  22. package/dist/cjs/index-BQ76EIiQ.js.map +1 -0
  23. package/dist/cjs/index.js +6 -6
  24. package/dist/{useFormSubmission-D3O7sDHp.js → cjs/useFormSubmission-CFV6smu9.js} +2 -2
  25. package/dist/cjs/useFormSubmission-CFV6smu9.js.map +1 -0
  26. package/dist/{utils-DBhM5B2L.js → cjs/utils-DDBCeNw7.js} +47 -43
  27. package/dist/cjs/utils-DDBCeNw7.js.map +1 -0
  28. package/dist/cjs/v2/BuildForm.js +3236 -0
  29. package/dist/cjs/v2/BuildForm.js.map +1 -0
  30. package/dist/cjs/v2/ExternalForm.js +661 -0
  31. package/dist/cjs/v2/ExternalForm.js.map +1 -0
  32. package/dist/cjs/v2/NeetoFormProvider.js +13 -0
  33. package/dist/cjs/v2/NeetoFormProvider.js.map +1 -0
  34. package/dist/cjs/v2/Submission.js +2836 -0
  35. package/dist/cjs/v2/Submission.js.map +1 -0
  36. package/dist/cjs/v2/UrlBuilder.js +352 -0
  37. package/dist/cjs/v2/UrlBuilder.js.map +1 -0
  38. package/dist/cjs/v2/buildForm-bsda0SF2.js +38 -0
  39. package/dist/cjs/v2/buildForm-bsda0SF2.js.map +1 -0
  40. package/dist/cjs/v2/constants-8Qh_klGy.js +36 -0
  41. package/dist/cjs/v2/constants-8Qh_klGy.js.map +1 -0
  42. package/dist/cjs/v2/hooks.js +33 -0
  43. package/dist/cjs/v2/hooks.js.map +1 -0
  44. package/dist/cjs/v2/index-C1-XsBQ0.js +21 -0
  45. package/dist/cjs/v2/index-C1-XsBQ0.js.map +1 -0
  46. package/dist/cjs/v2/index.js +112 -0
  47. package/dist/cjs/v2/index.js.map +1 -0
  48. package/dist/cjs/v2/useFormApi-DD0_MxNV.js +480 -0
  49. package/dist/cjs/v2/useFormApi-DD0_MxNV.js.map +1 -0
  50. package/dist/cjs/v2/useFormSubmission-BWH7QxuC.js +24 -0
  51. package/dist/cjs/v2/useFormSubmission-BWH7QxuC.js.map +1 -0
  52. package/dist/cjs/v2/utils-DxDOZ8uO.js +2793 -0
  53. package/dist/cjs/v2/utils-DxDOZ8uO.js.map +1 -0
  54. package/dist/cjs/v2/yup-D0709IcB.js +1177 -0
  55. package/dist/cjs/v2/yup-D0709IcB.js.map +1 -0
  56. package/dist/{yup-DoKhabp1.js → cjs/yup-W5RzIslJ.js} +3 -3
  57. package/dist/cjs/yup-W5RzIslJ.js.map +1 -0
  58. package/dist/{constants-Cj0XxE8a.js → constants-BV0Ig0ag.js} +13 -13
  59. package/dist/constants-BV0Ig0ag.js.map +1 -0
  60. package/dist/hooks.js +4 -4
  61. package/dist/{index-DhtQJpD_.js → index-DE7lvoSf.js} +2 -2
  62. package/dist/{index-DhtQJpD_.js.map → index-DE7lvoSf.js.map} +1 -1
  63. package/dist/index.js +6 -6
  64. package/dist/{useFormSubmission-PLRMfzJ3.js → useFormSubmission-CBP1Vu7h.js} +2 -2
  65. package/dist/{useFormSubmission-PLRMfzJ3.js.map → useFormSubmission-CBP1Vu7h.js.map} +1 -1
  66. package/dist/{utils-BPAW-N7-.js → utils-G-wqcNVe.js} +47 -43
  67. package/dist/utils-G-wqcNVe.js.map +1 -0
  68. package/dist/v2/BuildForm.js +3215 -0
  69. package/dist/v2/BuildForm.js.map +1 -0
  70. package/dist/v2/ExternalForm.js +659 -0
  71. package/dist/v2/ExternalForm.js.map +1 -0
  72. package/dist/v2/NeetoFormProvider.js +11 -0
  73. package/dist/v2/NeetoFormProvider.js.map +1 -0
  74. package/dist/v2/Submission.js +2834 -0
  75. package/dist/v2/Submission.js.map +1 -0
  76. package/dist/v2/UrlBuilder.js +350 -0
  77. package/dist/v2/UrlBuilder.js.map +1 -0
  78. package/dist/v2/buildForm-CpdYPz4r.js +35 -0
  79. package/dist/v2/buildForm-CpdYPz4r.js.map +1 -0
  80. package/dist/v2/constants-C8P1Mxiw.js +33 -0
  81. package/dist/v2/constants-C8P1Mxiw.js.map +1 -0
  82. package/dist/v2/hooks.js +20 -0
  83. package/dist/v2/hooks.js.map +1 -0
  84. package/dist/v2/index-CUrkh_zd.js +18 -0
  85. package/dist/v2/index-CUrkh_zd.js.map +1 -0
  86. package/dist/v2/index.js +94 -0
  87. package/dist/v2/index.js.map +1 -0
  88. package/dist/v2/main.css +2 -0
  89. package/dist/v2/main.css.map +1 -0
  90. package/dist/v2/useFormApi-B5a0zkAT.js +463 -0
  91. package/dist/v2/useFormApi-B5a0zkAT.js.map +1 -0
  92. package/dist/v2/useFormSubmission-PDJDRUfF.js +22 -0
  93. package/dist/v2/useFormSubmission-PDJDRUfF.js.map +1 -0
  94. package/dist/v2/utils-wCXQvtSj.js +2762 -0
  95. package/dist/v2/utils-wCXQvtSj.js.map +1 -0
  96. package/dist/v2/yup-CKd8MXQx.js +1087 -0
  97. package/dist/v2/yup-CKd8MXQx.js.map +1 -0
  98. package/dist/{yup-DfQmQc3v.js → yup-DEHT0L38.js} +3 -3
  99. package/dist/{yup-DfQmQc3v.js.map → yup-DEHT0L38.js.map} +1 -1
  100. package/package.json +29 -14
  101. package/types.d.ts +1 -0
  102. package/dist/buildForm-DfMpfuSp.js.map +0 -1
  103. package/dist/constants-Cj0XxE8a.js.map +0 -1
  104. package/dist/constants-D5JlvWws.js.map +0 -1
  105. package/dist/index-Beo6ztaM.js.map +0 -1
  106. package/dist/useFormSubmission-D3O7sDHp.js.map +0 -1
  107. package/dist/utils-BPAW-N7-.js.map +0 -1
  108. package/dist/utils-DBhM5B2L.js.map +0 -1
  109. package/dist/yup-DoKhabp1.js.map +0 -1
@@ -0,0 +1,2762 @@
1
+ import { useEffect, useState, useImperativeHandle, memo, Fragment as Fragment$1 } from 'react';
2
+ import { useFormikContext, useField, Field as Field$1, FastField } from 'formik';
3
+ import { isPresent, findBy, isNotEmpty, filterBy, findById, isNotPresent, hyphenate, noop, toLabelAndValue, getRandomInt, randomPick, slugify, notEqualsDeep } from '@bigbinary/neeto-cist';
4
+ import { dayjs, buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
5
+ import { c as isFunction, d as isEmptyValues, Q as QUESTION_KIND, A as ADDRESS_FIELD_TYPES, S as SPOT_QUESTION_DEFAULT_VALUE, P as PARENTHESES_REGEX, R as RATING_VALUES, E as EMAIL_REGEX, e as SCHEMA_LESS_QUESTION_KINDS, f as SIX_DIGIT_NUMBER_REGEX, g as fieldWithFallback, h as ADDRESS_FIELD_WIDTHS, j as LABEL_FIELDS, k as generateArray, D as DEFAULT_CHOICE_QUESTION_ATTRIBUTES, l as RADIO_DESELECT_KEYS, m as RATING_OPTIONS, I as ICONS_MAP } from './yup-CKd8MXQx.js';
6
+ import { parsePhoneNumber } from 'libphonenumber-js';
7
+ import { getFromLocalStorage, setToLocalStorage, removeFromLocalStorage, dayjs as dayjs$1, withEventTargetValue } from '@bigbinary/neeto-commons-frontend/v2/utils';
8
+ import { pick, mergeRight, omit, isEmpty, max, when, is, last, includes, __, mergeLeft, isNil, clamp, prop, trim, map, zipObj, identity, pluck, values, pipe, dec, equals } from 'ramda';
9
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
+ import EditorContent from '@bigbinary/neeto-editor/v2/EditorContent';
11
+ import { Q as QUESTION_TYPES, C as CAPTCHA_TYPES } from './constants-C8P1Mxiw.js';
12
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
13
+ import { MultiEmailInput, Button, Select, Input, Checkbox, DatePicker, Spinner, Callout, Toastr, Label, RadioGroup, Textarea, Badge } from '@bigbinary/neeto-atoms';
14
+ import Plus from '@bigbinary/neeto-icons/Plus';
15
+ import { useTranslation, Trans } from 'react-i18next';
16
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
17
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
18
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
19
+ import { isEditorEmpty } from '@bigbinary/neeto-editor/v2/utils';
20
+ import { validation, PhoneNumberInput } from '@bigbinary/neeto-molecules/v2/PhoneNumber';
21
+ import i18next from 'i18next';
22
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
23
+ import _toArray from '@babel/runtime/helpers/toArray';
24
+ import * as yup from 'yup';
25
+ import classnames from 'classnames';
26
+ import { useUpdateEffect, useStateWithDependency, useDebounce } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
27
+ import Refresh from '@bigbinary/neeto-icons/Refresh';
28
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
29
+ import { globalProps } from '@bigbinary/neeto-commons-frontend/v2/initializers';
30
+ import ReCAPTCHA from 'react-google-recaptcha';
31
+ import { useMutation } from '@tanstack/react-query';
32
+ import axios from 'axios';
33
+ import { E as EMAIL_VERIFICATIONS_CREATE_URL, i as EMAIL_VERIFICATIONS_VERIFY_URL } from './useFormApi-B5a0zkAT.js';
34
+ import CheckCircle from '@bigbinary/neeto-icons/CheckCircle';
35
+ import { FileUpload } from '@bigbinary/neeto-molecules/v2/FileUpload';
36
+ import Image from '@bigbinary/neeto-icons/Image';
37
+ import NeetoEditor from '@bigbinary/neeto-editor/v2/Editor';
38
+ import Info from '@bigbinary/neeto-icons/Info';
39
+
40
+ var clearLocalStorageValues = function clearLocalStorageValues(key) {
41
+ try {
42
+ localStorage.removeItem(key);
43
+ } catch (error) {
44
+ // eslint-disable-next-line no-console
45
+ console.error(error);
46
+ }
47
+ };
48
+ var setWithExpiry = function setWithExpiry(key, value) {
49
+ var expireInDays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
50
+ var expiryDate = dayjs().add(expireInDays, "day").toDate();
51
+ var item = {
52
+ value: value,
53
+ localStorageExpiry: expiryDate.getTime()
54
+ };
55
+ try {
56
+ localStorage.setItem(key, JSON.stringify(item));
57
+ } catch (error) {
58
+ // eslint-disable-next-line no-console
59
+ console.error(error);
60
+ }
61
+ };
62
+ var getWithExpiry = function getWithExpiry(key) {
63
+ try {
64
+ var itemStr = localStorage.getItem(key);
65
+ if (!itemStr) {
66
+ return null;
67
+ }
68
+ var item = JSON.parse(itemStr);
69
+ var now = new Date();
70
+ if (now.getTime() > item.localStorageExpiry) {
71
+ localStorage.removeItem(key);
72
+ return null;
73
+ }
74
+ return item.value;
75
+ } catch (error) {
76
+ // eslint-disable-next-line no-console
77
+ console.error(error);
78
+ return null;
79
+ }
80
+ };
81
+
82
+ var clientI18nInstance$1 = i18next.cloneInstance();
83
+
84
+ var FormikWrap = function FormikWrap(_ref) {
85
+ var onError = _ref.onError,
86
+ children = _ref.children,
87
+ formId = _ref.formId,
88
+ preserveValues = _ref.preserveValues,
89
+ onValuesChange = _ref.onValuesChange,
90
+ dataUpdateCount = _ref.dataUpdateCount;
91
+ var _useFormikContext = useFormikContext(),
92
+ errors = _useFormikContext.errors,
93
+ touched = _useFormikContext.touched,
94
+ isValid = _useFormikContext.isValid,
95
+ isSubmitting = _useFormikContext.isSubmitting,
96
+ values = _useFormikContext.values,
97
+ validateForm = _useFormikContext.validateForm;
98
+ var revalidate = function revalidate() {
99
+ return isPresent(errors) && validateForm();
100
+ };
101
+ useEffect(function () {
102
+ revalidate();
103
+ }, [clientI18nInstance$1.language, dataUpdateCount]);
104
+ var syncValuesWithLocalStorage = function syncValuesWithLocalStorage() {
105
+ return preserveValues && !isEmptyValues(values) && setWithExpiry("".concat(formId, "/values"), values);
106
+ };
107
+ useEffect(function () {
108
+ syncValuesWithLocalStorage();
109
+ onValuesChange && onValuesChange(values);
110
+ }, [values, formId, preserveValues]);
111
+ useEffect(function () {
112
+ if (isSubmitting || isValid) return;
113
+
114
+ // include only touched fields
115
+ var touchedErrors = Object.keys(errors).filter(function (key) {
116
+ return touched[key];
117
+ }).reduce(function (obj, key) {
118
+ obj[key] = errors[key];
119
+ return obj;
120
+ }, {});
121
+ if (isFunction(onError)) onError(touchedErrors);
122
+ }, [isValid, isSubmitting]);
123
+ return children;
124
+ };
125
+
126
+ var RESEND_DELAY = 120;
127
+ var ONE_SECOND = 1000;
128
+ var EMAIL_VERIFICATION_FIELD_NAME_PREFIX = "verificationCode";
129
+ var EMAIL_VERIFICATION_PREFIX = "neeto_form_nano_email_verification_details_";
130
+ var EMAIL_VERIFICATION_KEYS = {
131
+ EMAIL: "email",
132
+ TOKEN: "token",
133
+ VERIFIED: "verified",
134
+ CODE: "code",
135
+ CODE_SENT_AT: "code-sent-at"
136
+ };
137
+ var CALLOUT_STYLES = {
138
+ WARNING: "warning",
139
+ ERROR: "danger"
140
+ };
141
+ var DEFAULT_CALLOUT_DETAILS = {
142
+ message: "",
143
+ style: ""
144
+ };
145
+
146
+ var getEmailVerificationKey = function getEmailVerificationKey(formId) {
147
+ return "".concat(EMAIL_VERIFICATION_PREFIX, "-").concat(formId);
148
+ };
149
+ var getEmailVerificationDetails = function getEmailVerificationDetails(formId) {
150
+ return getFromLocalStorage(getEmailVerificationKey(formId)) || {};
151
+ };
152
+ var buildVerificationFieldName = function buildVerificationFieldName(questionId) {
153
+ return "".concat(EMAIL_VERIFICATION_FIELD_NAME_PREFIX, "-").concat(questionId);
154
+ };
155
+ var getLastVerificationCodeSentAt = function getLastVerificationCodeSentAt(formId, questionId) {
156
+ var codeSentAt = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT);
157
+ return Number(codeSentAt) || 0;
158
+ };
159
+ var storeLastVerificationCodeSentAt = function storeLastVerificationCodeSentAt(formId, questionId) {
160
+ var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
161
+ return setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT, Date.now() - offset));
162
+ };
163
+ var getRemainingTime = function getRemainingTime(formId, questionId) {
164
+ var elapsedTime = Math.floor((Date.now() - getLastVerificationCodeSentAt(formId, questionId)) / ONE_SECOND);
165
+ return max(RESEND_DELAY - elapsedTime, 0);
166
+ };
167
+ var getEmailVerificationDetail = function getEmailVerificationDetail(formId, questionId) {
168
+ var _questionDetails$keys;
169
+ var allDetails = getEmailVerificationDetails(formId);
170
+ var questionDetails = allDetails[questionId] || {};
171
+ for (var _len = arguments.length, keys = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
172
+ keys[_key - 2] = arguments[_key];
173
+ }
174
+ return keys.length === 1 ? (_questionDetails$keys = questionDetails[keys[0]]) !== null && _questionDetails$keys !== void 0 ? _questionDetails$keys : "" : pick(keys, allDetails);
175
+ };
176
+ var setEmailVerificationDetail = function setEmailVerificationDetail(formId, questionId, data) {
177
+ var storageKey = getEmailVerificationKey(formId);
178
+ var allDetails = getEmailVerificationDetails(formId);
179
+ allDetails[questionId] = mergeRight(allDetails[questionId] || {}, data);
180
+ setToLocalStorage(storageKey, allDetails);
181
+ };
182
+ var removeEmailVerificationDetail = function removeEmailVerificationDetail(formId, questionId) {
183
+ var storageKey = getEmailVerificationKey(formId);
184
+ var allDetails = getEmailVerificationDetails(formId);
185
+ for (var _len2 = arguments.length, keys = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
186
+ keys[_key2 - 2] = arguments[_key2];
187
+ }
188
+ allDetails[questionId] = omit(keys, allDetails[questionId]);
189
+ if (isEmpty(allDetails[questionId])) delete allDetails[questionId];
190
+ isEmpty(allDetails) ? removeFromLocalStorage(storageKey) : setToLocalStorage(storageKey, allDetails);
191
+ };
192
+ var clearEmailVerificationDetails = function clearEmailVerificationDetails(formId) {
193
+ removeFromLocalStorage(getEmailVerificationKey(formId));
194
+ };
195
+
196
+ var clientI18nInstance = i18next.cloneInstance();
197
+
198
+ var t$1 = clientI18nInstance.t;
199
+ var getInvalidFieldError = function getInvalidFieldError(label) {
200
+ return t$1("neetoForm.error.invalidField", {
201
+ label: label
202
+ });
203
+ };
204
+ var getRequiredFieldError = function getRequiredFieldError(label) {
205
+ return t$1("neetoForm.error.requiredField", {
206
+ label: label
207
+ });
208
+ };
209
+ var getSelectMinError = function getSelectMinError() {
210
+ var entity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t$1("neetoForm.common.option");
211
+ return t$1("neetoForm.error.minOneEntity", {
212
+ entity: entity
213
+ });
214
+ };
215
+ var getInvalidTypeError = function getInvalidTypeError(label, type) {
216
+ return t$1("neetoForm.error.invalidType", {
217
+ label: label,
218
+ type: type
219
+ });
220
+ };
221
+
222
+ function ownKeys$j(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
223
+ function _objectSpread$j(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$j(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$j(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
224
+ var resolveQueryParamValue = when(is(Array), last);
225
+ var toEmailValues = function toEmailValues() {
226
+ var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
227
+ return values.map(function (value) {
228
+ return {
229
+ label: value,
230
+ value: value,
231
+ valid: true
232
+ };
233
+ });
234
+ };
235
+ var getPhoneNumberFromUrl = function getPhoneNumberFromUrl(fieldCodes, fieldCode) {
236
+ var _resolveQueryParamVal;
237
+ var countryCode = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".country")]);
238
+ var phoneNumber = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".number")]);
239
+ var phoneNumberWithCountryCode = (_resolveQueryParamVal = resolveQueryParamValue(fieldCodes[fieldCode])) === null || _resolveQueryParamVal === void 0 ? void 0 : _resolveQueryParamVal.replace(PARENTHESES_REGEX, "");
240
+ if (phoneNumberWithCountryCode) return phoneNumberWithCountryCode;
241
+ if (!countryCode || !phoneNumber) return undefined;
242
+ var formattedValue = getPhoneData(phoneNumber, countryCode);
243
+ if (!formattedValue) return undefined;
244
+ return formattedValue.formatInternational();
245
+ };
246
+ var getOptionFromURL = function getOptionFromURL(_ref) {
247
+ var _findBy;
248
+ var optionsAttributes = _ref.optionsAttributes,
249
+ fieldCodes = _ref.fieldCodes,
250
+ fieldCode = _ref.fieldCode;
251
+ var preFillOption = resolveQueryParamValue(fieldCodes[fieldCode]);
252
+ return (_findBy = findBy({
253
+ label: preFillOption
254
+ }, optionsAttributes)) === null || _findBy === void 0 ? void 0 : _findBy.id;
255
+ };
256
+ var getMultipleOptionsFromURL = function getMultipleOptionsFromURL(_ref2) {
257
+ var optionsAttributes = _ref2.optionsAttributes,
258
+ fieldCodes = _ref2.fieldCodes,
259
+ fieldCode = _ref2.fieldCode;
260
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
261
+ if (!fieldCodeValue) return new Array(optionsAttributes.length).fill(false);
262
+ var allOptions = fieldCodeValue.split(",").map(trim);
263
+ return optionsAttributes.map(function (option) {
264
+ return allOptions.includes(option.label);
265
+ });
266
+ };
267
+ var getStarRatingOrOpinionScaleFromUrl = function getStarRatingOrOpinionScaleFromUrl(_ref3) {
268
+ var minValue = _ref3.minValue,
269
+ maxValue = _ref3.maxValue,
270
+ fieldCodes = _ref3.fieldCodes,
271
+ fieldCode = _ref3.fieldCode;
272
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
273
+ var rating = parseInt(fieldCodeValue);
274
+ return isNil(rating) || isNaN(rating) ? "" : clamp(minValue, maxValue, rating);
275
+ };
276
+ var getAdditionalGuestsFromUrl = function getAdditionalGuestsFromUrl(_ref4) {
277
+ var fieldCodes = _ref4.fieldCodes,
278
+ fieldCode = _ref4.fieldCode;
279
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
280
+ var allEmails = fieldCodeValue === null || fieldCodeValue === void 0 ? void 0 : fieldCodeValue.split(",");
281
+ if (!allEmails) return [];
282
+ return allEmails.map(function (email) {
283
+ return {
284
+ label: email.trim(),
285
+ value: email.trim(),
286
+ valid: EMAIL_REGEX.test(email.trim())
287
+ };
288
+ });
289
+ };
290
+ var getRatingFromUrl = function getRatingFromUrl(_ref5) {
291
+ var fieldCodes = _ref5.fieldCodes,
292
+ fieldCode = _ref5.fieldCode;
293
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
294
+ var allowedValues = Object.values(RATING_VALUES).map(prop("value"));
295
+ return allowedValues.includes(fieldCodeValue) ? fieldCodeValue : "";
296
+ };
297
+ var getNumberFromUrl = function getNumberFromUrl(_ref6) {
298
+ var fieldCodes = _ref6.fieldCodes,
299
+ fieldCode = _ref6.fieldCode,
300
+ kind = _ref6.kind;
301
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
302
+ var parsedValue = kind === QUESTION_KIND.INTEGER.value ? parseInt(fieldCodeValue) : parseFloat(fieldCodeValue);
303
+ return parsedValue || "";
304
+ };
305
+ var getNameFromUrl = function getNameFromUrl(_ref7, fieldCodes) {
306
+ var isSplitMode = _ref7.isSplitMode,
307
+ fieldCode = _ref7.fieldCode;
308
+ var fullName = resolveQueryParamValue(fieldCodes[fieldCode]) || "";
309
+ if (!isSplitMode) return {
310
+ fullName: fullName
311
+ };
312
+ var firstName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".first_name")]) || "";
313
+ var lastName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".last_name")]) || "";
314
+ if (isPresent(firstName) || isPresent(lastName)) {
315
+ return {
316
+ firstName: firstName,
317
+ lastName: lastName
318
+ };
319
+ }
320
+ if (isPresent(fullName)) {
321
+ var _fullName$trim$split = fullName.trim().split(/\s+/),
322
+ _fullName$trim$split2 = _toArray(_fullName$trim$split),
323
+ computedFirstName = _fullName$trim$split2[0],
324
+ remainingParts = _fullName$trim$split2.slice(1);
325
+ return {
326
+ firstName: computedFirstName,
327
+ lastName: remainingParts.join(" ")
328
+ };
329
+ }
330
+ return {
331
+ firstName: firstName,
332
+ lastName: lastName
333
+ };
334
+ };
335
+ var isValidSpotValue = function isValidSpotValue(value, remainingSlotsCount) {
336
+ var num = Number(value);
337
+ if (!Number.isInteger(num) || num <= 0) return false;
338
+ return !(typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && num > remainingSlotsCount);
339
+ };
340
+ var buildEmailVerificationEntries = function buildEmailVerificationEntries() {
341
+ var questions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
342
+ var emailQuestionsRequiringVerification = filterBy({
343
+ kind: QUESTION_TYPES.EMAIL,
344
+ isVerificationEnabled: true
345
+ }, questions);
346
+ var fieldNames = map(function (_ref8) {
347
+ var id = _ref8.id;
348
+ return buildVerificationFieldName(id);
349
+ }, emailQuestionsRequiringVerification);
350
+ return zipObj(fieldNames, Array(fieldNames.length).fill(""));
351
+ };
352
+ var getLabel = function getLabel(label, isRequired) {
353
+ return isRequired ? "".concat(label, "*") : label;
354
+ };
355
+ var generateInitValues = function generateInitValues(_ref9) {
356
+ var questions = _ref9.questions,
357
+ _ref9$initialValues = _ref9.initialValues,
358
+ initialValues = _ref9$initialValues === void 0 ? [] : _ref9$initialValues,
359
+ _ref9$localValues = _ref9.localValues,
360
+ localValues = _ref9$localValues === void 0 ? {} : _ref9$localValues,
361
+ _ref9$fieldCodes = _ref9.fieldCodes,
362
+ fieldCodes = _ref9$fieldCodes === void 0 ? {} : _ref9$fieldCodes,
363
+ remainingSlotsCount = _ref9.remainingSlotsCount;
364
+ var initValues = {};
365
+ var valuesMap = {};
366
+ if (initialValues) {
367
+ valuesMap = initialValues.reduce(function (acc, answer) {
368
+ return _objectSpread$j(_objectSpread$j({}, acc), {}, _defineProperty({}, answer.questionId, {
369
+ value: answer.value,
370
+ optionIds: answer.optionIds
371
+ }));
372
+ }, {});
373
+ }
374
+ questions.forEach(function (question) {
375
+ var id = question.id,
376
+ kind = question.kind,
377
+ optionsAttributes = question.optionsAttributes,
378
+ fieldCode = question.fieldCode,
379
+ minValue = question.minValue,
380
+ maxValue = question.maxValue,
381
+ fields = question.fields;
382
+ switch (kind) {
383
+ case QUESTION_KIND.CONDITION.value:
384
+ {
385
+ var _valuesMap$id$value, _valuesMap;
386
+ initValues[id] = (_valuesMap$id$value = (_valuesMap = valuesMap) === null || _valuesMap === void 0 || (_valuesMap = _valuesMap[id]) === null || _valuesMap === void 0 ? void 0 : _valuesMap.value) !== null && _valuesMap$id$value !== void 0 ? _valuesMap$id$value : false;
387
+ return;
388
+ }
389
+ case QUESTION_KIND.ADDITIONAL_GUESTS.value:
390
+ {
391
+ var _valuesMap2;
392
+ var emailsFromSubmission = toEmailValues((_valuesMap2 = valuesMap) === null || _valuesMap2 === void 0 || (_valuesMap2 = _valuesMap2[id]) === null || _valuesMap2 === void 0 ? void 0 : _valuesMap2.value);
393
+ initValues[id] = isNotEmpty(emailsFromSubmission) ? emailsFromSubmission : getAdditionalGuestsFromUrl({
394
+ fieldCodes: fieldCodes,
395
+ fieldCode: fieldCode
396
+ });
397
+ return;
398
+ }
399
+ case QUESTION_KIND.CHECKBOX.value:
400
+ {
401
+ var _valuesMap$id;
402
+ initValues[id] = (_valuesMap$id = valuesMap[id]) !== null && _valuesMap$id !== void 0 && (_valuesMap$id = _valuesMap$id.optionIds) !== null && _valuesMap$id !== void 0 && _valuesMap$id.length ? optionsAttributes.map(function (option) {
403
+ var _valuesMap$id2;
404
+ return (_valuesMap$id2 = valuesMap[id]) === null || _valuesMap$id2 === void 0 || (_valuesMap$id2 = _valuesMap$id2.optionIds) === null || _valuesMap$id2 === void 0 ? void 0 : _valuesMap$id2.includes(option.id);
405
+ }) : getMultipleOptionsFromURL({
406
+ optionsAttributes: optionsAttributes,
407
+ fieldCodes: fieldCodes,
408
+ fieldCode: fieldCode
409
+ });
410
+ return;
411
+ }
412
+ case QUESTION_KIND.RADIO.value:
413
+ case QUESTION_KIND.DROPDOWN.value:
414
+ {
415
+ var _optionsAttributes$fi;
416
+ var optionFromValues = optionsAttributes === null || optionsAttributes === void 0 || (_optionsAttributes$fi = optionsAttributes.find(function (option) {
417
+ var _valuesMap$id3;
418
+ return (_valuesMap$id3 = valuesMap[id]) === null || _valuesMap$id3 === void 0 || (_valuesMap$id3 = _valuesMap$id3.optionIds) === null || _valuesMap$id3 === void 0 ? void 0 : _valuesMap$id3.includes(option.id);
419
+ })) === null || _optionsAttributes$fi === void 0 ? void 0 : _optionsAttributes$fi.id;
420
+ var optionFromUrl = getOptionFromURL({
421
+ optionsAttributes: optionsAttributes,
422
+ fieldCodes: fieldCodes,
423
+ fieldCode: fieldCode
424
+ });
425
+ initValues[id] = optionFromValues || optionFromUrl;
426
+ return;
427
+ }
428
+ case QUESTION_KIND.SPOT.value:
429
+ {
430
+ var _valuesMap$id$value2, _valuesMap3;
431
+ var urlValue = getNumberFromUrl({
432
+ fieldCodes: fieldCodes,
433
+ fieldCode: fieldCode,
434
+ kind: QUESTION_KIND.INTEGER.value
435
+ });
436
+ var candidateValue = (_valuesMap$id$value2 = (_valuesMap3 = valuesMap) === null || _valuesMap3 === void 0 || (_valuesMap3 = _valuesMap3[id]) === null || _valuesMap3 === void 0 ? void 0 : _valuesMap3.value) !== null && _valuesMap$id$value2 !== void 0 ? _valuesMap$id$value2 : urlValue !== "" ? urlValue : SPOT_QUESTION_DEFAULT_VALUE;
437
+ initValues[id] = isValidSpotValue(candidateValue, remainingSlotsCount) ? candidateValue : SPOT_QUESTION_DEFAULT_VALUE;
438
+ return;
439
+ }
440
+ case QUESTION_KIND.INTEGER.value:
441
+ case QUESTION_KIND.DECIMAL.value:
442
+ {
443
+ var _valuesMap4;
444
+ initValues[id] = ((_valuesMap4 = valuesMap) === null || _valuesMap4 === void 0 || (_valuesMap4 = _valuesMap4[id]) === null || _valuesMap4 === void 0 ? void 0 : _valuesMap4.value) || getNumberFromUrl({
445
+ fieldCodes: fieldCodes,
446
+ fieldCode: fieldCode,
447
+ kind: kind
448
+ });
449
+ return;
450
+ }
451
+ case QUESTION_KIND.RATING.value:
452
+ {
453
+ var _valuesMap5;
454
+ initValues[id] = ((_valuesMap5 = valuesMap) === null || _valuesMap5 === void 0 || (_valuesMap5 = _valuesMap5[id]) === null || _valuesMap5 === void 0 ? void 0 : _valuesMap5.value) || getRatingFromUrl({
455
+ fieldCodes: fieldCodes,
456
+ fieldCode: fieldCode
457
+ });
458
+ return;
459
+ }
460
+ case QUESTION_KIND.TERMS.value:
461
+ {
462
+ initValues[id] = false;
463
+ return;
464
+ }
465
+ case QUESTION_KIND.FILE_UPLOAD.value:
466
+ {
467
+ var _valuesMap$id$value3, _valuesMap6;
468
+ initValues[id] = {
469
+ files: (_valuesMap$id$value3 = (_valuesMap6 = valuesMap) === null || _valuesMap6 === void 0 || (_valuesMap6 = _valuesMap6[id]) === null || _valuesMap6 === void 0 ? void 0 : _valuesMap6.value) !== null && _valuesMap$id$value3 !== void 0 ? _valuesMap$id$value3 : []
470
+ };
471
+ return;
472
+ }
473
+ case QUESTION_KIND.PHONE.value:
474
+ case QUESTION_KIND.SMS_REMINDER.value:
475
+ {
476
+ var _valuesMap$id$value4, _valuesMap7;
477
+ initValues[id] = (_valuesMap$id$value4 = (_valuesMap7 = valuesMap) === null || _valuesMap7 === void 0 || (_valuesMap7 = _valuesMap7[id]) === null || _valuesMap7 === void 0 ? void 0 : _valuesMap7.value) !== null && _valuesMap$id$value4 !== void 0 ? _valuesMap$id$value4 : getPhoneNumberFromUrl(fieldCodes, fieldCode);
478
+ return;
479
+ }
480
+ case QUESTION_KIND.STAR_RATING.value:
481
+ case QUESTION_KIND.OPINION_SCALE.value:
482
+ {
483
+ var _valuesMap$id$value5, _valuesMap8;
484
+ initValues[id] = (_valuesMap$id$value5 = (_valuesMap8 = valuesMap) === null || _valuesMap8 === void 0 || (_valuesMap8 = _valuesMap8[id]) === null || _valuesMap8 === void 0 ? void 0 : _valuesMap8.value) !== null && _valuesMap$id$value5 !== void 0 ? _valuesMap$id$value5 : getStarRatingOrOpinionScaleFromUrl({
485
+ minValue: minValue,
486
+ maxValue: maxValue,
487
+ fieldCodes: fieldCodes,
488
+ fieldCode: fieldCode
489
+ });
490
+ return;
491
+ }
492
+ case QUESTION_KIND.NAME.value:
493
+ {
494
+ var _valuesMap$id$value6, _valuesMap9;
495
+ initValues[id] = (_valuesMap$id$value6 = (_valuesMap9 = valuesMap) === null || _valuesMap9 === void 0 || (_valuesMap9 = _valuesMap9[id]) === null || _valuesMap9 === void 0 ? void 0 : _valuesMap9.value) !== null && _valuesMap$id$value6 !== void 0 ? _valuesMap$id$value6 : getNameFromUrl(question, fieldCodes);
496
+ return;
497
+ }
498
+ case QUESTION_KIND.ADDRESS.value:
499
+ {
500
+ var _valuesMap$id$value7, _valuesMap0;
501
+ initValues[id] = (_valuesMap$id$value7 = (_valuesMap0 = valuesMap) === null || _valuesMap0 === void 0 || (_valuesMap0 = _valuesMap0[id]) === null || _valuesMap0 === void 0 ? void 0 : _valuesMap0.value) !== null && _valuesMap$id$value7 !== void 0 ? _valuesMap$id$value7 : fields.reduce(function (values, field) {
502
+ var value = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".").concat(field.label)]);
503
+ if (field.fieldType === ADDRESS_FIELD_TYPES.SELECT) {
504
+ var _field$properties;
505
+ values[field.id] = findBy({
506
+ label: value
507
+ }, (_field$properties = field.properties) === null || _field$properties === void 0 ? void 0 : _field$properties.options) ? value : "";
508
+ } else {
509
+ values[field.id] = value || "";
510
+ }
511
+ return values;
512
+ }, {});
513
+ return;
514
+ }
515
+ default:
516
+ {
517
+ var _valuesMap$id$value8, _valuesMap1;
518
+ initValues[id] = (_valuesMap$id$value8 = (_valuesMap1 = valuesMap) === null || _valuesMap1 === void 0 || (_valuesMap1 = _valuesMap1[id]) === null || _valuesMap1 === void 0 ? void 0 : _valuesMap1.value) !== null && _valuesMap$id$value8 !== void 0 ? _valuesMap$id$value8 : resolveQueryParamValue(fieldCodes[fieldCode] || "");
519
+ return;
520
+ }
521
+ }
522
+ });
523
+ var formInitialValues = !isEmptyValues(localValues) ? localValues : initValues;
524
+ return mergeLeft(formInitialValues, buildEmailVerificationEntries(questions));
525
+ };
526
+ var generateFormResponse = function generateFormResponse(response, questions) {
527
+ var formResponse = [];
528
+ questions.forEach(function (question) {
529
+ var id = question.id,
530
+ kind = question.kind,
531
+ optionsAttributes = question.optionsAttributes;
532
+ if (!SCHEMA_LESS_QUESTION_KINDS.includes(kind)) {
533
+ var responseValue = response[id];
534
+ if (kind === QUESTION_KIND.RADIO.value || kind === QUESTION_KIND.DROPDOWN.value) {
535
+ var option = findById(responseValue, optionsAttributes);
536
+ if (option) {
537
+ formResponse.push({
538
+ questionId: id,
539
+ questionOptionId: option.id,
540
+ value: option.label,
541
+ kind: kind
542
+ });
543
+ }
544
+ } else if (kind === QUESTION_KIND.SPOT.value) {
545
+ formResponse.push({
546
+ questionId: id,
547
+ value: responseValue,
548
+ kind: kind
549
+ });
550
+ } else if (kind === QUESTION_KIND.CHECKBOX.value) {
551
+ responseValue.forEach(function (isChecked, index) {
552
+ if (!isChecked) return;
553
+ var option = optionsAttributes[index];
554
+ formResponse.push({
555
+ questionId: id,
556
+ questionOptionId: option.id,
557
+ value: option.label,
558
+ kind: kind
559
+ });
560
+ });
561
+ } else if (isPhoneNumberField(kind)) {
562
+ formResponse.push({
563
+ questionId: id,
564
+ value: responseValue ? parsePhoneNumber(responseValue).formatInternational() : "",
565
+ kind: kind
566
+ });
567
+ } else if (kind === QUESTION_KIND.ADDITIONAL_GUESTS.value) {
568
+ formResponse.push({
569
+ questionId: id,
570
+ value: responseValue ? pluck("value", responseValue) : null,
571
+ kind: kind
572
+ });
573
+ } else if (kind === QUESTION_KIND.RICH_TEXT.value) {
574
+ formResponse.push({
575
+ questionId: id,
576
+ value: isEditorEmpty(responseValue) ? null : responseValue,
577
+ kind: kind
578
+ });
579
+ } else if (kind === QUESTION_KIND.FILE_UPLOAD.value) {
580
+ formResponse.push({
581
+ questionId: id,
582
+ files: isPresent(responseValue) ? responseValue.files : null,
583
+ kind: kind
584
+ });
585
+ } else if (kind === QUESTION_KIND.DATE.value) {
586
+ formResponse.push({
587
+ questionId: id,
588
+ value: dayjs$1(responseValue).isValid() ?
589
+ // YYYY-MM-DD format is not supported by dateFormat.
590
+ // eslint-disable-next-line @bigbinary/neeto/use-standard-date-time-formats
591
+ dayjs$1(responseValue).format("YYYY-MM-DD") : "",
592
+ kind: kind
593
+ });
594
+ } else formResponse.push({
595
+ questionId: id,
596
+ value: responseValue,
597
+ kind: kind
598
+ });
599
+ }
600
+ });
601
+ return formResponse;
602
+ };
603
+ var mergeRefs = function mergeRefs() {
604
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
605
+ refs[_key] = arguments[_key];
606
+ }
607
+ return function (node) {
608
+ return refs.forEach(function (ref) {
609
+ return typeof ref === "function" ? ref(node) : ref.current = node;
610
+ });
611
+ };
612
+ };
613
+ var getError = function getError(meta) {
614
+ if (meta.error && meta.touched) {
615
+ return typeof meta.error === "string" ? meta.error : "";
616
+ }
617
+ return "";
618
+ };
619
+ var buildAutoCompleteAttribute = function buildAutoCompleteAttribute(kind, autoCompleteKinds, formDomProps) {
620
+ return (formDomProps === null || formDomProps === void 0 ? void 0 : formDomProps.autoComplete) === "off" && includes(kind, autoCompleteKinds) ? "on" : undefined;
621
+ };
622
+ var renderButtonsInOrder = function renderButtonsInOrder(buttonsArray, shouldReverse) {
623
+ var orderedButtons = shouldReverse ? buttonsArray.reverse() : buttonsArray;
624
+ return map(identity, orderedButtons);
625
+ };
626
+ var getSelectedRating = function getSelectedRating(value) {
627
+ var parsedValue = parseInt(value);
628
+ return isNaN(parsedValue) ? -1 : parsedValue;
629
+ };
630
+ var isPhoneNumberField = includes(__, [QUESTION_KIND.PHONE.value, QUESTION_KIND.SMS_REMINDER.value]);
631
+
632
+ var _excluded$4 = ["kind", "customValidator"];
633
+ var _fieldKindValidatorMa;
634
+ function ownKeys$i(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
635
+ function _objectSpread$i(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$i(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$i(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
636
+ var t = clientI18nInstance$1.t;
637
+ var isValidDate = function isValidDate(date) {
638
+ return date && dayjs$1(date).isValid();
639
+ };
640
+ var extractEmailDomain = function extractEmailDomain(email) {
641
+ return email === null || email === void 0 ? void 0 : email.split("@")[1];
642
+ };
643
+ var isEmailFromWhitelistedDomain = function isEmailFromWhitelistedDomain(email, whitelistedDomains) {
644
+ if (isEmpty(whitelistedDomains)) return true;
645
+ var domain = extractEmailDomain(email);
646
+ return includes(domain, whitelistedDomains);
647
+ };
648
+ var isEmailFromBlacklistedDomain = function isEmailFromBlacklistedDomain(email, blacklistedDomains) {
649
+ var domain = extractEmailDomain(email);
650
+ return includes(domain, blacklistedDomains);
651
+ };
652
+ var countWords = function countWords(value) {
653
+ return value ? value.trim().split(/\s+/).filter(Boolean).length : 0;
654
+ };
655
+ var validateTextField = function validateTextField(_ref) {
656
+ var kind = _ref.kind,
657
+ label = _ref.label,
658
+ isRequired = _ref.isRequired,
659
+ minWords = _ref.minWords,
660
+ remainingSlotsCount = _ref.remainingSlotsCount;
661
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
662
+ if (isPhoneNumberField(kind)) {
663
+ schema = validation(getInvalidFieldError(t("neetoForm.common.phoneNumberValidation")));
664
+ }
665
+ var requiredError = kind === QUESTION_KIND.SPOT.value ? t("neetoForm.questions.spot.numberOfSpotsRequired") : getRequiredFieldError(label);
666
+ if (isRequired) schema = schema.trim().required(requiredError);
667
+ if (kind === QUESTION_KIND.SPOT.value) {
668
+ schema = schema.test("integer-spots", t("neetoForm.questions.spot.mustBeInteger"), function (value) {
669
+ return isNotPresent(value) || value === "" || Number.isInteger(Number(value));
670
+ }).test("min-spots", t("neetoForm.error.mustBeOrGreaterThanOrEqualTo", {
671
+ value: 1
672
+ }), function (value) {
673
+ return isNotPresent(value) || value === "" || Number(value) > 0;
674
+ });
675
+ if (typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0) {
676
+ schema = schema.test("max-spots", t("neetoForm.questions.spot.exceedsRemainingSpots", {
677
+ count: remainingSlotsCount
678
+ }), function (value) {
679
+ return isNotPresent(value) || value === "" || Number(value) > 0 && Number(value) <= remainingSlotsCount;
680
+ });
681
+ }
682
+ }
683
+ if (minWords) {
684
+ schema = schema.test("min-words", t("neetoForm.questions.textarea.minimumWordsError", {
685
+ count: minWords
686
+ }), function (value) {
687
+ return !value || countWords(value) >= minWords;
688
+ });
689
+ }
690
+ return schema.trim();
691
+ };
692
+ var validateEmailField = function validateEmailField(_ref2) {
693
+ var label = _ref2.label,
694
+ isRequired = _ref2.isRequired,
695
+ whitelistedDomains = _ref2.whitelistedDomains,
696
+ blacklistedDomains = _ref2.blacklistedDomains;
697
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string")).email(getInvalidFieldError("Email")).test("verify domain", function (_ref3) {
698
+ var value = _ref3.value;
699
+ return t("neetoForm.error.emailFromRestrictedDomain", {
700
+ domain: extractEmailDomain(value)
701
+ });
702
+ }, function (value) {
703
+ return isNotPresent(value) || isEmailFromWhitelistedDomain(value, whitelistedDomains) && !isEmailFromBlacklistedDomain(value, blacklistedDomains);
704
+ });
705
+ if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
706
+ return schema.trim();
707
+ };
708
+ var validateNameField = function validateNameField(_ref4) {
709
+ var label = _ref4.label,
710
+ isRequired = _ref4.isRequired;
711
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
712
+ if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
713
+ return schema.trim();
714
+ };
715
+ var validateSingleChoiceField = function validateSingleChoiceField(_ref5) {
716
+ var label = _ref5.label,
717
+ isRequired = _ref5.isRequired;
718
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
719
+ if (isRequired) schema = schema.required(getSelectMinError());
720
+ return schema.trim();
721
+ };
722
+ var validateMultiChoiceField = function validateMultiChoiceField(_ref6) {
723
+ var isRequired = _ref6.isRequired;
724
+ var schema = yup.array().of(yup["boolean"]());
725
+ if (isRequired) schema = schema.compact().min(1, getSelectMinError());
726
+ return schema;
727
+ };
728
+ var validateRatingField = function validateRatingField(_ref7) {
729
+ var label = _ref7.label,
730
+ isRequired = _ref7.isRequired;
731
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
732
+ if (isRequired) schema = schema.required(getSelectMinError());
733
+ return schema.trim();
734
+ };
735
+ var validateStarRatingField = function validateStarRatingField(_ref8) {
736
+ var label = _ref8.label,
737
+ isRequired = _ref8.isRequired;
738
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
739
+ if (isRequired) {
740
+ schema = schema.required(getSelectMinError(t("neetoForm.common.rating")));
741
+ }
742
+ return schema.trim();
743
+ };
744
+ var validateOpinionScaleField = function validateOpinionScaleField(_ref9) {
745
+ var label = _ref9.label,
746
+ isRequired = _ref9.isRequired;
747
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
748
+ if (isRequired) {
749
+ schema = schema.required(getSelectMinError(t("neetoForm.common.selection")));
750
+ }
751
+ return schema.trim();
752
+ };
753
+ var validateTermsField = function validateTermsField(_ref0) {
754
+ var _ref0$isRequired = _ref0.isRequired,
755
+ isRequired = _ref0$isRequired === void 0 ? true : _ref0$isRequired;
756
+ return isRequired ? yup["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptTermsAndConditions")) : yup["boolean"]().notRequired();
757
+ };
758
+ var validateConditionField = function validateConditionField(_ref1) {
759
+ var _ref1$isRequired = _ref1.isRequired,
760
+ isRequired = _ref1$isRequired === void 0 ? true : _ref1$isRequired;
761
+ return isRequired ? yup["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptCondition")) : yup["boolean"]().notRequired();
762
+ };
763
+ var validateDateField = function validateDateField(_ref10) {
764
+ var label = _ref10.label,
765
+ isRequired = _ref10.isRequired;
766
+ var schema = yup.string().test("is valid date", getInvalidTypeError(label, "date"), function (value) {
767
+ return isNotPresent(value) || isValidDate(value);
768
+ });
769
+ if (isRequired) {
770
+ schema = schema.required(getRequiredFieldError(label));
771
+ }
772
+ return schema;
773
+ };
774
+ var validateMultiEmailField = function validateMultiEmailField(_ref11) {
775
+ var isRequired = _ref11.isRequired;
776
+ var schema = yup.array().of(yup.object().shape({
777
+ value: yup.string().email(getInvalidFieldError("Email")).trim()
778
+ })).nullable();
779
+ if (isRequired) {
780
+ schema = schema.compact().min(1, getSelectMinError(t("neetoForm.common.email")));
781
+ }
782
+ return schema;
783
+ };
784
+ var validateAddressField = function validateAddressField(_ref12) {
785
+ var label = _ref12.label,
786
+ isRequired = _ref12.isRequired;
787
+ var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
788
+ if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
789
+ return schema.trim();
790
+ };
791
+ var editorHasValue = function editorHasValue(content) {
792
+ return !isEditorEmpty(content);
793
+ };
794
+ var validateRichTextField = function validateRichTextField(_ref13) {
795
+ var isRequired = _ref13.isRequired;
796
+ var schema = yup.string();
797
+ if (isRequired) {
798
+ schema = schema.test("required", getRequiredFieldError("content"), editorHasValue);
799
+ }
800
+ return schema.trim();
801
+ };
802
+ var validateFileUploadField = function validateFileUploadField(_ref14) {
803
+ var isRequired = _ref14.isRequired,
804
+ multipleFilesAllowed = _ref14.multipleFilesAllowed;
805
+ var files_schema = yup.array();
806
+ if (isRequired) {
807
+ files_schema = files_schema.of(yup.object().shape({
808
+ name: yup.string(),
809
+ signedId: yup.string().required(t("neetoForm.fileUpload.validations.waitForUpload")),
810
+ url: yup.string().required(t("neetoForm.fileUpload.validations.waitForUpload"))
811
+ })).unique("name", t("neetoForm.fileUpload.validations.removeDuplicates")).min(1, multipleFilesAllowed ? t("neetoForm.fileUpload.validations.atLeastOneFileRequired") : t("neetoForm.fileUpload.validations.fileIsRequired"));
812
+ }
813
+ return yup.object().shape({
814
+ files: files_schema
815
+ });
816
+ };
817
+ var validateCaptchaField = function validateCaptchaField(_ref15) {
818
+ var variant = _ref15.variant;
819
+ return variant === CAPTCHA_TYPES.MATH_CAPTCHA ? yup.mixed().test("verification failed", t("neetoForm.error.captchaVerificationFailed"), function (value) {
820
+ return isNotPresent(value) || value;
821
+ }).transform(function (value) {
822
+ return value === "" ? null : value;
823
+ }).required(t("neetoForm.error.incompleteCaptcha")) : yup.string().trim().required(t("neetoForm.error.incompleteCaptcha"));
824
+ };
825
+ var fieldKindValidatorMap = (_fieldKindValidatorMa = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, QUESTION_KIND.EMAIL.value, validateEmailField), QUESTION_KIND.NAME.value, validateNameField), QUESTION_KIND.PHONE.value, validateTextField), QUESTION_KIND.TEXT.value, validateTextField), QUESTION_KIND.QUESTION.value, validateTextField), QUESTION_KIND.TEXTAREA.value, validateTextField), QUESTION_KIND.DECIMAL.value, validateTextField), QUESTION_KIND.INTEGER.value, validateTextField), QUESTION_KIND.DROPDOWN.value, validateSingleChoiceField), QUESTION_KIND.RADIO.value, validateSingleChoiceField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, QUESTION_KIND.SPOT.value, validateTextField), QUESTION_KIND.CHECKBOX.value, validateMultiChoiceField), QUESTION_KIND.RATING.value, validateRatingField), QUESTION_KIND.TERMS.value, validateTermsField), QUESTION_KIND.DATE.value, validateDateField), QUESTION_KIND.STAR_RATING.value, validateStarRatingField), QUESTION_KIND.OPINION_SCALE.value, validateOpinionScaleField), QUESTION_KIND.ADDITIONAL_GUESTS.value, validateMultiEmailField), QUESTION_KIND.RICH_TEXT.value, validateRichTextField), QUESTION_KIND.CONDITION.value, validateConditionField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, QUESTION_KIND.FILE_UPLOAD.value, validateFileUploadField), QUESTION_KIND.CAPTCHA.value, validateCaptchaField), QUESTION_KIND.SMS_REMINDER.value, validateTextField), QUESTION_KIND.ADDRESS.value, validateAddressField));
826
+ var validateFieldValue = function validateFieldValue(_ref16) {
827
+ var kind = _ref16.kind,
828
+ customValidator = _ref16.customValidator,
829
+ otherProps = _objectWithoutProperties(_ref16, _excluded$4);
830
+ return function (value) {
831
+ if (!(kind in fieldKindValidatorMap)) return;
832
+ var validator = fieldKindValidatorMap[kind];
833
+ var schema = customValidator || validator(_objectSpread$i({
834
+ kind: kind
835
+ }, otherProps));
836
+
837
+ // eslint-disable-next-line consistent-return, no-async-promise-executor
838
+ return new Promise(/*#__PURE__*/function () {
839
+ var _ref17 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
840
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
841
+ while (1) switch (_context.prev = _context.next) {
842
+ case 0:
843
+ _context.prev = 0;
844
+ _context.next = 3;
845
+ return schema.validate(value);
846
+ case 3:
847
+ resolve(undefined);
848
+ _context.next = 9;
849
+ break;
850
+ case 6:
851
+ _context.prev = 6;
852
+ _context.t0 = _context["catch"](0);
853
+ resolve(_context.t0.message);
854
+ case 9:
855
+ case "end":
856
+ return _context.stop();
857
+ }
858
+ }, _callee, null, [[0, 6]]);
859
+ }));
860
+ return function (_x) {
861
+ return _ref17.apply(this, arguments);
862
+ };
863
+ }());
864
+ };
865
+ };
866
+ var validateVerificationCode = function validateVerificationCode(context) {
867
+ return function (value) {
868
+ var entity = t("neetoForm.emailVerification.verificationCode");
869
+ var schema = yup.string().trim().when("$isVerificationEnabled", {
870
+ is: true,
871
+ then: function then(schema) {
872
+ return schema.when("$isRequired", {
873
+ is: true,
874
+ then: function then(s) {
875
+ return s.required(getRequiredFieldError(entity));
876
+ }
877
+ }).when("$email", function (email, s) {
878
+ if (email !== null && email !== void 0 && email.trim()) {
879
+ return s.required(getRequiredFieldError(entity));
880
+ }
881
+ return s;
882
+ }).test("is-6-digit-number", t("neetoForm.error.mustBeASixDigitNumber", {
883
+ entity: entity
884
+ }), function (value) {
885
+ return isNotPresent(value) || SIX_DIGIT_NUMBER_REGEX.test(value);
886
+ }).test("verify code", t("neetoForm.error.emailNotVerified"), function () {
887
+ var _this$options;
888
+ return this === null || this === void 0 || (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.context) === null || _this$options === void 0 ? void 0 : _this$options.isCodeVerified;
889
+ });
890
+ }
891
+ });
892
+
893
+ // eslint-disable-next-line no-async-promise-executor
894
+ return new Promise(/*#__PURE__*/function () {
895
+ var _ref18 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve) {
896
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
897
+ while (1) switch (_context2.prev = _context2.next) {
898
+ case 0:
899
+ _context2.prev = 0;
900
+ _context2.next = 3;
901
+ return schema.validate(value, {
902
+ context: context
903
+ });
904
+ case 3:
905
+ resolve(undefined);
906
+ _context2.next = 9;
907
+ break;
908
+ case 6:
909
+ _context2.prev = 6;
910
+ _context2.t0 = _context2["catch"](0);
911
+ resolve(_context2.t0.message);
912
+ case 9:
913
+ case "end":
914
+ return _context2.stop();
915
+ }
916
+ }, _callee2, null, [[0, 6]]);
917
+ }));
918
+ return function (_x2) {
919
+ return _ref18.apply(this, arguments);
920
+ };
921
+ }());
922
+ };
923
+ };
924
+
925
+ var MultipleEmailInput = function MultipleEmailInput(_ref) {
926
+ var question = _ref.question,
927
+ customValidator = _ref.customValidator;
928
+ var name = question.id,
929
+ kind = question.kind,
930
+ isRequired = question.isRequired,
931
+ nodeId = question.nodeId,
932
+ isReadOnly = question.isReadOnly;
933
+ var label = fieldWithFallback(question, "label");
934
+ var _useFormikContext = useFormikContext(),
935
+ submitCount = _useFormikContext.submitCount;
936
+ var _useTranslation = useTranslation(),
937
+ t = _useTranslation.t;
938
+ var _useField = useField({
939
+ name: name || nodeId,
940
+ validate: validateFieldValue({
941
+ kind: kind,
942
+ label: label,
943
+ isRequired: isRequired,
944
+ customValidator: customValidator
945
+ })
946
+ }),
947
+ _useField2 = _slicedToArray(_useField, 3),
948
+ field = _useField2[0],
949
+ meta = _useField2[1],
950
+ _useField2$ = _useField2[2],
951
+ setValue = _useField2$.setValue,
952
+ setTouched = _useField2$.setTouched;
953
+ var _useState = useState(isPresent(field.value)),
954
+ _useState2 = _slicedToArray(_useState, 2),
955
+ isInputVisible = _useState2[0],
956
+ setIsInputVisible = _useState2[1];
957
+ return /*#__PURE__*/jsx("div", {
958
+ className: "neeto-form-engine-input__wrapper",
959
+ children: /*#__PURE__*/jsx("div", {
960
+ className: "w-full",
961
+ children: isInputVisible ? /*#__PURE__*/jsx(MultiEmailInput, {
962
+ isRequired: isRequired,
963
+ label: label,
964
+ disabled: isReadOnly,
965
+ error: meta.touched ? meta.error : "",
966
+ helpText: t("neetoForm.common.addGuestsHelper"),
967
+ name: field.name,
968
+ placeholder: fieldWithFallback(question, "placeholder"),
969
+ value: field.value,
970
+ onBlur: function onBlur() {
971
+ return setTouched(true);
972
+ },
973
+ onChange: setValue
974
+ }) : /*#__PURE__*/jsxs("div", {
975
+ className: "flex flex-col gap-2 items-end",
976
+ children: [/*#__PURE__*/jsx(Button, {
977
+ label: label,
978
+ "data-testid": "add-guest-button",
979
+ disabled: isReadOnly,
980
+ icon: Plus,
981
+ iconPosition: "left",
982
+ variant: "link",
983
+ onClick: function onClick() {
984
+ return setIsInputVisible(true);
985
+ }
986
+ }), (meta === null || meta === void 0 ? void 0 : meta.error) && submitCount > 0 && /*#__PURE__*/jsx("span", {
987
+ className: "text-error-500",
988
+ children: meta.error
989
+ })]
990
+ })
991
+ })
992
+ });
993
+ };
994
+
995
+ function ownKeys$h(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
996
+ function _objectSpread$h(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$h(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$h(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
997
+ var AddressField = function AddressField(_ref) {
998
+ var question = _ref.question,
999
+ customValidator = _ref.customValidator;
1000
+ var name = question.id,
1001
+ kind = question.kind,
1002
+ isAddressRequired = question.isRequired,
1003
+ isReadOnly = question.isReadOnly,
1004
+ _question$fields = question.fields,
1005
+ fields = _question$fields === void 0 ? [] : _question$fields;
1006
+ var label = fieldWithFallback(question, "label");
1007
+ var transformedFields = fields.map(function (field) {
1008
+ return _objectSpread$h(_objectSpread$h({}, field), {}, {
1009
+ label: fieldWithFallback(field, "label")
1010
+ });
1011
+ });
1012
+ return /*#__PURE__*/jsxs("div", {
1013
+ className: "neeto-form-engine-address-wrapper",
1014
+ children: [/*#__PURE__*/jsx("div", {
1015
+ className: "neeto-form-engine-input__label-wrapper",
1016
+ children: label && /*#__PURE__*/jsx("label", {
1017
+ className: "neeto-form-engine-label",
1018
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
1019
+ children: label
1020
+ })
1021
+ }), /*#__PURE__*/jsx("div", {
1022
+ className: "neeto-form-engine-address pb-1",
1023
+ children: getVisibleOptions(transformedFields).map(function (_ref2) {
1024
+ var id = _ref2.id,
1025
+ label = _ref2.label,
1026
+ width = _ref2.width,
1027
+ fieldType = _ref2.fieldType,
1028
+ properties = _ref2.properties,
1029
+ isRequired = _ref2.isRequired;
1030
+ return /*#__PURE__*/jsx("div", {
1031
+ "data-testid": "neeto-form-engine-address-fields",
1032
+ className: classnames("neeto-form-engine-address__field", {
1033
+ "neeto-form-engine-address__field--width-full": width === ADDRESS_FIELD_WIDTHS.FULL,
1034
+ "neeto-form-engine-address__field--width-half": width === ADDRESS_FIELD_WIDTHS.HALF,
1035
+ "neeto-form-engine-address__field--width-one-forth": width === ADDRESS_FIELD_WIDTHS.ONE_FOURTH,
1036
+ "neeto-form-engine-address__field--width-three-forth": width === ADDRESS_FIELD_WIDTHS.THREE_FOURTH
1037
+ }),
1038
+ children: /*#__PURE__*/jsx(Field$1, {
1039
+ name: "".concat(name, ".").concat(id),
1040
+ validate: isAddressRequired ? validateFieldValue({
1041
+ kind: kind,
1042
+ label: label,
1043
+ isRequired: isRequired,
1044
+ customValidator: customValidator
1045
+ }) : noop,
1046
+ children: function children(_ref3) {
1047
+ var _properties$options;
1048
+ var field = _ref3.field,
1049
+ meta = _ref3.meta,
1050
+ form = _ref3.form;
1051
+ return fieldType === ADDRESS_FIELD_TYPES.SELECT ? /*#__PURE__*/jsx(Select, _objectSpread$h(_objectSpread$h({
1052
+ label: label,
1053
+ size: "large"
1054
+ }, field), {}, {
1055
+ error: meta.touched && meta.error,
1056
+ isDisabled: isReadOnly,
1057
+ menuPosition: "absolute",
1058
+ required: isRequired,
1059
+ value: toLabelAndValue(field.value),
1060
+ options: properties === null || properties === void 0 || (_properties$options = properties.options) === null || _properties$options === void 0 ? void 0 : _properties$options.map(function (_ref4) {
1061
+ var label = _ref4.label;
1062
+ return toLabelAndValue(label);
1063
+ }),
1064
+ onChange: function onChange(_ref5) {
1065
+ var value = _ref5.value;
1066
+ return !isReadOnly && form.setFieldValue("".concat(name, ".").concat(id), value);
1067
+ }
1068
+ })) : /*#__PURE__*/jsx(Input, _objectSpread$h(_objectSpread$h({}, _objectSpread$h(_objectSpread$h({}, field), {}, {
1069
+ label: label
1070
+ })), {}, {
1071
+ disabled: isReadOnly,
1072
+ error: meta.touched && meta.error,
1073
+ required: isRequired
1074
+ }));
1075
+ }
1076
+ })
1077
+ }, id);
1078
+ })
1079
+ })]
1080
+ });
1081
+ };
1082
+
1083
+ var CaptchaField = function CaptchaField(_ref) {
1084
+ var question = _ref.question,
1085
+ preview = _ref.preview,
1086
+ customValidator = _ref.customValidator,
1087
+ captchaRef = _ref.captchaRef;
1088
+ var name = question.id,
1089
+ kind = question.kind,
1090
+ isRequired = question.isRequired,
1091
+ variant = question.variant,
1092
+ nodeId = question.nodeId;
1093
+ var label = fieldWithFallback(question, "label");
1094
+ var _useField = useField({
1095
+ name: name || nodeId,
1096
+ validate: validateFieldValue({
1097
+ kind: kind,
1098
+ label: label,
1099
+ isRequired: isRequired,
1100
+ customValidator: customValidator,
1101
+ variant: variant
1102
+ })
1103
+ }),
1104
+ _useField2 = _slicedToArray(_useField, 3);
1105
+ _useField2[0];
1106
+ var _useField2$ = _useField2[1],
1107
+ touched = _useField2$.touched,
1108
+ error = _useField2$.error,
1109
+ _useField2$2 = _useField2[2],
1110
+ setValue = _useField2$2.setValue,
1111
+ setTouched = _useField2$2.setTouched;
1112
+ var handleVerifyCaptcha = function handleVerifyCaptcha(response) {
1113
+ setTouched(true);
1114
+ setValue(response);
1115
+ };
1116
+ var Component = CAPTCHA_COMPONENT_MAP[variant];
1117
+ return /*#__PURE__*/jsxs("div", {
1118
+ className: "neeto-form-engine-input__wrapper",
1119
+ children: [/*#__PURE__*/jsx("div", {
1120
+ className: "neeto-form-engine-input__label-wrapper",
1121
+ children: label && /*#__PURE__*/jsx("label", {
1122
+ className: "neeto-form-engine-label",
1123
+ children: getLabel(label, isRequired)
1124
+ })
1125
+ }), /*#__PURE__*/jsx("div", {
1126
+ className: classnames({
1127
+ "pointer-events-none": preview
1128
+ }),
1129
+ children: /*#__PURE__*/jsx(Component, {
1130
+ captchaRef: captchaRef,
1131
+ handleVerifyCaptcha: handleVerifyCaptcha,
1132
+ handleBlur: function handleBlur() {
1133
+ return setTouched(true);
1134
+ }
1135
+ })
1136
+ }), touched && error && /*#__PURE__*/jsx("p", {
1137
+ className: "neeto-form-engine-input__error",
1138
+ "data-testid": "neeto-form-engine-captcha-error",
1139
+ children: error
1140
+ })]
1141
+ });
1142
+ };
1143
+
1144
+ var MATH_OPERATORS = {
1145
+ PLUS: "+",
1146
+ MINUS: "-"
1147
+ };
1148
+
1149
+ var generateRandomOperation = function generateRandomOperation() {
1150
+ var firstNumber = getRandomInt(1, 50);
1151
+ var secondNumber = getRandomInt(1, 50);
1152
+ var operator = randomPick.apply(void 0, _toConsumableArray(values(MATH_OPERATORS)));
1153
+ return {
1154
+ firstNumber: firstNumber,
1155
+ secondNumber: secondNumber,
1156
+ operator: operator
1157
+ };
1158
+ };
1159
+
1160
+ var MathCaptcha = function MathCaptcha(_ref) {
1161
+ var captchaRef = _ref.captchaRef,
1162
+ handleVerifyCaptcha = _ref.handleVerifyCaptcha,
1163
+ handleBlur = _ref.handleBlur;
1164
+ var _useState = useState(generateRandomOperation()),
1165
+ _useState2 = _slicedToArray(_useState, 2),
1166
+ operation = _useState2[0],
1167
+ setOperation = _useState2[1];
1168
+ var _useState3 = useState(""),
1169
+ _useState4 = _slicedToArray(_useState3, 2),
1170
+ userInput = _useState4[0],
1171
+ setUserInput = _useState4[1];
1172
+ var firstNumber = operation.firstNumber,
1173
+ secondNumber = operation.secondNumber,
1174
+ operator = operation.operator;
1175
+ var resetCaptcha = function resetCaptcha() {
1176
+ setOperation(generateRandomOperation());
1177
+ setUserInput("");
1178
+ };
1179
+ useImperativeHandle(captchaRef, function () {
1180
+ return {
1181
+ reset: resetCaptcha
1182
+ };
1183
+ });
1184
+ var calculateResult = function calculateResult() {
1185
+ switch (operator) {
1186
+ case MATH_OPERATORS.PLUS:
1187
+ return firstNumber + secondNumber;
1188
+ case MATH_OPERATORS.MINUS:
1189
+ return firstNumber - secondNumber;
1190
+ default:
1191
+ return null;
1192
+ }
1193
+ };
1194
+ var verifyCaptcha = function verifyCaptcha() {
1195
+ var result = calculateResult();
1196
+ if (result === null) return;
1197
+ handleVerifyCaptcha(result === Number(userInput));
1198
+ };
1199
+ useUpdateEffect(function () {
1200
+ verifyCaptcha();
1201
+ }, [userInput]);
1202
+ return /*#__PURE__*/jsxs("div", {
1203
+ className: "neeto-form-nano-math-captcha",
1204
+ "data-testid": "math-captcha",
1205
+ ref: captchaRef,
1206
+ children: [/*#__PURE__*/jsx("button", {
1207
+ className: "neeto-form-nano-math-captcha__button",
1208
+ type: "button",
1209
+ onClick: resetCaptcha,
1210
+ children: /*#__PURE__*/jsx(Refresh, {})
1211
+ }), /*#__PURE__*/jsxs("div", {
1212
+ className: "neeto-form-nano-math-captcha__equation",
1213
+ children: [/*#__PURE__*/jsx("span", {
1214
+ "data-testid": "first-number",
1215
+ children: firstNumber
1216
+ }), /*#__PURE__*/jsx("span", {
1217
+ "data-testid": "operator",
1218
+ children: operator
1219
+ }), /*#__PURE__*/jsx("span", {
1220
+ "data-testid": "second-number",
1221
+ children: secondNumber
1222
+ }), /*#__PURE__*/jsx("span", {
1223
+ children: "="
1224
+ })]
1225
+ }), /*#__PURE__*/jsx(Input, {
1226
+ required: true,
1227
+ className: "neeto-form-nano-math-captcha__input",
1228
+ "data-testid": "math-captcha-input",
1229
+ value: userInput,
1230
+ onBlur: handleBlur,
1231
+ onChange: withEventTargetValue(setUserInput)
1232
+ })]
1233
+ });
1234
+ };
1235
+
1236
+ var Recaptcha = function Recaptcha(_ref) {
1237
+ var captchaRef = _ref.captchaRef,
1238
+ handleVerifyCaptcha = _ref.handleVerifyCaptcha;
1239
+ var verifyRecaptcha = function verifyRecaptcha(response) {
1240
+ if (response === null) {
1241
+ return;
1242
+ }
1243
+ handleVerifyCaptcha(response);
1244
+ };
1245
+ var expiredRecaptcha = function expiredRecaptcha() {
1246
+ var _captchaRef$current;
1247
+ captchaRef === null || captchaRef === void 0 || (_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 || _captchaRef$current.reset();
1248
+ handleVerifyCaptcha("");
1249
+ };
1250
+ return /*#__PURE__*/jsx(ReCAPTCHA, {
1251
+ hl: clientI18nInstance$1.language,
1252
+ ref: captchaRef,
1253
+ sitekey: globalProps.formNanoRecaptchaV2SiteKey,
1254
+ onChange: verifyRecaptcha,
1255
+ onErrored: noop,
1256
+ onExpired: expiredRecaptcha
1257
+ }, clientI18nInstance$1.language);
1258
+ };
1259
+
1260
+ function ownKeys$g(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1261
+ function _objectSpread$g(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$g(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$g(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1262
+ var ConditionField = function ConditionField(_ref) {
1263
+ var question = _ref.question,
1264
+ customValidator = _ref.customValidator;
1265
+ var name = question.id,
1266
+ kind = question.kind,
1267
+ isRequired = question.isRequired,
1268
+ nodeId = question.nodeId;
1269
+ var label = fieldWithFallback(question, "label");
1270
+ return /*#__PURE__*/jsx(Field$1, {
1271
+ name: name || nodeId,
1272
+ validate: validateFieldValue({
1273
+ kind: kind,
1274
+ label: label,
1275
+ isRequired: isRequired,
1276
+ customValidator: customValidator
1277
+ }),
1278
+ children: function children(_ref2) {
1279
+ var meta = _ref2.meta,
1280
+ field = _ref2.field,
1281
+ form = _ref2.form;
1282
+ return /*#__PURE__*/jsx(Checkbox, _objectSpread$g(_objectSpread$g({}, _objectSpread$g(_objectSpread$g({}, field), {}, {
1283
+ label: label,
1284
+ name: name
1285
+ })), {}, {
1286
+ checked: field.value,
1287
+ error: meta.touched ? meta.error : "",
1288
+ required: isRequired,
1289
+ onCheckedChange: function onCheckedChange(checked) {
1290
+ return form.setFieldValue(name, checked);
1291
+ }
1292
+ }));
1293
+ }
1294
+ });
1295
+ };
1296
+
1297
+ var _excluded$3 = ["value"];
1298
+ function ownKeys$f(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1299
+ function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$f(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$f(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1300
+ var DateField = function DateField(_ref) {
1301
+ var question = _ref.question,
1302
+ customValidator = _ref.customValidator;
1303
+ var name = question.id,
1304
+ kind = question.kind,
1305
+ isRequired = question.isRequired,
1306
+ nodeId = question.nodeId,
1307
+ isReadOnly = question.isReadOnly;
1308
+ var label = fieldWithFallback(question, "label");
1309
+ var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()].type,
1310
+ type = _QUESTION_KIND$kind$t === void 0 ? "date" : _QUESTION_KIND$kind$t;
1311
+ return /*#__PURE__*/jsxs("div", {
1312
+ className: "neeto-form-engine-input__wrapper",
1313
+ children: [/*#__PURE__*/jsx("div", {
1314
+ className: "neeto-form-engine-input__label-wrapper",
1315
+ children: label && /*#__PURE__*/jsx("label", {
1316
+ className: "neeto-form-engine-label",
1317
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
1318
+ children: getLabel(label, isRequired)
1319
+ })
1320
+ }), /*#__PURE__*/jsx("div", {
1321
+ className: "neeto-form-engine-date-picker",
1322
+ children: /*#__PURE__*/jsx(Field$1, {
1323
+ name: name || nodeId,
1324
+ validate: validateFieldValue({
1325
+ kind: kind,
1326
+ label: label,
1327
+ isRequired: isRequired,
1328
+ customValidator: customValidator
1329
+ }),
1330
+ children: function children(_ref2) {
1331
+ var meta = _ref2.meta,
1332
+ _ref2$field = _ref2.field,
1333
+ value = _ref2$field.value,
1334
+ field = _objectWithoutProperties(_ref2$field, _excluded$3),
1335
+ form = _ref2.form;
1336
+ return /*#__PURE__*/jsx(DatePicker, _objectSpread$f(_objectSpread$f({}, _objectSpread$f(_objectSpread$f({}, field), {}, {
1337
+ type: type
1338
+ })), {}, {
1339
+ // TODO: atoms DatePicker has no `onCalendarChange`/`popupClassName` props; dateFormat now uses date-fns tokens instead of moment/dayjs tokens.
1340
+ "data-testid": "".concat(hyphenate(label), "-input-field"),
1341
+ dateFormat: "MMM d, yyyy",
1342
+ disabled: isReadOnly,
1343
+ error: meta.touched ? meta.error : "",
1344
+ placeholder: fieldWithFallback(question, "placeholder"),
1345
+ required: isRequired,
1346
+ size: "small",
1347
+ value: getValidDate(value),
1348
+ onChange: function onChange(date) {
1349
+ form.setFieldValue(name, date ? date.toISOString() : "");
1350
+ }
1351
+ }));
1352
+ }
1353
+ })
1354
+ })]
1355
+ });
1356
+ };
1357
+
1358
+ var create = function create(_ref) {
1359
+ var formId = _ref.formId,
1360
+ questionId = _ref.questionId,
1361
+ payload = _ref.payload;
1362
+ return axios.post(buildUrl(EMAIL_VERIFICATIONS_CREATE_URL, {
1363
+ formId: formId,
1364
+ questionId: questionId
1365
+ }), payload, {
1366
+ showToastr: false
1367
+ });
1368
+ };
1369
+ var verify = function verify(_ref2) {
1370
+ var formId = _ref2.formId,
1371
+ questionId = _ref2.questionId,
1372
+ payload = _ref2.payload;
1373
+ return axios.post(buildUrl(EMAIL_VERIFICATIONS_VERIFY_URL, {
1374
+ formId: formId,
1375
+ questionId: questionId
1376
+ }), payload, {
1377
+ showToastr: false
1378
+ });
1379
+ };
1380
+ var emailVerificationsApi = {
1381
+ create: create,
1382
+ verify: verify
1383
+ };
1384
+
1385
+ function ownKeys$e(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1386
+ function _objectSpread$e(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$e(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1387
+ var getMutationCallbacks = function getMutationCallbacks(options) {
1388
+ return {
1389
+ onSuccess: function onSuccess() {
1390
+ var _options$onSuccess;
1391
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1392
+ args[_key] = arguments[_key];
1393
+ }
1394
+ return (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call.apply(_options$onSuccess, [options].concat(args));
1395
+ },
1396
+ onError: function onError() {
1397
+ var _options$onError;
1398
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1399
+ args[_key2] = arguments[_key2];
1400
+ }
1401
+ return (_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call.apply(_options$onError, [options].concat(args));
1402
+ }
1403
+ };
1404
+ };
1405
+ var useSendEmailVerificationCode = function useSendEmailVerificationCode(formId, questionId) {
1406
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1407
+ return useMutation(_objectSpread$e(_objectSpread$e({
1408
+ mutationFn: function mutationFn(payload) {
1409
+ return emailVerificationsApi.create({
1410
+ formId: formId,
1411
+ questionId: questionId,
1412
+ payload: payload
1413
+ });
1414
+ }
1415
+ }, options), getMutationCallbacks(options)));
1416
+ };
1417
+ var useVerifyEmailVerificationCode = function useVerifyEmailVerificationCode(formId, questionId) {
1418
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1419
+ return useMutation(_objectSpread$e(_objectSpread$e({
1420
+ mutationFn: function mutationFn(payload) {
1421
+ return emailVerificationsApi.verify({
1422
+ formId: formId,
1423
+ questionId: questionId,
1424
+ payload: payload
1425
+ });
1426
+ }
1427
+ }, options), getMutationCallbacks(options)));
1428
+ };
1429
+
1430
+ var SendCodeButton = function SendCodeButton(_ref) {
1431
+ var isCodeVerified = _ref.isCodeVerified,
1432
+ isSendingVerificationCode = _ref.isSendingVerificationCode,
1433
+ handleClick = _ref.handleClick,
1434
+ isDisabled = _ref.isDisabled;
1435
+ var _useTranslation = useTranslation(),
1436
+ t = _useTranslation.t;
1437
+ if (isCodeVerified) {
1438
+ return /*#__PURE__*/jsx(CheckCircle, {});
1439
+ }
1440
+ return /*#__PURE__*/jsx(Button, {
1441
+ "data-testid": "send-code-button",
1442
+ disabled: isDisabled,
1443
+ size: "sm",
1444
+ variant: "outline",
1445
+ onClick: handleClick,
1446
+ children: isSendingVerificationCode ? /*#__PURE__*/jsx(Spinner, {
1447
+ size: "16"
1448
+ }) : t("neetoForm.emailVerification.sendCode")
1449
+ });
1450
+ };
1451
+
1452
+ var ResendVerificationCode = function ResendVerificationCode(_ref) {
1453
+ var formId = _ref.formId,
1454
+ questionId = _ref.questionId,
1455
+ sendVerificationCode = _ref.sendVerificationCode,
1456
+ isResendDisabled = _ref.isResendDisabled;
1457
+ var _useState = useState(getRemainingTime(formId, questionId)),
1458
+ _useState2 = _slicedToArray(_useState, 2),
1459
+ secondsLeft = _useState2[0],
1460
+ setSecondsLeft = _useState2[1];
1461
+ var _useTranslation = useTranslation(),
1462
+ t = _useTranslation.t;
1463
+ useEffect(function () {
1464
+ if (secondsLeft <= 0) return undefined;
1465
+ var interval = setTimeout(function () {
1466
+ setSecondsLeft(pipe(dec, max(0)));
1467
+ }, ONE_SECOND);
1468
+ return function () {
1469
+ return clearTimeout(interval);
1470
+ };
1471
+ }, [secondsLeft]);
1472
+ var handleResendClick = function handleResendClick() {
1473
+ if (secondsLeft !== 0) return;
1474
+ sendVerificationCode();
1475
+ setSecondsLeft(RESEND_DELAY);
1476
+ storeLastVerificationCodeSentAt(formId, questionId);
1477
+ };
1478
+ return /*#__PURE__*/jsx("p", {
1479
+ children: !isResendDisabled && secondsLeft > 0 ? t("neetoForm.emailVerification.resendInSeconds", {
1480
+ secondsLeft: secondsLeft
1481
+ }) : /*#__PURE__*/jsx(Trans, {
1482
+ i18nKey: "neetoForm.emailVerification.resendCode",
1483
+ components: {
1484
+ button: /*#__PURE__*/jsx(Button, {
1485
+ "data-testid": "otp-resend-button",
1486
+ disabled: isResendDisabled,
1487
+ size: "sm",
1488
+ variant: "link",
1489
+ onClick: handleResendClick
1490
+ })
1491
+ }
1492
+ })
1493
+ });
1494
+ };
1495
+
1496
+ function ownKeys$d(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1497
+ function _objectSpread$d(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$d(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1498
+ var VerifyCode = function VerifyCode(_ref) {
1499
+ var formId = _ref.formId,
1500
+ questionId = _ref.questionId,
1501
+ email = _ref.email,
1502
+ emailVerificationToken = _ref.emailVerificationToken,
1503
+ isCodeVerified = _ref.isCodeVerified,
1504
+ setIsCodeVerified = _ref.setIsCodeVerified,
1505
+ handleResponseError = _ref.handleResponseError,
1506
+ hasSentVerificationCode = _ref.hasSentVerificationCode,
1507
+ calloutDetails = _ref.calloutDetails,
1508
+ handleSendVerificationCode = _ref.handleSendVerificationCode,
1509
+ isRequired = _ref.isRequired,
1510
+ isVerificationEnabled = _ref.isVerificationEnabled;
1511
+ var _useTranslation = useTranslation(),
1512
+ t = _useTranslation.t;
1513
+ var verificationFieldName = buildVerificationFieldName(questionId);
1514
+ var _useField = useField({
1515
+ name: verificationFieldName,
1516
+ validate: validateVerificationCode({
1517
+ isVerificationEnabled: isVerificationEnabled,
1518
+ isRequired: isRequired,
1519
+ email: email,
1520
+ isCodeVerified: isCodeVerified
1521
+ })
1522
+ }),
1523
+ _useField2 = _slicedToArray(_useField, 3),
1524
+ field = _useField2[0],
1525
+ _useField2$ = _useField2[1],
1526
+ touched = _useField2$.touched,
1527
+ error = _useField2$.error,
1528
+ _useField2$2 = _useField2[2],
1529
+ setValue = _useField2$2.setValue,
1530
+ setTouched = _useField2$2.setTouched;
1531
+ var code = field.value;
1532
+ var _useState = useState(code),
1533
+ _useState2 = _slicedToArray(_useState, 2),
1534
+ previousCode = _useState2[0],
1535
+ setPreviousCode = _useState2[1];
1536
+ var _useVerifyEmailVerifi = useVerifyEmailVerificationCode(formId, questionId, {
1537
+ onSuccess: function onSuccess(_, _ref2) {
1538
+ var emailVerifications = _ref2.emailVerifications;
1539
+ setIsCodeVerified(true);
1540
+ setPreviousCode(emailVerifications.otp);
1541
+ setEmailVerificationDetail(formId, questionId, _defineProperty(_defineProperty(_defineProperty({}, EMAIL_VERIFICATION_KEYS.EMAIL, emailVerifications.email), EMAIL_VERIFICATION_KEYS.CODE, emailVerifications.otp), EMAIL_VERIFICATION_KEYS.VERIFIED, true));
1542
+ },
1543
+ onError: handleResponseError
1544
+ }),
1545
+ verifyCode = _useVerifyEmailVerifi.mutate,
1546
+ isVerifyingCode = _useVerifyEmailVerifi.isPending;
1547
+ var hasError = isPresent(error);
1548
+ useEffect(function () {
1549
+ var handleVerifyCode = function handleVerifyCode() {
1550
+ if (equals(code, previousCode) || hasError || (code === null || code === void 0 ? void 0 : code.length) !== 6) {
1551
+ return;
1552
+ }
1553
+ verifyCode({
1554
+ emailVerifications: {
1555
+ email: email,
1556
+ token: emailVerificationToken,
1557
+ otp: code
1558
+ }
1559
+ });
1560
+ };
1561
+ handleVerifyCode();
1562
+ }, [code, hasError]);
1563
+ return /*#__PURE__*/jsxs(Fragment, {
1564
+ children: [/*#__PURE__*/jsx(Input, _objectSpread$d(_objectSpread$d({}, _objectSpread$d({}, field)), {}, {
1565
+ "data-testid": "otp-input-field",
1566
+ disabled: isVerifyingCode,
1567
+ error: touched ? error : "",
1568
+ loading: isVerifyingCode,
1569
+ name: verificationFieldName,
1570
+ placeholder: t("neetoForm.emailVerification.verificationCode"),
1571
+ size: "small",
1572
+ onBlur: function onBlur() {
1573
+ return setTouched(true);
1574
+ },
1575
+ onChange: withEventTargetValue(setValue)
1576
+ })), hasSentVerificationCode && /*#__PURE__*/jsx(ResendVerificationCode, {
1577
+ formId: formId,
1578
+ questionId: questionId,
1579
+ isResendDisabled: calloutDetails.style === CALLOUT_STYLES.ERROR,
1580
+ sendVerificationCode: handleSendVerificationCode
1581
+ }), calloutDetails.message && /*#__PURE__*/jsx(Callout, {
1582
+ variant: calloutDetails.style,
1583
+ children: calloutDetails.message
1584
+ })]
1585
+ });
1586
+ };
1587
+
1588
+ function ownKeys$c(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1589
+ function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1590
+ var EmailField = function EmailField(_ref) {
1591
+ var question = _ref.question,
1592
+ customValidator = _ref.customValidator,
1593
+ autoComplete = _ref.autoComplete,
1594
+ isFormPreview = _ref.preview,
1595
+ isUrlBuilderPreview = _ref.isUrlBuilderPreview;
1596
+ var questionId = question.id,
1597
+ kind = question.kind,
1598
+ isRequired = question.isRequired,
1599
+ isReadOnly = question.isReadOnly,
1600
+ isDomainWhitelistingEnabled = question.isDomainWhitelistingEnabled,
1601
+ whitelistedDomains = question.whitelistedDomains,
1602
+ isDomainBlacklistingEnabled = question.isDomainBlacklistingEnabled,
1603
+ blacklistedDomains = question.blacklistedDomains,
1604
+ isVerificationEnabled = question.isVerificationEnabled,
1605
+ nodeId = question.nodeId,
1606
+ formId = question.formId;
1607
+ var label = fieldWithFallback(question, "label");
1608
+ var _useState = useState(DEFAULT_CALLOUT_DETAILS),
1609
+ _useState2 = _slicedToArray(_useState, 2),
1610
+ calloutDetails = _useState2[0],
1611
+ setCalloutDetails = _useState2[1];
1612
+ var type = QUESTION_KIND[kind.toUpperCase()].type;
1613
+ var _useState3 = useState(getLastVerificationCodeSentAt(questionId) > 0),
1614
+ _useState4 = _slicedToArray(_useState3, 2),
1615
+ hasSentVerificationCode = _useState4[0],
1616
+ setHasSentVerificationCode = _useState4[1];
1617
+ var verificationStatus = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.VERIFIED);
1618
+ var _useStateWithDependen = useStateWithDependency(verificationStatus, [verificationStatus]),
1619
+ _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
1620
+ isCodeVerified = _useStateWithDependen2[0],
1621
+ setIsCodeVerified = _useStateWithDependen2[1];
1622
+ var _useField = useField({
1623
+ name: questionId || nodeId,
1624
+ validate: validateFieldValue({
1625
+ kind: kind,
1626
+ label: label,
1627
+ isRequired: isRequired,
1628
+ customValidator: customValidator,
1629
+ whitelistedDomains: isDomainWhitelistingEnabled ? whitelistedDomains : [],
1630
+ blacklistedDomains: isDomainBlacklistingEnabled ? blacklistedDomains : []
1631
+ })
1632
+ }),
1633
+ _useField2 = _slicedToArray(_useField, 3),
1634
+ field = _useField2[0],
1635
+ _useField2$ = _useField2[1],
1636
+ touched = _useField2$.touched,
1637
+ error = _useField2$.error,
1638
+ _useField2$2 = _useField2[2],
1639
+ setValue = _useField2$2.setValue,
1640
+ setTouched = _useField2$2.setTouched;
1641
+ var _useFormikContext = useFormikContext(),
1642
+ setFieldValue = _useFormikContext.setFieldValue;
1643
+ var email = field.value;
1644
+ var emailVerificationToken = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.TOKEN);
1645
+ var handleResponseError = function handleResponseError(error) {
1646
+ var _error$response;
1647
+ var message = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.error;
1648
+ if ((error === null || error === void 0 ? void 0 : error.status) === 429) {
1649
+ setCalloutDetails({
1650
+ message: message,
1651
+ style: CALLOUT_STYLES.ERROR
1652
+ });
1653
+ storeLastVerificationCodeSentAt(formId, questionId, RESEND_DELAY * ONE_SECOND);
1654
+ } else {
1655
+ Toastr.error(message);
1656
+ }
1657
+ };
1658
+
1659
+ // TODO backend validation
1660
+ var _useSendEmailVerifica = useSendEmailVerificationCode(formId, questionId, {
1661
+ onSuccess: function onSuccess(_ref2) {
1662
+ var token = _ref2.token,
1663
+ message = _ref2.message;
1664
+ setHasSentVerificationCode(true);
1665
+ storeLastVerificationCodeSentAt(formId, questionId);
1666
+ if (!emailVerificationToken) {
1667
+ setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.TOKEN, token));
1668
+ }
1669
+ if (message) {
1670
+ setCalloutDetails({
1671
+ message: message,
1672
+ style: CALLOUT_STYLES.WARNING
1673
+ });
1674
+ }
1675
+ },
1676
+ onError: handleResponseError
1677
+ }),
1678
+ sendVerificationCode = _useSendEmailVerifica.mutate,
1679
+ isSendingVerificationCode = _useSendEmailVerifica.isPending;
1680
+ var resetVerifiedData = function resetVerifiedData(email) {
1681
+ var verifiedEmail = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.EMAIL);
1682
+ if (email !== verifiedEmail) {
1683
+ removeEmailVerificationDetail(formId, questionId, values(omit(["TOKEN"], EMAIL_VERIFICATION_KEYS)));
1684
+ setIsCodeVerified(false);
1685
+ setFieldValue(buildVerificationFieldName(questionId), "");
1686
+ setHasSentVerificationCode(false);
1687
+ setCalloutDetails(DEFAULT_CALLOUT_DETAILS);
1688
+ }
1689
+ };
1690
+ var handleFieldChange = withEventTargetValue(setValue);
1691
+ var handleSendVerificationCode = function handleSendVerificationCode() {
1692
+ return sendVerificationCode({
1693
+ emailVerifications: {
1694
+ email: email,
1695
+ token: emailVerificationToken
1696
+ }
1697
+ });
1698
+ };
1699
+ var shouldShowVerifyButton = isVerificationEnabled && !isUrlBuilderPreview && (isFormPreview || isPresent(email) && isNotPresent(error));
1700
+ var shouldShowVerificationCodeInput = shouldShowVerifyButton && !isFormPreview && !isCodeVerified;
1701
+ return /*#__PURE__*/jsxs("div", {
1702
+ className: "flex-col space-y-2",
1703
+ children: [/*#__PURE__*/jsx(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c(_objectSpread$c({
1704
+ type: type
1705
+ }, field), {}, {
1706
+ autoComplete: autoComplete,
1707
+ label: label
1708
+ }, shouldShowVerifyButton && {
1709
+ suffix: /*#__PURE__*/jsx(SendCodeButton, {
1710
+ isCodeVerified: isCodeVerified,
1711
+ isSendingVerificationCode: isSendingVerificationCode,
1712
+ handleClick: isFormPreview ? noop : handleSendVerificationCode,
1713
+ isDisabled: isCodeVerified || hasSentVerificationCode
1714
+ })
1715
+ })), {}, {
1716
+ disabled: isReadOnly,
1717
+ error: touched && !isCodeVerified ? error : "",
1718
+ name: kind,
1719
+ placeholder: fieldWithFallback(question, "placeholder"),
1720
+ required: isRequired,
1721
+ onBlur: function onBlur() {
1722
+ return setTouched(true);
1723
+ },
1724
+ onBlurCapture: withEventTargetValue(resetVerifiedData),
1725
+ onChange: handleFieldChange
1726
+ })), shouldShowVerificationCodeInput && /*#__PURE__*/jsx(VerifyCode, {
1727
+ calloutDetails: calloutDetails,
1728
+ email: email,
1729
+ emailVerificationToken: emailVerificationToken,
1730
+ formId: formId,
1731
+ handleResponseError: handleResponseError,
1732
+ handleSendVerificationCode: handleSendVerificationCode,
1733
+ hasSentVerificationCode: hasSentVerificationCode,
1734
+ isCodeVerified: isCodeVerified,
1735
+ isRequired: isRequired,
1736
+ isVerificationEnabled: isVerificationEnabled,
1737
+ questionId: questionId,
1738
+ setIsCodeVerified: setIsCodeVerified
1739
+ })]
1740
+ });
1741
+ };
1742
+
1743
+ var FileUploadField = function FileUploadField(_ref) {
1744
+ var question = _ref.question,
1745
+ _ref$preview = _ref.preview,
1746
+ preview = _ref$preview === void 0 ? false : _ref$preview,
1747
+ customValidator = _ref.customValidator;
1748
+ var name = question.id,
1749
+ kind = question.kind,
1750
+ isRequired = question.isRequired,
1751
+ nodeId = question.nodeId,
1752
+ allowedFileTypes = question.allowedFileTypes,
1753
+ multipleFilesAllowed = question.multipleFilesAllowed,
1754
+ maxFileSize = question.maxFileSize;
1755
+ var label = fieldWithFallback(question, "label");
1756
+ var _useField = useField({
1757
+ name: name || nodeId,
1758
+ validate: validateFieldValue({
1759
+ kind: kind,
1760
+ label: label,
1761
+ isRequired: isRequired,
1762
+ customValidator: customValidator,
1763
+ multipleFilesAllowed: multipleFilesAllowed
1764
+ })
1765
+ }),
1766
+ _useField2 = _slicedToArray(_useField, 3);
1767
+ _useField2[0];
1768
+ var _useField2$ = _useField2[1],
1769
+ value = _useField2$.value,
1770
+ touched = _useField2$.touched,
1771
+ error = _useField2$.error,
1772
+ _useField2$2 = _useField2[2],
1773
+ setValue = _useField2$2.setValue,
1774
+ setError = _useField2$2.setError,
1775
+ setTouched = _useField2$2.setTouched;
1776
+ var errorToDisplay = touched && error ? error : "";
1777
+ return /*#__PURE__*/jsxs("div", {
1778
+ className: "neeto-form-engine-input__wrapper",
1779
+ children: [/*#__PURE__*/jsx("div", {
1780
+ className: "neeto-form-engine-input__label-wrapper",
1781
+ children: /*#__PURE__*/jsx(Label, {
1782
+ className: "neeto-form-engine-label",
1783
+ required: isRequired,
1784
+ children: label
1785
+ })
1786
+ }), /*#__PURE__*/jsx(FileUpload, {
1787
+ allowedFileTypes: allowedFileTypes,
1788
+ maxFileSize: maxFileSize,
1789
+ multipleFilesAllowed: multipleFilesAllowed,
1790
+ setError: setError,
1791
+ setTouched: setTouched,
1792
+ error: errorToDisplay,
1793
+ files: value === null || value === void 0 ? void 0 : value.files,
1794
+ isPreview: preview,
1795
+ onChange: function onChange(files) {
1796
+ return setValue({
1797
+ files: files
1798
+ });
1799
+ }
1800
+ })]
1801
+ });
1802
+ };
1803
+
1804
+ function ownKeys$b(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1805
+ function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1806
+ var Field = function Field(_ref) {
1807
+ var question = _ref.question,
1808
+ name = _ref.name,
1809
+ labelField = _ref.labelField,
1810
+ placeholderField = _ref.placeholderField,
1811
+ customValidator = _ref.customValidator,
1812
+ autoComplete = _ref.autoComplete;
1813
+ var kind = question.kind,
1814
+ isRequired = question.isRequired,
1815
+ nodeId = question.nodeId,
1816
+ isReadOnly = question.isReadOnly;
1817
+ var label = fieldWithFallback(question, labelField);
1818
+ var type = QUESTION_KIND.NAME.type;
1819
+ var _useField = useField({
1820
+ name: name || nodeId,
1821
+ validate: validateFieldValue({
1822
+ kind: kind,
1823
+ label: label,
1824
+ isRequired: isRequired,
1825
+ customValidator: customValidator
1826
+ })
1827
+ }),
1828
+ _useField2 = _slicedToArray(_useField, 3),
1829
+ field = _useField2[0],
1830
+ _useField2$ = _useField2[1],
1831
+ touched = _useField2$.touched,
1832
+ error = _useField2$.error,
1833
+ _useField2$2 = _useField2[2],
1834
+ setValue = _useField2$2.setValue,
1835
+ setTouched = _useField2$2.setTouched;
1836
+ return /*#__PURE__*/jsx(Input, _objectSpread$b(_objectSpread$b({}, _objectSpread$b(_objectSpread$b({
1837
+ type: type
1838
+ }, field), {}, {
1839
+ autoComplete: autoComplete,
1840
+ label: label,
1841
+ name: name
1842
+ })), {}, {
1843
+ disabled: isReadOnly,
1844
+ error: touched ? error : "",
1845
+ placeholder: fieldWithFallback(question, placeholderField),
1846
+ required: isRequired,
1847
+ onBlur: function onBlur() {
1848
+ return setTouched(true);
1849
+ },
1850
+ onChange: withEventTargetValue(setValue)
1851
+ }));
1852
+ };
1853
+
1854
+ function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1855
+ function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1856
+ var NameField = function NameField(props) {
1857
+ var _props$question = props.question,
1858
+ id = _props$question.id,
1859
+ isSplitMode = _props$question.isSplitMode;
1860
+ if (isSplitMode) {
1861
+ return /*#__PURE__*/jsxs("div", {
1862
+ className: "flex w-full justify-between space-x-4",
1863
+ children: [/*#__PURE__*/jsx(Field, _objectSpread$a(_objectSpread$a({}, props), {}, {
1864
+ labelField: LABEL_FIELDS.FIRST_NAME,
1865
+ name: "".concat(id, ".firstName"),
1866
+ placeholderField: "firstNamePlaceholder"
1867
+ })), /*#__PURE__*/jsx(Field, _objectSpread$a(_objectSpread$a({}, props), {}, {
1868
+ labelField: LABEL_FIELDS.LAST_NAME,
1869
+ name: "".concat(id, ".lastName"),
1870
+ placeholderField: "lastNamePlaceholder"
1871
+ }))]
1872
+ });
1873
+ }
1874
+ return /*#__PURE__*/jsx(Field, _objectSpread$a(_objectSpread$a({}, props), {}, {
1875
+ labelField: LABEL_FIELDS.FULL_NAME,
1876
+ name: "".concat(id, ".fullName"),
1877
+ placeholderField: "fullNamePlaceholder"
1878
+ }));
1879
+ };
1880
+
1881
+ var OpinionScaleField = function OpinionScaleField(_ref) {
1882
+ var question = _ref.question,
1883
+ customValidator = _ref.customValidator;
1884
+ var name = question.id,
1885
+ kind = question.kind,
1886
+ isRequired = question.isRequired,
1887
+ minValue = question.minValue,
1888
+ maxValue = question.maxValue,
1889
+ isReadOnly = question.isReadOnly,
1890
+ hasOpinionLabels = question.hasOpinionLabels;
1891
+ var label = fieldWithFallback(question, "label");
1892
+ var leftOpinionLabel = fieldWithFallback(question, "leftOpinionLabel");
1893
+ var rightOpinionLabel = fieldWithFallback(question, "rightOpinionLabel");
1894
+ var _useField = useField({
1895
+ name: name,
1896
+ validate: validateFieldValue({
1897
+ kind: kind,
1898
+ label: label,
1899
+ isRequired: isRequired,
1900
+ customValidator: customValidator
1901
+ })
1902
+ }),
1903
+ _useField2 = _slicedToArray(_useField, 3),
1904
+ field = _useField2[0],
1905
+ _useField2$ = _useField2[1],
1906
+ error = _useField2$.error,
1907
+ touched = _useField2$.touched,
1908
+ setValue = _useField2[2].setValue;
1909
+ var handleClick = function handleClick(event, index) {
1910
+ if (index !== parseInt(field.value)) return;
1911
+ event.preventDefault();
1912
+ setValue("");
1913
+ };
1914
+ var opinionScaleOptions = generateArray(minValue, maxValue);
1915
+ return /*#__PURE__*/jsxs("div", {
1916
+ className: "neeto-form-engine-input__wrapper neeto-form-engine-opinion-scale",
1917
+ children: [/*#__PURE__*/jsx("div", {
1918
+ className: "neeto-form-engine-input__label-wrapper",
1919
+ children: /*#__PURE__*/jsx("label", {
1920
+ className: "neeto-form-engine-label",
1921
+ "data-testid": "opinion-scale-input-label",
1922
+ children: getLabel(label, isRequired)
1923
+ })
1924
+ }), /*#__PURE__*/jsx("div", {
1925
+ className: "neeto-form-nano-opinion-scale",
1926
+ "data-testid": "form-opinion-scale",
1927
+ children: /*#__PURE__*/jsxs("div", {
1928
+ className: "neeto-form-nano-opinion-scale__group",
1929
+ children: [hasOpinionLabels && /*#__PURE__*/jsx("div", {
1930
+ className: "neeto-form-nano-opinion-scale__labels-wrap neeto-form-nano-opinion-scale__labels-wrap-mobile",
1931
+ children: /*#__PURE__*/jsx("label", {
1932
+ className: "neeto-form-nano-opinion-scale__label",
1933
+ "data-testid": "opinion-scale-left-label",
1934
+ children: leftOpinionLabel
1935
+ })
1936
+ }), /*#__PURE__*/jsx("ul", {
1937
+ className: "neeto-form-nano-opinion-scale__list",
1938
+ "data-testid": "opinion-scale-list",
1939
+ children: opinionScaleOptions.map(function (step) {
1940
+ return /*#__PURE__*/jsx("li", {
1941
+ className: "neeto-form-nano-opinion-scale__item",
1942
+ "data-testid": "opinion-scale-list-item",
1943
+ children: /*#__PURE__*/jsxs("label", {
1944
+ className: "neeto-form-nano-opinion-scale__item-label",
1945
+ "data-testid": "opinion-scale-label",
1946
+ onClick: function onClick(event) {
1947
+ return handleClick(event, step);
1948
+ },
1949
+ children: [/*#__PURE__*/jsx(Field$1, {
1950
+ name: name,
1951
+ checked: parseInt(field.value) === step,
1952
+ className: "neeto-form-nano-sr-only neeto-form-nano-opinion-scale__item-input",
1953
+ "data-testid": "opinion-scale-input-".concat(step),
1954
+ disabled: isReadOnly,
1955
+ type: "radio",
1956
+ value: step
1957
+ }), /*#__PURE__*/jsx("span", {
1958
+ className: "neeto-form-nano-opinion-scale__item-highlight",
1959
+ "data-testid": "opinion-scale-item-".concat(step),
1960
+ children: step
1961
+ })]
1962
+ })
1963
+ }, step);
1964
+ })
1965
+ }), hasOpinionLabels && /*#__PURE__*/jsxs("div", {
1966
+ className: "neeto-form-nano-opinion-scale__labels-wrap",
1967
+ children: [/*#__PURE__*/jsx("label", {
1968
+ className: "neeto-form-nano-opinion-scale__label neeto-form-nano-opinion-scale__label--start",
1969
+ "data-testid": "opinion-scale-left-label",
1970
+ children: leftOpinionLabel
1971
+ }), /*#__PURE__*/jsx("label", {
1972
+ className: "neeto-form-nano-opinion-scale__label neeto-form-nano-opinion-scale__label--end",
1973
+ "data-testid": "opinion-scale-right-label",
1974
+ children: rightOpinionLabel
1975
+ })]
1976
+ })]
1977
+ })
1978
+ }), touched && error && /*#__PURE__*/jsx("p", {
1979
+ className: "neeto-form-engine-input__error",
1980
+ "data-testid": "neeto-form-engine-opinion-scale-error",
1981
+ children: error
1982
+ })]
1983
+ });
1984
+ };
1985
+
1986
+ var ChoiceImage = function ChoiceImage(_ref) {
1987
+ var src = _ref.src,
1988
+ alt = _ref.alt,
1989
+ height = _ref.height,
1990
+ shouldFitImages = _ref.shouldFitImages;
1991
+ var _useState = useState(false),
1992
+ _useState2 = _slicedToArray(_useState, 2),
1993
+ hasError = _useState2[0],
1994
+ setHasError = _useState2[1];
1995
+ var _useState3 = useState(true),
1996
+ _useState4 = _slicedToArray(_useState3, 2),
1997
+ isLoading = _useState4[0],
1998
+ setIsLoading = _useState4[1];
1999
+ var handleLoad = function handleLoad() {
2000
+ return setIsLoading(false);
2001
+ };
2002
+ var handleError = function handleError() {
2003
+ setHasError(true);
2004
+ setIsLoading(false);
2005
+ };
2006
+ if (hasError || !src) {
2007
+ return /*#__PURE__*/jsx("div", {
2008
+ className: "neeto-form-engine-choice__image-placeholder bg-muted",
2009
+ style: {
2010
+ height: height
2011
+ },
2012
+ children: /*#__PURE__*/jsx(Image, {
2013
+ size: 32
2014
+ })
2015
+ });
2016
+ }
2017
+ return /*#__PURE__*/jsx("div", {
2018
+ style: {
2019
+ height: height
2020
+ },
2021
+ className: classnames("neeto-form-engine-choice__image-wrapper", {
2022
+ "neeto-form-engine-choice__image-wrapper--loading": isLoading
2023
+ }),
2024
+ children: /*#__PURE__*/jsx("img", {
2025
+ alt: alt,
2026
+ src: src,
2027
+ draggable: false,
2028
+ className: classnames("neeto-form-engine-choice__image", {
2029
+ "neeto-form-engine-choice__image--fit": shouldFitImages
2030
+ }),
2031
+ onError: handleError,
2032
+ onLoad: handleLoad
2033
+ })
2034
+ });
2035
+ };
2036
+
2037
+ function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2038
+ function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2039
+ var Choices$1 = function Choices(_ref) {
2040
+ var label = _ref.label,
2041
+ options = _ref.options,
2042
+ type = _ref.type,
2043
+ name = _ref.name,
2044
+ value = _ref.value,
2045
+ onChange = _ref.onChange,
2046
+ onValueChange = _ref.onValueChange,
2047
+ error = _ref.error,
2048
+ disabled = _ref.isDisabled,
2049
+ _ref$isPictureChoice = _ref.isPictureChoice,
2050
+ isPictureChoice = _ref$isPictureChoice === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.isPictureChoice : _ref$isPictureChoice,
2051
+ _ref$imageHeight = _ref.imageHeight,
2052
+ imageHeight = _ref$imageHeight === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.imageHeight : _ref$imageHeight,
2053
+ _ref$shouldFitImages = _ref.shouldFitImages,
2054
+ shouldFitImages = _ref$shouldFitImages === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.shouldFitImages : _ref$shouldFitImages;
2055
+ var isCheckBox = type === "checkbox";
2056
+ var ChoiceWrapper = isCheckBox ? "div" : RadioGroup;
2057
+ var handleChoiceValueChange = function handleChoiceValueChange(updatedValue) {
2058
+ if (typeof onValueChange === "function") {
2059
+ onValueChange(updatedValue);
2060
+ return;
2061
+ }
2062
+ onChange({
2063
+ target: {
2064
+ name: name,
2065
+ value: updatedValue
2066
+ }
2067
+ });
2068
+ };
2069
+ var shouldDeselectOption = function shouldDeselectOption(optionId) {
2070
+ return !isCheckBox && !disabled && value === optionId;
2071
+ };
2072
+ var handleChoiceClick = function handleChoiceClick(event, optionId) {
2073
+ if (!shouldDeselectOption(optionId)) return;
2074
+ event.preventDefault();
2075
+ handleChoiceValueChange("");
2076
+ };
2077
+ var handleChoiceKeyDown = function handleChoiceKeyDown(event, optionId) {
2078
+ if (!shouldDeselectOption(optionId)) return;
2079
+ if (!RADIO_DESELECT_KEYS.includes(event.key)) return;
2080
+ event.preventDefault();
2081
+ handleChoiceValueChange("");
2082
+ };
2083
+ return /*#__PURE__*/jsxs("div", {
2084
+ className: "neeto-form-engine-choices__wrapper",
2085
+ "data-testid": "".concat(hyphenate(label), "-select-container-wrapper"),
2086
+ children: [/*#__PURE__*/jsx("label", {
2087
+ className: "neeto-form-engine-label",
2088
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
2089
+ children: label
2090
+ }), /*#__PURE__*/jsx(ChoiceWrapper, _objectSpread$9(_objectSpread$9({}, isCheckBox ? {} : {
2091
+ disabled: disabled,
2092
+ name: name,
2093
+ value: value,
2094
+ onValueChange: handleChoiceValueChange
2095
+ }), {}, {
2096
+ className: classnames("neeto-form-engine-choices", {
2097
+ "neeto-form-engine-choices--picture": isPictureChoice
2098
+ }),
2099
+ children: options.map(function (option, index) {
2100
+ var _value$index, _option$image;
2101
+ var isChecked = isCheckBox ? (_value$index = value === null || value === void 0 ? void 0 : value[index]) !== null && _value$index !== void 0 ? _value$index : false : value === option.id;
2102
+ return /*#__PURE__*/jsxs("label", {
2103
+ htmlFor: option.id,
2104
+ className: classnames("neeto-form-engine-choice", {
2105
+ "neeto-form-engine-choice--picture": isPictureChoice,
2106
+ "neeto-form-engine-choice--selected": isChecked,
2107
+ "cursor-not-allowed": disabled
2108
+ }),
2109
+ onClick: function onClick(event) {
2110
+ return handleChoiceClick(event, option.id);
2111
+ },
2112
+ children: [isPictureChoice && /*#__PURE__*/jsx(ChoiceImage, {
2113
+ shouldFitImages: shouldFitImages,
2114
+ alt: option.label,
2115
+ height: imageHeight,
2116
+ src: (_option$image = option.image) === null || _option$image === void 0 ? void 0 : _option$image.url
2117
+ }), isCheckBox ? /*#__PURE__*/jsx(Checkbox, {
2118
+ disabled: disabled,
2119
+ checked: isChecked,
2120
+ className: classnames({
2121
+ "cursor-not-allowed": disabled
2122
+ }),
2123
+ id: option.id,
2124
+ label: option.label,
2125
+ name: "".concat(name, ".").concat(index),
2126
+ value: option.id,
2127
+ labelProps: {
2128
+ className: classnames({
2129
+ "cursor-not-allowed": disabled
2130
+ })
2131
+ },
2132
+ onKeyDown: function onKeyDown(event) {
2133
+ return handleChoiceKeyDown(event, option.id);
2134
+ },
2135
+ onCheckedChange: function onCheckedChange(checked) {
2136
+ return onChange({
2137
+ target: {
2138
+ name: "".concat(name, ".").concat(index),
2139
+ checked: checked
2140
+ }
2141
+ });
2142
+ }
2143
+ }) : /*#__PURE__*/jsx(RadioGroup.Item, {
2144
+ disabled: disabled,
2145
+ className: classnames({
2146
+ "cursor-not-allowed": disabled
2147
+ }),
2148
+ id: option.id,
2149
+ label: option.label,
2150
+ value: option.id,
2151
+ labelProps: {
2152
+ className: classnames({
2153
+ "cursor-not-allowed": disabled
2154
+ })
2155
+ },
2156
+ onKeyDown: function onKeyDown(event) {
2157
+ return handleChoiceKeyDown(event, option.id);
2158
+ }
2159
+ })]
2160
+ }, option.id);
2161
+ })
2162
+ })), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2163
+ className: "neeto-form-engine-input__error",
2164
+ "data-testid": "neeto-form-engine-".concat(type, "-error"),
2165
+ children: error
2166
+ })]
2167
+ });
2168
+ };
2169
+ var Choices = /*#__PURE__*/memo(Choices$1);
2170
+
2171
+ function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2172
+ function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2173
+ var OptionsField = function OptionsField(_ref) {
2174
+ var question = _ref.question,
2175
+ customValidator = _ref.customValidator,
2176
+ isLastFewElements = _ref.isLastFewElements;
2177
+ var _useFormikContext = useFormikContext(),
2178
+ setFieldTouched = _useFormikContext.setFieldTouched,
2179
+ setFieldValue = _useFormikContext.setFieldValue,
2180
+ validateField = _useFormikContext.validateField;
2181
+ var name = question.id,
2182
+ kind = question.kind,
2183
+ isRequired = question.isRequired,
2184
+ isReadOnly = question.isReadOnly,
2185
+ isPictureChoiceFromQuestion = question.isPictureChoice,
2186
+ imageHeight = question.imageHeight,
2187
+ shouldFitImages = question.shouldFitImages,
2188
+ _question$optionsAttr = question.optionsAttributes,
2189
+ options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
2190
+ var isPictureChoice = isPictureChoiceFromQuestion;
2191
+ var isDropdown = kind === QUESTION_KIND.DROPDOWN.value;
2192
+ var label = fieldWithFallback(question, "label");
2193
+ var Component = isDropdown ? Select : Choices;
2194
+ var transformedOptions = isDropdown ? options.map(function (option) {
2195
+ return {
2196
+ label: fieldWithFallback(option, "label"),
2197
+ position: option.position,
2198
+ value: option.id
2199
+ };
2200
+ }) : options.map(function (option) {
2201
+ return _objectSpread$8(_objectSpread$8({}, option), {}, {
2202
+ label: fieldWithFallback(option, "label")
2203
+ });
2204
+ });
2205
+ var handleSelect = function handleSelect(option) {
2206
+ setFieldValue(name, option === null || option === void 0 ? void 0 : option.value, false);
2207
+ setFieldTouched(name, true, false);
2208
+ setTimeout(function () {
2209
+ return validateField(name);
2210
+ });
2211
+ };
2212
+ var handleValueChange = function handleValueChange(updatedValue) {
2213
+ setFieldValue(name, updatedValue, false);
2214
+ setFieldTouched(name, true, false);
2215
+ setTimeout(function () {
2216
+ return validateField(name);
2217
+ });
2218
+ };
2219
+ var customFilter = function customFilter(option, inputValue) {
2220
+ if (!option) return false;
2221
+ return containsIgnoreCase(option.label, inputValue);
2222
+ };
2223
+ return /*#__PURE__*/jsx(Field$1, {
2224
+ name: name,
2225
+ validate: validateFieldValue({
2226
+ kind: kind,
2227
+ label: label,
2228
+ isRequired: isRequired,
2229
+ customValidator: customValidator
2230
+ }),
2231
+ children: function children(_ref2) {
2232
+ var meta = _ref2.meta,
2233
+ field = _ref2.field;
2234
+ var onChange = field.onChange,
2235
+ value = field.value;
2236
+ return /*#__PURE__*/jsx(Component, _objectSpread$8(_objectSpread$8({
2237
+ error: getError(meta),
2238
+ isDisabled: isReadOnly,
2239
+ label: getLabel(label, isRequired),
2240
+ options: transformedOptions,
2241
+ strategy: "fixed",
2242
+ type: kind
2243
+ }, _objectSpread$8(_objectSpread$8({
2244
+ isRequired: isRequired,
2245
+ name: name
2246
+ }, isDropdown && {
2247
+ filterOption: customFilter
2248
+ }), !isDropdown && {
2249
+ imageHeight: imageHeight,
2250
+ isPictureChoice: isPictureChoice,
2251
+ shouldFitImages: shouldFitImages
2252
+ })), {}, {
2253
+ value: isDropdown ? findBy({
2254
+ value: value
2255
+ }, transformedOptions) || null : value,
2256
+ onChange: isDropdown ? handleSelect : onChange,
2257
+ onValueChange: !isDropdown ? handleValueChange : undefined
2258
+ }, isDropdown && {
2259
+ isClearable: true,
2260
+ menuPlacement: isLastFewElements ? "top" : "auto",
2261
+ menuPortalTarget: document.body,
2262
+ menuPosition: "fixed"
2263
+ }));
2264
+ }
2265
+ });
2266
+ };
2267
+
2268
+ var PhoneNumberField = function PhoneNumberField(_ref) {
2269
+ var _getPhoneData;
2270
+ var question = _ref.question,
2271
+ autoComplete = _ref.autoComplete,
2272
+ isLastFewElements = _ref.isLastFewElements;
2273
+ var name = question.id,
2274
+ kind = question.kind,
2275
+ isRequired = question.isRequired,
2276
+ nodeId = question.nodeId,
2277
+ isReadOnly = question.isReadOnly;
2278
+ var label = fieldWithFallback(question, "label");
2279
+ var _useField = useField({
2280
+ name: name || nodeId,
2281
+ validate: validateFieldValue({
2282
+ kind: kind,
2283
+ label: label,
2284
+ isRequired: isRequired
2285
+ })
2286
+ }),
2287
+ _useField2 = _slicedToArray(_useField, 3),
2288
+ value = _useField2[0].value,
2289
+ _useField2$ = _useField2[1],
2290
+ touched = _useField2$.touched,
2291
+ error = _useField2$.error,
2292
+ _useField2$2 = _useField2[2],
2293
+ setValue = _useField2$2.setValue,
2294
+ setTouched = _useField2$2.setTouched;
2295
+ return /*#__PURE__*/jsx(PhoneNumberInput, {
2296
+ autoComplete: autoComplete,
2297
+ label: label,
2298
+ value: value,
2299
+ className: "neeto-form-engine-input__wrapper items-stretch",
2300
+ disabled: isReadOnly,
2301
+ error: touched ? error : "",
2302
+ initialCountryCode: (_getPhoneData = getPhoneData(value)) === null || _getPhoneData === void 0 ? void 0 : _getPhoneData.country,
2303
+ placeholder: fieldWithFallback(question, "placeholder"),
2304
+ required: isRequired,
2305
+ selectProps: {
2306
+ isDisabled: isReadOnly,
2307
+ menuPlacement: isLastFewElements ? "top" : "auto",
2308
+ menuPortalTarget: document.body,
2309
+ menuPosition: "fixed"
2310
+ },
2311
+ onBlur: function onBlur() {
2312
+ return setTouched(true);
2313
+ },
2314
+ onChange: setValue
2315
+ });
2316
+ };
2317
+
2318
+ var _excluded$2 = ["name", "label", "error", "lowestRatingLabel", "averageRatingLabel", "highestRatingLabel", "value", "disabled"];
2319
+ function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2320
+ function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2321
+ var Rating$1 = function Rating(_ref) {
2322
+ var name = _ref.name,
2323
+ label = _ref.label,
2324
+ error = _ref.error,
2325
+ lowestRatingLabel = _ref.lowestRatingLabel,
2326
+ averageRatingLabel = _ref.averageRatingLabel,
2327
+ highestRatingLabel = _ref.highestRatingLabel,
2328
+ value = _ref.value,
2329
+ disabled = _ref.disabled,
2330
+ other = _objectWithoutProperties(_ref, _excluded$2);
2331
+ var handleClick = function handleClick(e) {
2332
+ return e.currentTarget.nextElementSibling.click();
2333
+ };
2334
+ var render = function render() {
2335
+ var labels = [highestRatingLabel, averageRatingLabel, lowestRatingLabel];
2336
+ return RATING_OPTIONS.map(function (_ref2, index) {
2337
+ var Icon = _ref2.icon,
2338
+ modifier = _ref2.modifier,
2339
+ rating = _ref2.value;
2340
+ return /*#__PURE__*/jsxs(Fragment$1, {
2341
+ children: [/*#__PURE__*/jsxs("button", {
2342
+ disabled: disabled,
2343
+ type: "button",
2344
+ className: classnames("neeto-form-engine-rating__item neeto-form-engine-rating__item--".concat(modifier), {
2345
+ active: rating === value
2346
+ }),
2347
+ onClick: handleClick,
2348
+ children: [/*#__PURE__*/jsx(Icon, {}), /*#__PURE__*/jsx("label", {
2349
+ className: "neeto-form-engine-label",
2350
+ children: labels[index]
2351
+ })]
2352
+ }), /*#__PURE__*/jsx("input", _objectSpread$7({
2353
+ name: name,
2354
+ hidden: true,
2355
+ checked: rating === value,
2356
+ type: "radio",
2357
+ value: rating
2358
+ }, other))]
2359
+ }, rating);
2360
+ });
2361
+ };
2362
+ return /*#__PURE__*/jsxs("div", {
2363
+ className: "neeto-form-engine-rating",
2364
+ children: [/*#__PURE__*/jsx("label", {
2365
+ className: "neeto-form-engine-label",
2366
+ "data-testid": "rating-input-label",
2367
+ children: label
2368
+ }), /*#__PURE__*/jsx("div", {
2369
+ className: "neeto-form-engine-rating__row",
2370
+ "data-testid": "rating-input-field",
2371
+ children: render()
2372
+ }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2373
+ className: "neeto-form-engine-input__error",
2374
+ "data-testid": "neeto-form-engine-rating-error",
2375
+ children: error
2376
+ })]
2377
+ });
2378
+ };
2379
+ var Rating = /*#__PURE__*/memo(Rating$1);
2380
+
2381
+ function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2382
+ function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2383
+ var RatingField = function RatingField(_ref) {
2384
+ var question = _ref.question,
2385
+ customValidator = _ref.customValidator;
2386
+ var name = question.id,
2387
+ kind = question.kind,
2388
+ isRequired = question.isRequired,
2389
+ isReadOnly = question.isReadOnly;
2390
+ var label = fieldWithFallback(question, "label");
2391
+ return /*#__PURE__*/jsx(Field$1, {
2392
+ name: name,
2393
+ validate: validateFieldValue({
2394
+ kind: kind,
2395
+ label: label,
2396
+ isRequired: isRequired,
2397
+ customValidator: customValidator
2398
+ }),
2399
+ children: function children(_ref2) {
2400
+ var meta = _ref2.meta,
2401
+ field = _ref2.field;
2402
+ return /*#__PURE__*/jsx(Rating, _objectSpread$6(_objectSpread$6({}, field), {}, {
2403
+ disabled: isReadOnly,
2404
+ error: meta.touched ? meta.error : "",
2405
+ label: getLabel(label, isRequired),
2406
+ averageRatingLabel: fieldWithFallback(question, "averageRatingLabel") || RATING_VALUES.AVERAGE.label,
2407
+ highestRatingLabel: fieldWithFallback(question, "highestRatingLabel") || RATING_VALUES.GOOD.label,
2408
+ lowestRatingLabel: fieldWithFallback(question, "lowestRatingLabel") || RATING_VALUES.BAD.label
2409
+ }));
2410
+ }
2411
+ });
2412
+ };
2413
+
2414
+ function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2415
+ function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2416
+ var RichTextEditor = function RichTextEditor(_ref) {
2417
+ var editorRef = _ref.editorRef,
2418
+ question = _ref.question,
2419
+ _ref$editorProps = _ref.editorProps,
2420
+ editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps;
2421
+ var _useFormikContext = useFormikContext(),
2422
+ errors = _useFormikContext.errors,
2423
+ touched = _useFormikContext.touched;
2424
+ var name = question.id,
2425
+ kind = question.kind,
2426
+ isRequired = question.isRequired,
2427
+ nodeId = question.nodeId,
2428
+ isReadOnly = question.isReadOnly;
2429
+ var label = fieldWithFallback(question, "label");
2430
+ var debouncedPlaceholder = useDebounce(fieldWithFallback(question, "placeholder"), 300);
2431
+ useEffect(function () {
2432
+ var _editorRef$current, _editorRef$current$se;
2433
+ editorRef === null || editorRef === void 0 || (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || (_editorRef$current = _editorRef$current.editor) === null || _editorRef$current === void 0 || (_editorRef$current$se = _editorRef$current.setEditable) === null || _editorRef$current$se === void 0 || _editorRef$current$se.call(_editorRef$current, !isReadOnly);
2434
+ }, [editorRef === null || editorRef === void 0 ? void 0 : editorRef.current, isReadOnly]);
2435
+ var propsToCompare = ["debouncedPlaceholder", "error", "touched", "isReadOnly"];
2436
+ return /*#__PURE__*/jsxs("div", {
2437
+ className: "neeto-form-engine-input__wrapper",
2438
+ children: [/*#__PURE__*/jsx("div", {
2439
+ className: "neeto-form-engine-input__label-wrapper",
2440
+ children: label && /*#__PURE__*/jsx("label", {
2441
+ className: "neeto-form-engine-label",
2442
+ "data-testid": "".concat(hyphenate(label), "-input-label"),
2443
+ children: getLabel(label, isRequired)
2444
+ })
2445
+ }), /*#__PURE__*/jsx(FastField, {
2446
+ debouncedPlaceholder: debouncedPlaceholder,
2447
+ isReadOnly: isReadOnly,
2448
+ error: errors[name],
2449
+ name: name || nodeId,
2450
+ shouldUpdate: isPropsUnequal(propsToCompare),
2451
+ touched: touched[name],
2452
+ validate: validateFieldValue({
2453
+ kind: kind,
2454
+ label: label,
2455
+ isRequired: isRequired
2456
+ }),
2457
+ children: function children(_ref2) {
2458
+ var field = _ref2.field,
2459
+ form = _ref2.form,
2460
+ meta = _ref2.meta;
2461
+ return /*#__PURE__*/jsx(NeetoEditor, _objectSpread$5({
2462
+ editable: isReadOnly,
2463
+ error: meta.touched ? meta.error : "",
2464
+ initialValue: field.value,
2465
+ menuType: isReadOnly ? "bubble" : "fixed",
2466
+ placeholder: debouncedPlaceholder,
2467
+ ref: editorRef,
2468
+ addons: isReadOnly ? [] : ["attachments", "block-quote", "code-block", "image-upload"],
2469
+ className: classnames("neeto-form-engine-rich-text-input", {
2470
+ "cursor-not-allowed border": isReadOnly
2471
+ }),
2472
+ onBlur: function onBlur() {
2473
+ return form.setFieldTouched(name, true);
2474
+ },
2475
+ onChange: function onChange(value) {
2476
+ return form.setFieldValue(name, value);
2477
+ }
2478
+ }, editorProps), debouncedPlaceholder);
2479
+ }
2480
+ })]
2481
+ });
2482
+ };
2483
+
2484
+ var _excluded$1 = ["value", "iconType", "label", "rating"];
2485
+ function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2486
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2487
+ var RatingButton$1 = function RatingButton(_ref) {
2488
+ var _ref$value = _ref.value,
2489
+ value = _ref$value === void 0 ? 0 : _ref$value,
2490
+ iconType = _ref.iconType,
2491
+ label = _ref.label,
2492
+ rating = _ref.rating,
2493
+ otherProps = _objectWithoutProperties(_ref, _excluded$1);
2494
+ var handleClick = function handleClick(e) {
2495
+ return e.currentTarget.nextElementSibling.click();
2496
+ };
2497
+ var Icon = ICONS_MAP[iconType];
2498
+ var selectedRating = getSelectedRating(value);
2499
+ return /*#__PURE__*/jsxs(Fragment, {
2500
+ children: [/*#__PURE__*/jsxs("button", {
2501
+ className: classnames({
2502
+ active: rating === value
2503
+ }),
2504
+ disabled: otherProps === null || otherProps === void 0 ? void 0 : otherProps.disabled,
2505
+ type: "button",
2506
+ onClick: handleClick,
2507
+ children: [/*#__PURE__*/jsx(Icon, {
2508
+ size: 24,
2509
+ className: classnames("neeto-form-engine-star-rating__icon", {
2510
+ "neeto-form-engine-star-rating__icon--active": rating <= selectedRating
2511
+ })
2512
+ }), /*#__PURE__*/jsx("label", {
2513
+ className: "neeto-form-engine-label",
2514
+ children: label
2515
+ })]
2516
+ }), /*#__PURE__*/jsx("input", _objectSpread$4({
2517
+ hidden: true,
2518
+ checked: equals(rating, value),
2519
+ type: "radio",
2520
+ value: rating
2521
+ }, otherProps))]
2522
+ });
2523
+ };
2524
+ var RatingButton = /*#__PURE__*/memo(RatingButton$1);
2525
+
2526
+ var _excluded = ["label", "minValue", "maxValue", "error"];
2527
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2528
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2529
+ var StarRating$1 = function StarRating(_ref) {
2530
+ var label = _ref.label,
2531
+ minValue = _ref.minValue,
2532
+ maxValue = _ref.maxValue,
2533
+ error = _ref.error,
2534
+ props = _objectWithoutProperties(_ref, _excluded);
2535
+ return /*#__PURE__*/jsxs("div", {
2536
+ className: "neeto-form-engine-input__wrapper neeto-form-engine-star-rating",
2537
+ children: [/*#__PURE__*/jsx("div", {
2538
+ className: "neeto-form-engine-input__label-wrapper",
2539
+ children: /*#__PURE__*/jsx("label", {
2540
+ className: "neeto-form-engine-label",
2541
+ "data-testid": "star-rating-input-label",
2542
+ children: label
2543
+ })
2544
+ }), /*#__PURE__*/jsx("div", {
2545
+ className: "neeto-form-engine-star-rating__row",
2546
+ "data-testid": "star-rating-input-field",
2547
+ children: generateArray(minValue, maxValue).map(function (index) {
2548
+ return /*#__PURE__*/jsx(RatingButton, _objectSpread$3({
2549
+ label: index,
2550
+ rating: index
2551
+ }, props), index);
2552
+ })
2553
+ }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2554
+ className: "neeto-form-engine-input__error",
2555
+ "data-testid": "neeto-form-engine-star-rating-error",
2556
+ children: error
2557
+ })]
2558
+ });
2559
+ };
2560
+ var StarRating = /*#__PURE__*/memo(StarRating$1);
2561
+
2562
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2563
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2564
+ var StarRatingField = function StarRatingField(_ref) {
2565
+ var question = _ref.question,
2566
+ customValidator = _ref.customValidator;
2567
+ var name = question.id,
2568
+ kind = question.kind,
2569
+ isRequired = question.isRequired,
2570
+ minValue = question.minValue,
2571
+ maxValue = question.maxValue,
2572
+ iconType = question.iconType,
2573
+ isReadOnly = question.isReadOnly;
2574
+ var label = fieldWithFallback(question, "label");
2575
+ return /*#__PURE__*/jsx(Field$1, {
2576
+ name: name,
2577
+ validate: validateFieldValue({
2578
+ kind: kind,
2579
+ label: label,
2580
+ isRequired: isRequired,
2581
+ customValidator: customValidator
2582
+ }),
2583
+ children: function children(_ref2) {
2584
+ var meta = _ref2.meta,
2585
+ field = _ref2.field;
2586
+ return /*#__PURE__*/jsx(StarRating, _objectSpread$2({
2587
+ iconType: iconType,
2588
+ maxValue: maxValue,
2589
+ minValue: minValue,
2590
+ name: name,
2591
+ disabled: isReadOnly,
2592
+ error: meta.touched ? meta.error : "",
2593
+ label: getLabel(label, isRequired)
2594
+ }, field));
2595
+ }
2596
+ });
2597
+ };
2598
+
2599
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2600
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2601
+ var TermsField = function TermsField(_ref) {
2602
+ var question = _ref.question,
2603
+ customValidator = _ref.customValidator;
2604
+ var name = question.id,
2605
+ kind = question.kind,
2606
+ isRequired = question.isRequired,
2607
+ nodeId = question.nodeId;
2608
+ var label = fieldWithFallback(question, "label", true);
2609
+ return /*#__PURE__*/jsx(Field$1, {
2610
+ name: name || nodeId,
2611
+ validate: validateFieldValue({
2612
+ kind: kind,
2613
+ label: label,
2614
+ isRequired: isRequired,
2615
+ customValidator: customValidator
2616
+ }),
2617
+ children: function children(_ref2) {
2618
+ var meta = _ref2.meta,
2619
+ field = _ref2.field,
2620
+ form = _ref2.form;
2621
+ return /*#__PURE__*/jsx("div", {
2622
+ className: "neeto-form-engine-terms",
2623
+ children: /*#__PURE__*/jsx(Checkbox, _objectSpread$1(_objectSpread$1({}, _objectSpread$1(_objectSpread$1({}, field), {}, {
2624
+ name: name
2625
+ })), {}, {
2626
+ checked: field.value,
2627
+ error: meta.touched ? meta.error : "",
2628
+ label: /*#__PURE__*/jsx(EditorContent, {
2629
+ content: label
2630
+ }),
2631
+ onCheckedChange: function onCheckedChange(checked) {
2632
+ return form.setFieldValue(name, checked);
2633
+ }
2634
+ }))
2635
+ });
2636
+ }
2637
+ });
2638
+ };
2639
+
2640
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2641
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2642
+ var TextField = function TextField(_ref) {
2643
+ var _otherProps$onChange;
2644
+ var question = _ref.question,
2645
+ customValidator = _ref.customValidator,
2646
+ autoComplete = _ref.autoComplete,
2647
+ remainingSlotsCount = _ref.remainingSlotsCount;
2648
+ var _useTranslation = useTranslation(),
2649
+ t = _useTranslation.t;
2650
+ var name = question.id,
2651
+ kind = question.kind,
2652
+ isRequired = question.isRequired,
2653
+ isReadOnly = question.isReadOnly,
2654
+ nodeId = question.nodeId,
2655
+ minWords = question.minWords;
2656
+ var label = fieldWithFallback(question, "label");
2657
+ var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()],
2658
+ _QUESTION_KIND$kind$t2 = _QUESTION_KIND$kind$t.type,
2659
+ type = _QUESTION_KIND$kind$t2 === void 0 ? "text" : _QUESTION_KIND$kind$t2,
2660
+ onKeyDown = _QUESTION_KIND$kind$t.onKeyDown,
2661
+ otherProps = _QUESTION_KIND$kind$t.otherProps;
2662
+ var Component = kind === QUESTION_KIND.TEXTAREA.value ? Textarea : Input;
2663
+ var _useField = useField({
2664
+ name: name || nodeId,
2665
+ validate: validateFieldValue({
2666
+ kind: kind,
2667
+ label: label,
2668
+ isRequired: isRequired,
2669
+ minWords: minWords,
2670
+ customValidator: customValidator,
2671
+ remainingSlotsCount: remainingSlotsCount
2672
+ })
2673
+ }),
2674
+ _useField2 = _slicedToArray(_useField, 3),
2675
+ field = _useField2[0],
2676
+ _useField2$ = _useField2[1],
2677
+ touched = _useField2$.touched,
2678
+ error = _useField2$.error,
2679
+ _useField2$2 = _useField2[2],
2680
+ setValue = _useField2$2.setValue,
2681
+ setTouched = _useField2$2.setTouched;
2682
+ var handleFieldChange = withEventTargetValue(setValue);
2683
+ return /*#__PURE__*/jsxs("div", {
2684
+ className: "w-full flex flex-col gap-2",
2685
+ children: [/*#__PURE__*/jsx(Component, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({
2686
+ type: type
2687
+ }, field), {}, {
2688
+ autoComplete: autoComplete,
2689
+ label: label,
2690
+ onKeyDown: onKeyDown
2691
+ }, kind === QUESTION_KIND.SPOT.value && _objectSpread({
2692
+ min: 1
2693
+ }, typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && {
2694
+ max: remainingSlotsCount
2695
+ }))), {}, {
2696
+ disabled: isReadOnly,
2697
+ error: touched ? error : "",
2698
+ name: slugify(label),
2699
+ placeholder: fieldWithFallback(question, "placeholder"),
2700
+ required: isRequired,
2701
+ onBlur: function onBlur() {
2702
+ return setTouched(true);
2703
+ },
2704
+ onChange: (_otherProps$onChange = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onChange(handleFieldChange)) !== null && _otherProps$onChange !== void 0 ? _otherProps$onChange : handleFieldChange
2705
+ })), kind === QUESTION_KIND.SPOT.value && typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && /*#__PURE__*/jsx("div", {
2706
+ className: "flex justify-end",
2707
+ children: /*#__PURE__*/jsx(Badge, {
2708
+ icon: Info,
2709
+ variant: "blue",
2710
+ label: t("neetoForm.questions.spot.remainingSlotsCount", {
2711
+ count: remainingSlotsCount
2712
+ })
2713
+ })
2714
+ })]
2715
+ });
2716
+ };
2717
+
2718
+ var _QUESTION_TO_COMPONEN;
2719
+ var QUESTION_TO_COMPONENT_MAP = (_QUESTION_TO_COMPONEN = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXT.value, TextField), QUESTION_KIND.NAME.value, NameField), QUESTION_KIND.EMAIL.value, EmailField), QUESTION_KIND.INTEGER.value, TextField), QUESTION_KIND.DECIMAL.value, TextField), QUESTION_KIND.PHONE.value, PhoneNumberField), QUESTION_KIND.QUESTION.value, TextField), QUESTION_KIND.TEXTAREA.value, TextField), QUESTION_KIND.CHECKBOX.value, OptionsField), QUESTION_KIND.RADIO.value, OptionsField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.DROPDOWN.value, OptionsField), QUESTION_KIND.RATING.value, RatingField), QUESTION_KIND.PARAGRAPH.value, function (_ref) {
2720
+ var question = _ref.question;
2721
+ return /*#__PURE__*/jsx(EditorContent, {
2722
+ content: fieldWithFallback(question, "label", true)
2723
+ });
2724
+ }), QUESTION_KIND.TERMS.value, TermsField), QUESTION_KIND.DATE.value, DateField), QUESTION_KIND.STAR_RATING.value, StarRatingField), QUESTION_KIND.OPINION_SCALE.value, OpinionScaleField), QUESTION_KIND.ADDITIONAL_GUESTS.value, MultipleEmailInput), QUESTION_KIND.RICH_TEXT.value, RichTextEditor), QUESTION_KIND.CONDITION.value, ConditionField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.FILE_UPLOAD.value, FileUploadField), QUESTION_KIND.CAPTCHA.value, CaptchaField), QUESTION_KIND.SMS_REMINDER.value, PhoneNumberField), QUESTION_KIND.SPOT.value, TextField), QUESTION_KIND.ADDRESS.value, AddressField));
2725
+ var CAPTCHA_COMPONENT_MAP = _defineProperty(_defineProperty({}, CAPTCHA_TYPES.RECAPTCHA_V2, Recaptcha), CAPTCHA_TYPES.MATH_CAPTCHA, MathCaptcha);
2726
+
2727
+ var getFieldComponent = function getFieldComponent(_ref) {
2728
+ var kind = _ref.kind;
2729
+ if (kind in QUESTION_TO_COMPONENT_MAP) return QUESTION_TO_COMPONENT_MAP[kind];
2730
+ return function () {
2731
+ return null;
2732
+ };
2733
+ };
2734
+ var isPropsUnequal = function isPropsUnequal(props) {
2735
+ return function (nextProps, prevProps) {
2736
+ return notEqualsDeep(pick(props, nextProps), pick(props, prevProps));
2737
+ };
2738
+ };
2739
+ var getValidDate = function getValidDate(date) {
2740
+ if (!date) return "";
2741
+ return dayjs$1(date).isValid() ? dayjs$1(date) : "";
2742
+ };
2743
+ var getPhoneData = function getPhoneData(value, countryCode) {
2744
+ try {
2745
+ return parsePhoneNumber(value, countryCode);
2746
+ } catch (_unused) {
2747
+ return undefined;
2748
+ }
2749
+ };
2750
+ var containsIgnoreCase = function containsIgnoreCase(string, substring) {
2751
+ return string.toLowerCase().includes(substring.toLowerCase());
2752
+ };
2753
+ var getVisibleOptions = function getVisibleOptions(options) {
2754
+ return Array.isArray(options) ? options.filter(function (option) {
2755
+ return !option.deleted;
2756
+ }).sort(function (a, b) {
2757
+ return a.position - b.position;
2758
+ }) : [];
2759
+ };
2760
+
2761
+ export { FormikWrap as F, generateInitValues as a, buildAutoCompleteAttribute as b, clientI18nInstance$1 as c, getWithExpiry as d, clearEmailVerificationDetails as e, generateFormResponse as f, getFieldComponent as g, clearLocalStorageValues as h, mergeRefs as m, renderButtonsInOrder as r };
2762
+ //# sourceMappingURL=utils-wCXQvtSj.js.map