@bonlineza/luxity-lib 2.39.4 → 2.39.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/Accordion.js +342 -352
  2. package/AddInterest.js +3109 -3068
  3. package/AddProductInterest.js +999 -7572
  4. package/BrandSelector.js +854 -861
  5. package/Checkbox.js +240 -250
  6. package/CheckboxButton.js +229 -236
  7. package/CommunicationPreferenceOptionsRenderer.js +560 -568
  8. package/CommunicationPreferenceSection.js +651 -659
  9. package/CommunicationPreferences.js +2394 -2402
  10. package/ConditionSelector.js +852 -859
  11. package/CountryCodeSelect.js +79 -6650
  12. package/CurrencyInputFormatter.js +86 -96
  13. package/CurrencySelect.js +219 -227
  14. package/DropdownSelector.js +212 -6821
  15. package/GALink.js +43 -51
  16. package/GenderSelector.js +355 -362
  17. package/GraphQLDropdownSelector.js +5308 -11832
  18. package/GraphQLMultiSelector.js +593 -601
  19. package/IconHeader.js +118 -126
  20. package/IconWrapper.js +17 -25
  21. package/InterestCatSelector.js +424 -389
  22. package/InterestItem.js +462 -469
  23. package/Interests.js +4719 -11243
  24. package/InterestsSubheading.js +33 -41
  25. package/InvertedTextButton.js +167 -175
  26. package/LuxityAppSideNav.js +181 -189
  27. package/LuxityDesktopHeader.js +1355 -1363
  28. package/LuxityFooter.js +2228 -2236
  29. package/LuxityGraphQLDropdownSelector.js +5395 -11919
  30. package/LuxityGraphQLMultiselector.js +778 -785
  31. package/LuxityMobileHeader.js +1786 -1794
  32. package/LuxityPageReady.js +199 -209
  33. package/LuxityProductInterestItem.js +359 -367
  34. package/LuxitySideNav.js +665 -673
  35. package/MaterialSelector.js +5430 -11954
  36. package/ModelSelector.js +5430 -11954
  37. package/NotificationDropDown.js +459 -7030
  38. package/Notify.js +20 -32
  39. package/OutlinePrimaryButton.js +134 -142
  40. package/PriceRangeSelector.js +1264 -1265
  41. package/PrimaryButton.js +129 -137
  42. package/RadioButtons.js +308 -318
  43. package/RangeSlider.js +1033 -1039
  44. package/RareStepFooter.js +257 -264
  45. package/RareStepHeader.js +801 -808
  46. package/ReactSelectWrapper.js +33 -6604
  47. package/SecondaryButton.js +144 -152
  48. package/ShoeSizeRangeSelector.js +1147 -1153
  49. package/ShoeSizeSelector.js +1146 -1154
  50. package/SimpleErrorBoundary.js +130 -138
  51. package/StyleSelector.js +854 -861
  52. package/TestComponent.js +15 -0
  53. package/TextButton.js +135 -143
  54. package/Tooltip.js +176 -184
  55. package/Tracking.js +15 -25
  56. package/WrapperButton.js +50 -58
  57. package/build/CountryCodeSelect/index.js +18 -0
  58. package/build/ReactSelectWrapper/index.js +34 -0
  59. package/build/bundle.css +1 -1
  60. package/build/bundle.js +10634 -17192
  61. package/build/constants.js +32 -43
  62. package/package.json +2 -2
  63. package/postcss.config.js +6 -0
  64. package/svg/Accessories.js +34 -42
  65. package/svg/Account.js +30 -38
  66. package/svg/Add.js +31 -39
  67. package/svg/ArrowRight.js +28 -36
  68. package/svg/Bags.js +40 -48
  69. package/svg/BurgerMenu.js +24 -32
  70. package/svg/Calendar.js +98 -106
  71. package/svg/CalendarCircled.js +100 -108
  72. package/svg/CheckCircled.js +32 -40
  73. package/svg/Close.js +29 -37
  74. package/svg/Clothing.js +36 -44
  75. package/svg/Dot.js +32 -40
  76. package/svg/Edit.js +27 -35
  77. package/svg/Eye.js +28 -36
  78. package/svg/FileAttach.js +28 -36
  79. package/svg/FileAttachCircled.js +30 -38
  80. package/svg/Jewellery.js +56 -0
  81. package/svg/LightBulb.js +58 -66
  82. package/svg/Logo.js +132 -140
  83. package/svg/LuxityMenu.js +28 -36
  84. package/svg/Minus.js +29 -37
  85. package/svg/MobileAvatar.js +28 -36
  86. package/svg/MyOrder.js +36 -44
  87. package/svg/MyPayment.js +36 -44
  88. package/svg/MyProfile.js +44 -52
  89. package/svg/MySale.js +31 -39
  90. package/svg/Notification.js +30 -38
  91. package/svg/PointerDown.js +28 -36
  92. package/svg/Search.js +27 -35
  93. package/svg/Shoes.js +37 -45
  94. package/svg/SvgWrapper.js +13 -21
  95. package/svg/Trash.js +32 -40
  96. package/svg/Watches.js +47 -55
package/LuxityFooter.js CHANGED
@@ -1,2309 +1,2301 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('styled-components')) :
3
- typeof define === 'function' && define.amd ? define(['react', 'styled-components'], factory) :
4
- (global = global || self, global.LuxityFooter = factory(global.React, global.styled));
5
- }(this, (function (React, styled) { 'use strict';
6
-
7
- var React__default = 'default' in React ? React['default'] : React;
8
- var styled__default = 'default' in styled ? styled['default'] : styled;
9
-
10
- function _extends() {
11
- _extends = Object.assign ? Object.assign.bind() : function (target) {
12
- for (var i = 1; i < arguments.length; i++) {
13
- var source = arguments[i];
14
-
15
- for (var key in source) {
16
- if (Object.prototype.hasOwnProperty.call(source, key)) {
17
- target[key] = source[key];
18
- }
1
+ import React, { forwardRef, useState, useRef } from 'react';
2
+ import styled, { ThemeProvider, css } from 'styled-components';
3
+
4
+ function _extends() {
5
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
6
+ for (var i = 1; i < arguments.length; i++) {
7
+ var source = arguments[i];
8
+
9
+ for (var key in source) {
10
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
11
+ target[key] = source[key];
19
12
  }
20
13
  }
14
+ }
21
15
 
22
- return target;
23
- };
24
- return _extends.apply(this, arguments);
16
+ return target;
17
+ };
18
+ return _extends.apply(this, arguments);
19
+ }
20
+
21
+ function _taggedTemplateLiteral(strings, raw) {
22
+ if (!raw) {
23
+ raw = strings.slice(0);
25
24
  }
26
25
 
27
- function _taggedTemplateLiteral(strings, raw) {
28
- if (!raw) {
29
- raw = strings.slice(0);
26
+ return Object.freeze(Object.defineProperties(strings, {
27
+ raw: {
28
+ value: Object.freeze(raw)
30
29
  }
30
+ }));
31
+ }
31
32
 
32
- return Object.freeze(Object.defineProperties(strings, {
33
- raw: {
34
- value: Object.freeze(raw)
35
- }
36
- }));
37
- }
33
+ function _slicedToArray(arr, i) {
34
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
35
+ }
38
36
 
39
- function _slicedToArray(arr, i) {
40
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
41
- }
37
+ function _arrayWithHoles(arr) {
38
+ if (Array.isArray(arr)) return arr;
39
+ }
42
40
 
43
- function _arrayWithHoles(arr) {
44
- if (Array.isArray(arr)) return arr;
45
- }
41
+ function _iterableToArrayLimit(arr, i) {
42
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
46
43
 
47
- function _iterableToArrayLimit(arr, i) {
48
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
44
+ if (_i == null) return;
45
+ var _arr = [];
46
+ var _n = true;
47
+ var _d = false;
49
48
 
50
- if (_i == null) return;
51
- var _arr = [];
52
- var _n = true;
53
- var _d = false;
49
+ var _s, _e;
54
50
 
55
- var _s, _e;
51
+ try {
52
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
53
+ _arr.push(_s.value);
56
54
 
55
+ if (i && _arr.length === i) break;
56
+ }
57
+ } catch (err) {
58
+ _d = true;
59
+ _e = err;
60
+ } finally {
57
61
  try {
58
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
59
- _arr.push(_s.value);
60
-
61
- if (i && _arr.length === i) break;
62
- }
63
- } catch (err) {
64
- _d = true;
65
- _e = err;
62
+ if (!_n && _i["return"] != null) _i["return"]();
66
63
  } finally {
67
- try {
68
- if (!_n && _i["return"] != null) _i["return"]();
69
- } finally {
70
- if (_d) throw _e;
71
- }
64
+ if (_d) throw _e;
72
65
  }
73
-
74
- return _arr;
75
66
  }
76
67
 
77
- function _unsupportedIterableToArray(o, minLen) {
78
- if (!o) return;
79
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
80
- var n = Object.prototype.toString.call(o).slice(8, -1);
81
- if (n === "Object" && o.constructor) n = o.constructor.name;
82
- if (n === "Map" || n === "Set") return Array.from(o);
83
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
84
- }
68
+ return _arr;
69
+ }
85
70
 
86
- function _arrayLikeToArray(arr, len) {
87
- if (len == null || len > arr.length) len = arr.length;
71
+ function _unsupportedIterableToArray(o, minLen) {
72
+ if (!o) return;
73
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
74
+ var n = Object.prototype.toString.call(o).slice(8, -1);
75
+ if (n === "Object" && o.constructor) n = o.constructor.name;
76
+ if (n === "Map" || n === "Set") return Array.from(o);
77
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
78
+ }
88
79
 
89
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
80
+ function _arrayLikeToArray(arr, len) {
81
+ if (len == null || len > arr.length) len = arr.length;
90
82
 
91
- return arr2;
92
- }
83
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
93
84
 
94
- function _nonIterableRest() {
95
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
96
- }
85
+ return arr2;
86
+ }
97
87
 
98
- var isCheckBoxInput = (element) => element.type === 'checkbox';
88
+ function _nonIterableRest() {
89
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
90
+ }
99
91
 
100
- var isDateObject = (value) => value instanceof Date;
92
+ var isCheckBoxInput = (element) => element.type === 'checkbox';
101
93
 
102
- var isNullOrUndefined = (value) => value == null;
94
+ var isDateObject = (value) => value instanceof Date;
103
95
 
104
- const isObjectType = (value) => typeof value === 'object';
105
- var isObject = (value) => !isNullOrUndefined(value) &&
106
- !Array.isArray(value) &&
107
- isObjectType(value) &&
108
- !isDateObject(value);
96
+ var isNullOrUndefined = (value) => value == null;
109
97
 
110
- var getEventValue = (event) => isObject(event) && event.target
111
- ? isCheckBoxInput(event.target)
112
- ? event.target.checked
113
- : event.target.value
114
- : event;
98
+ const isObjectType = (value) => typeof value === 'object';
99
+ var isObject = (value) => !isNullOrUndefined(value) &&
100
+ !Array.isArray(value) &&
101
+ isObjectType(value) &&
102
+ !isDateObject(value);
115
103
 
116
- var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
104
+ var getEventValue = (event) => isObject(event) && event.target
105
+ ? isCheckBoxInput(event.target)
106
+ ? event.target.checked
107
+ : event.target.value
108
+ : event;
117
109
 
118
- var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
110
+ var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
119
111
 
120
- var isPlainObject = (tempObject) => {
121
- const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
122
- return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
123
- };
112
+ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
124
113
 
125
- var isWeb = typeof window !== 'undefined' &&
126
- typeof window.HTMLElement !== 'undefined' &&
127
- typeof document !== 'undefined';
114
+ var isPlainObject = (tempObject) => {
115
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
116
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
117
+ };
128
118
 
129
- function cloneObject(data) {
130
- let copy;
131
- const isArray = Array.isArray(data);
132
- if (data instanceof Date) {
133
- copy = new Date(data);
134
- }
135
- else if (data instanceof Set) {
136
- copy = new Set(data);
137
- }
138
- else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
139
- (isArray || isObject(data))) {
140
- copy = isArray ? [] : {};
141
- if (!isArray && !isPlainObject(data)) {
142
- copy = data;
143
- }
144
- else {
145
- for (const key in data) {
146
- if (data.hasOwnProperty(key)) {
147
- copy[key] = cloneObject(data[key]);
148
- }
149
- }
150
- }
151
- }
152
- else {
153
- return data;
154
- }
155
- return copy;
156
- }
119
+ var isWeb = typeof window !== 'undefined' &&
120
+ typeof window.HTMLElement !== 'undefined' &&
121
+ typeof document !== 'undefined';
157
122
 
158
- var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
123
+ function cloneObject(data) {
124
+ let copy;
125
+ const isArray = Array.isArray(data);
126
+ if (data instanceof Date) {
127
+ copy = new Date(data);
128
+ }
129
+ else if (data instanceof Set) {
130
+ copy = new Set(data);
131
+ }
132
+ else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
133
+ (isArray || isObject(data))) {
134
+ copy = isArray ? [] : {};
135
+ if (!isArray && !isPlainObject(data)) {
136
+ copy = data;
137
+ }
138
+ else {
139
+ for (const key in data) {
140
+ if (data.hasOwnProperty(key)) {
141
+ copy[key] = cloneObject(data[key]);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ else {
147
+ return data;
148
+ }
149
+ return copy;
150
+ }
159
151
 
160
- var isUndefined = (val) => val === undefined;
152
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
161
153
 
162
- var get = (obj, path, defaultValue) => {
163
- if (!path || !isObject(obj)) {
164
- return defaultValue;
165
- }
166
- const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);
167
- return isUndefined(result) || result === obj
168
- ? isUndefined(obj[path])
169
- ? defaultValue
170
- : obj[path]
171
- : result;
172
- };
154
+ var isUndefined = (val) => val === undefined;
173
155
 
174
- const EVENTS = {
175
- BLUR: 'blur',
176
- FOCUS_OUT: 'focusout',
177
- CHANGE: 'change',
178
- };
179
- const VALIDATION_MODE = {
180
- onBlur: 'onBlur',
181
- onChange: 'onChange',
182
- onSubmit: 'onSubmit',
183
- onTouched: 'onTouched',
184
- all: 'all',
185
- };
186
- const INPUT_VALIDATION_RULES = {
187
- max: 'max',
188
- min: 'min',
189
- maxLength: 'maxLength',
190
- minLength: 'minLength',
191
- pattern: 'pattern',
192
- required: 'required',
193
- validate: 'validate',
194
- };
156
+ var get = (obj, path, defaultValue) => {
157
+ if (!path || !isObject(obj)) {
158
+ return defaultValue;
159
+ }
160
+ const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], obj);
161
+ return isUndefined(result) || result === obj
162
+ ? isUndefined(obj[path])
163
+ ? defaultValue
164
+ : obj[path]
165
+ : result;
166
+ };
167
+
168
+ const EVENTS = {
169
+ BLUR: 'blur',
170
+ FOCUS_OUT: 'focusout',
171
+ CHANGE: 'change',
172
+ };
173
+ const VALIDATION_MODE = {
174
+ onBlur: 'onBlur',
175
+ onChange: 'onChange',
176
+ onSubmit: 'onSubmit',
177
+ onTouched: 'onTouched',
178
+ all: 'all',
179
+ };
180
+ const INPUT_VALIDATION_RULES = {
181
+ max: 'max',
182
+ min: 'min',
183
+ maxLength: 'maxLength',
184
+ minLength: 'minLength',
185
+ pattern: 'pattern',
186
+ required: 'required',
187
+ validate: 'validate',
188
+ };
189
+
190
+ const HookFormContext = React.createContext(null);
191
+
192
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
193
+ const result = {
194
+ defaultValues: control._defaultValues,
195
+ };
196
+ for (const key in formState) {
197
+ Object.defineProperty(result, key, {
198
+ get: () => {
199
+ const _key = key;
200
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
201
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
202
+ }
203
+ localProxyFormState && (localProxyFormState[_key] = true);
204
+ return formState[_key];
205
+ },
206
+ });
207
+ }
208
+ return result;
209
+ };
210
+
211
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
212
+
213
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
214
+ updateFormState(formStateData);
215
+ const { name, ...formState } = formStateData;
216
+ return (isEmptyObject(formState) ||
217
+ Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
218
+ Object.keys(formState).find((key) => _proxyFormState[key] ===
219
+ (!isRoot || VALIDATION_MODE.all)));
220
+ };
221
+
222
+ var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
223
+
224
+ function useSubscribe(props) {
225
+ const _props = React.useRef(props);
226
+ _props.current = props;
227
+ React.useEffect(() => {
228
+ const subscription = !props.disabled &&
229
+ _props.current.subject &&
230
+ _props.current.subject.subscribe({
231
+ next: _props.current.next,
232
+ });
233
+ return () => {
234
+ subscription && subscription.unsubscribe();
235
+ };
236
+ }, [props.disabled]);
237
+ }
238
+
239
+ var isString = (value) => typeof value === 'string';
240
+
241
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
242
+ if (isString(names)) {
243
+ isGlobal && _names.watch.add(names);
244
+ return get(formValues, names, defaultValue);
245
+ }
246
+ if (Array.isArray(names)) {
247
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
248
+ }
249
+ isGlobal && (_names.watchAll = true);
250
+ return formValues;
251
+ };
252
+
253
+ var isKey = (value) => /^\w*$/.test(value);
254
+
255
+ var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
256
+
257
+ function set(object, path, value) {
258
+ let index = -1;
259
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
260
+ const length = tempPath.length;
261
+ const lastIndex = length - 1;
262
+ while (++index < length) {
263
+ const key = tempPath[index];
264
+ let newValue = value;
265
+ if (index !== lastIndex) {
266
+ const objValue = object[key];
267
+ newValue =
268
+ isObject(objValue) || Array.isArray(objValue)
269
+ ? objValue
270
+ : !isNaN(+tempPath[index + 1])
271
+ ? []
272
+ : {};
273
+ }
274
+ object[key] = newValue;
275
+ object = object[key];
276
+ }
277
+ return object;
278
+ }
279
+
280
+ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
281
+ ? {
282
+ ...errors[name],
283
+ types: {
284
+ ...(errors[name] && errors[name].types ? errors[name].types : {}),
285
+ [type]: message || true,
286
+ },
287
+ }
288
+ : {};
289
+
290
+ const focusFieldBy = (fields, callback, fieldsNames) => {
291
+ for (const key of fieldsNames || Object.keys(fields)) {
292
+ const field = get(fields, key);
293
+ if (field) {
294
+ const { _f, ...currentField } = field;
295
+ if (_f && callback(_f.name)) {
296
+ if (_f.ref.focus) {
297
+ _f.ref.focus();
298
+ break;
299
+ }
300
+ else if (_f.refs && _f.refs[0].focus) {
301
+ _f.refs[0].focus();
302
+ break;
303
+ }
304
+ }
305
+ else if (isObject(currentField)) {
306
+ focusFieldBy(currentField, callback);
307
+ }
308
+ }
309
+ }
310
+ };
311
+
312
+ var getValidationModes = (mode) => ({
313
+ isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
314
+ isOnBlur: mode === VALIDATION_MODE.onBlur,
315
+ isOnChange: mode === VALIDATION_MODE.onChange,
316
+ isOnAll: mode === VALIDATION_MODE.all,
317
+ isOnTouch: mode === VALIDATION_MODE.onTouched,
318
+ });
319
+
320
+ var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
321
+ (_names.watchAll ||
322
+ _names.watch.has(name) ||
323
+ [..._names.watch].some((watchName) => name.startsWith(watchName) &&
324
+ /^\.\w+/.test(name.slice(watchName.length))));
325
+
326
+ var updateFieldArrayRootError = (errors, error, name) => {
327
+ const fieldArrayErrors = compact(get(errors, name));
328
+ set(fieldArrayErrors, 'root', error[name]);
329
+ set(errors, name, fieldArrayErrors);
330
+ return errors;
331
+ };
332
+
333
+ var isBoolean = (value) => typeof value === 'boolean';
334
+
335
+ var isFileInput = (element) => element.type === 'file';
336
+
337
+ var isFunction = (value) => typeof value === 'function';
338
+
339
+ var isHTMLElement = (value) => {
340
+ if (!isWeb) {
341
+ return false;
342
+ }
343
+ const owner = value ? value.ownerDocument : 0;
344
+ return (value instanceof
345
+ (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
346
+ };
347
+
348
+ var isMessage = (value) => isString(value);
349
+
350
+ var isRadioInput = (element) => element.type === 'radio';
351
+
352
+ var isRegex = (value) => value instanceof RegExp;
353
+
354
+ const defaultResult = {
355
+ value: false,
356
+ isValid: false,
357
+ };
358
+ const validResult = { value: true, isValid: true };
359
+ var getCheckboxValue = (options) => {
360
+ if (Array.isArray(options)) {
361
+ if (options.length > 1) {
362
+ const values = options
363
+ .filter((option) => option && option.checked && !option.disabled)
364
+ .map((option) => option.value);
365
+ return { value: values, isValid: !!values.length };
366
+ }
367
+ return options[0].checked && !options[0].disabled
368
+ ? // @ts-expect-error expected to work in the browser
369
+ options[0].attributes && !isUndefined(options[0].attributes.value)
370
+ ? isUndefined(options[0].value) || options[0].value === ''
371
+ ? validResult
372
+ : { value: options[0].value, isValid: true }
373
+ : validResult
374
+ : defaultResult;
375
+ }
376
+ return defaultResult;
377
+ };
378
+
379
+ const defaultReturn = {
380
+ isValid: false,
381
+ value: null,
382
+ };
383
+ var getRadioValue = (options) => Array.isArray(options)
384
+ ? options.reduce((previous, option) => option && option.checked && !option.disabled
385
+ ? {
386
+ isValid: true,
387
+ value: option.value,
388
+ }
389
+ : previous, defaultReturn)
390
+ : defaultReturn;
391
+
392
+ function getValidateError(result, ref, type = 'validate') {
393
+ if (isMessage(result) ||
394
+ (Array.isArray(result) && result.every(isMessage)) ||
395
+ (isBoolean(result) && !result)) {
396
+ return {
397
+ type,
398
+ message: isMessage(result) ? result : '',
399
+ ref,
400
+ };
401
+ }
402
+ }
195
403
 
196
- const HookFormContext = React__default.createContext(null);
197
-
198
- var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
199
- const result = {
200
- defaultValues: control._defaultValues,
201
- };
202
- for (const key in formState) {
203
- Object.defineProperty(result, key, {
204
- get: () => {
205
- const _key = key;
206
- if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
207
- control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
208
- }
209
- localProxyFormState && (localProxyFormState[_key] = true);
210
- return formState[_key];
211
- },
212
- });
213
- }
214
- return result;
215
- };
404
+ var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
405
+ ? validationData
406
+ : {
407
+ value: validationData,
408
+ message: '',
409
+ };
216
410
 
217
- var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
411
+ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
412
+ const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
413
+ const inputValue = get(formValues, name);
414
+ if (!mount || disabled) {
415
+ return {};
416
+ }
417
+ const inputRef = refs ? refs[0] : ref;
418
+ const setCustomValidity = (message) => {
419
+ if (shouldUseNativeValidation && inputRef.reportValidity) {
420
+ inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
421
+ inputRef.reportValidity();
422
+ }
423
+ };
424
+ const error = {};
425
+ const isRadio = isRadioInput(ref);
426
+ const isCheckBox = isCheckBoxInput(ref);
427
+ const isRadioOrCheckbox = isRadio || isCheckBox;
428
+ const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
429
+ isUndefined(ref.value) &&
430
+ isUndefined(inputValue)) ||
431
+ (isHTMLElement(ref) && ref.value === '') ||
432
+ inputValue === '' ||
433
+ (Array.isArray(inputValue) && !inputValue.length);
434
+ const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
435
+ const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
436
+ const message = exceedMax ? maxLengthMessage : minLengthMessage;
437
+ error[name] = {
438
+ type: exceedMax ? maxType : minType,
439
+ message,
440
+ ref,
441
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message),
442
+ };
443
+ };
444
+ if (isFieldArray
445
+ ? !Array.isArray(inputValue) || !inputValue.length
446
+ : required &&
447
+ ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
448
+ (isBoolean(inputValue) && !inputValue) ||
449
+ (isCheckBox && !getCheckboxValue(refs).isValid) ||
450
+ (isRadio && !getRadioValue(refs).isValid))) {
451
+ const { value, message } = isMessage(required)
452
+ ? { value: !!required, message: required }
453
+ : getValueAndMessage(required);
454
+ if (value) {
455
+ error[name] = {
456
+ type: INPUT_VALIDATION_RULES.required,
457
+ message,
458
+ ref: inputRef,
459
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
460
+ };
461
+ if (!validateAllFieldCriteria) {
462
+ setCustomValidity(message);
463
+ return error;
464
+ }
465
+ }
466
+ }
467
+ if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
468
+ let exceedMax;
469
+ let exceedMin;
470
+ const maxOutput = getValueAndMessage(max);
471
+ const minOutput = getValueAndMessage(min);
472
+ if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
473
+ const valueNumber = ref.valueAsNumber ||
474
+ (inputValue ? +inputValue : inputValue);
475
+ if (!isNullOrUndefined(maxOutput.value)) {
476
+ exceedMax = valueNumber > maxOutput.value;
477
+ }
478
+ if (!isNullOrUndefined(minOutput.value)) {
479
+ exceedMin = valueNumber < minOutput.value;
480
+ }
481
+ }
482
+ else {
483
+ const valueDate = ref.valueAsDate || new Date(inputValue);
484
+ const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
485
+ const isTime = ref.type == 'time';
486
+ const isWeek = ref.type == 'week';
487
+ if (isString(maxOutput.value) && inputValue) {
488
+ exceedMax = isTime
489
+ ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
490
+ : isWeek
491
+ ? inputValue > maxOutput.value
492
+ : valueDate > new Date(maxOutput.value);
493
+ }
494
+ if (isString(minOutput.value) && inputValue) {
495
+ exceedMin = isTime
496
+ ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
497
+ : isWeek
498
+ ? inputValue < minOutput.value
499
+ : valueDate < new Date(minOutput.value);
500
+ }
501
+ }
502
+ if (exceedMax || exceedMin) {
503
+ getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
504
+ if (!validateAllFieldCriteria) {
505
+ setCustomValidity(error[name].message);
506
+ return error;
507
+ }
508
+ }
509
+ }
510
+ if ((maxLength || minLength) &&
511
+ !isEmpty &&
512
+ (isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
513
+ const maxLengthOutput = getValueAndMessage(maxLength);
514
+ const minLengthOutput = getValueAndMessage(minLength);
515
+ const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
516
+ inputValue.length > +maxLengthOutput.value;
517
+ const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
518
+ inputValue.length < +minLengthOutput.value;
519
+ if (exceedMax || exceedMin) {
520
+ getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
521
+ if (!validateAllFieldCriteria) {
522
+ setCustomValidity(error[name].message);
523
+ return error;
524
+ }
525
+ }
526
+ }
527
+ if (pattern && !isEmpty && isString(inputValue)) {
528
+ const { value: patternValue, message } = getValueAndMessage(pattern);
529
+ if (isRegex(patternValue) && !inputValue.match(patternValue)) {
530
+ error[name] = {
531
+ type: INPUT_VALIDATION_RULES.pattern,
532
+ message,
533
+ ref,
534
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
535
+ };
536
+ if (!validateAllFieldCriteria) {
537
+ setCustomValidity(message);
538
+ return error;
539
+ }
540
+ }
541
+ }
542
+ if (validate) {
543
+ if (isFunction(validate)) {
544
+ const result = await validate(inputValue, formValues);
545
+ const validateError = getValidateError(result, inputRef);
546
+ if (validateError) {
547
+ error[name] = {
548
+ ...validateError,
549
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
550
+ };
551
+ if (!validateAllFieldCriteria) {
552
+ setCustomValidity(validateError.message);
553
+ return error;
554
+ }
555
+ }
556
+ }
557
+ else if (isObject(validate)) {
558
+ let validationResult = {};
559
+ for (const key in validate) {
560
+ if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
561
+ break;
562
+ }
563
+ const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
564
+ if (validateError) {
565
+ validationResult = {
566
+ ...validateError,
567
+ ...appendErrorsCurry(key, validateError.message),
568
+ };
569
+ setCustomValidity(validateError.message);
570
+ if (validateAllFieldCriteria) {
571
+ error[name] = validationResult;
572
+ }
573
+ }
574
+ }
575
+ if (!isEmptyObject(validationResult)) {
576
+ error[name] = {
577
+ ref: inputRef,
578
+ ...validationResult,
579
+ };
580
+ if (!validateAllFieldCriteria) {
581
+ return error;
582
+ }
583
+ }
584
+ }
585
+ }
586
+ setCustomValidity(true);
587
+ return error;
588
+ };
589
+
590
+ function baseGet(object, updatePath) {
591
+ const length = updatePath.slice(0, -1).length;
592
+ let index = 0;
593
+ while (index < length) {
594
+ object = isUndefined(object) ? index++ : object[updatePath[index++]];
595
+ }
596
+ return object;
597
+ }
598
+ function isEmptyArray(obj) {
599
+ for (const key in obj) {
600
+ if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
601
+ return false;
602
+ }
603
+ }
604
+ return true;
605
+ }
606
+ function unset(object, path) {
607
+ const paths = Array.isArray(path)
608
+ ? path
609
+ : isKey(path)
610
+ ? [path]
611
+ : stringToPath(path);
612
+ const childObject = paths.length === 1 ? object : baseGet(object, paths);
613
+ const index = paths.length - 1;
614
+ const key = paths[index];
615
+ if (childObject) {
616
+ delete childObject[key];
617
+ }
618
+ if (index !== 0 &&
619
+ ((isObject(childObject) && isEmptyObject(childObject)) ||
620
+ (Array.isArray(childObject) && isEmptyArray(childObject)))) {
621
+ unset(object, paths.slice(0, -1));
622
+ }
623
+ return object;
624
+ }
625
+
626
+ function createSubject() {
627
+ let _observers = [];
628
+ const next = (value) => {
629
+ for (const observer of _observers) {
630
+ observer.next && observer.next(value);
631
+ }
632
+ };
633
+ const subscribe = (observer) => {
634
+ _observers.push(observer);
635
+ return {
636
+ unsubscribe: () => {
637
+ _observers = _observers.filter((o) => o !== observer);
638
+ },
639
+ };
640
+ };
641
+ const unsubscribe = () => {
642
+ _observers = [];
643
+ };
644
+ return {
645
+ get observers() {
646
+ return _observers;
647
+ },
648
+ next,
649
+ subscribe,
650
+ unsubscribe,
651
+ };
652
+ }
218
653
 
219
- var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
220
- updateFormState(formStateData);
221
- const { name, ...formState } = formStateData;
222
- return (isEmptyObject(formState) ||
223
- Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
224
- Object.keys(formState).find((key) => _proxyFormState[key] ===
225
- (!isRoot || VALIDATION_MODE.all)));
226
- };
654
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
227
655
 
228
- var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
229
-
230
- function useSubscribe(props) {
231
- const _props = React__default.useRef(props);
232
- _props.current = props;
233
- React__default.useEffect(() => {
234
- const subscription = !props.disabled &&
235
- _props.current.subject &&
236
- _props.current.subject.subscribe({
237
- next: _props.current.next,
238
- });
239
- return () => {
240
- subscription && subscription.unsubscribe();
241
- };
242
- }, [props.disabled]);
243
- }
656
+ function deepEqual(object1, object2) {
657
+ if (isPrimitive(object1) || isPrimitive(object2)) {
658
+ return object1 === object2;
659
+ }
660
+ if (isDateObject(object1) && isDateObject(object2)) {
661
+ return object1.getTime() === object2.getTime();
662
+ }
663
+ const keys1 = Object.keys(object1);
664
+ const keys2 = Object.keys(object2);
665
+ if (keys1.length !== keys2.length) {
666
+ return false;
667
+ }
668
+ for (const key of keys1) {
669
+ const val1 = object1[key];
670
+ if (!keys2.includes(key)) {
671
+ return false;
672
+ }
673
+ if (key !== 'ref') {
674
+ const val2 = object2[key];
675
+ if ((isDateObject(val1) && isDateObject(val2)) ||
676
+ (isObject(val1) && isObject(val2)) ||
677
+ (Array.isArray(val1) && Array.isArray(val2))
678
+ ? !deepEqual(val1, val2)
679
+ : val1 !== val2) {
680
+ return false;
681
+ }
682
+ }
683
+ }
684
+ return true;
685
+ }
244
686
 
245
- var isString = (value) => typeof value === 'string';
687
+ var isMultipleSelect = (element) => element.type === `select-multiple`;
246
688
 
247
- var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
248
- if (isString(names)) {
249
- isGlobal && _names.watch.add(names);
250
- return get(formValues, names, defaultValue);
251
- }
252
- if (Array.isArray(names)) {
253
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
254
- }
255
- isGlobal && (_names.watchAll = true);
256
- return formValues;
257
- };
689
+ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
258
690
 
259
- var isKey = (value) => /^\w*$/.test(value);
260
-
261
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
262
-
263
- function set(object, path, value) {
264
- let index = -1;
265
- const tempPath = isKey(path) ? [path] : stringToPath(path);
266
- const length = tempPath.length;
267
- const lastIndex = length - 1;
268
- while (++index < length) {
269
- const key = tempPath[index];
270
- let newValue = value;
271
- if (index !== lastIndex) {
272
- const objValue = object[key];
273
- newValue =
274
- isObject(objValue) || Array.isArray(objValue)
275
- ? objValue
276
- : !isNaN(+tempPath[index + 1])
277
- ? []
278
- : {};
279
- }
280
- object[key] = newValue;
281
- object = object[key];
282
- }
283
- return object;
284
- }
691
+ var live = (ref) => isHTMLElement(ref) && ref.isConnected;
285
692
 
286
- var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
287
- ? {
288
- ...errors[name],
289
- types: {
290
- ...(errors[name] && errors[name].types ? errors[name].types : {}),
291
- [type]: message || true,
292
- },
293
- }
294
- : {};
295
-
296
- const focusFieldBy = (fields, callback, fieldsNames) => {
297
- for (const key of fieldsNames || Object.keys(fields)) {
298
- const field = get(fields, key);
299
- if (field) {
300
- const { _f, ...currentField } = field;
301
- if (_f && callback(_f.name)) {
302
- if (_f.ref.focus) {
303
- _f.ref.focus();
304
- break;
305
- }
306
- else if (_f.refs && _f.refs[0].focus) {
307
- _f.refs[0].focus();
308
- break;
309
- }
310
- }
311
- else if (isObject(currentField)) {
312
- focusFieldBy(currentField, callback);
313
- }
314
- }
315
- }
316
- };
693
+ var objectHasFunction = (data) => {
694
+ for (const key in data) {
695
+ if (isFunction(data[key])) {
696
+ return true;
697
+ }
698
+ }
699
+ return false;
700
+ };
701
+
702
+ function markFieldsDirty(data, fields = {}) {
703
+ const isParentNodeArray = Array.isArray(data);
704
+ if (isObject(data) || isParentNodeArray) {
705
+ for (const key in data) {
706
+ if (Array.isArray(data[key]) ||
707
+ (isObject(data[key]) && !objectHasFunction(data[key]))) {
708
+ fields[key] = Array.isArray(data[key]) ? [] : {};
709
+ markFieldsDirty(data[key], fields[key]);
710
+ }
711
+ else if (!isNullOrUndefined(data[key])) {
712
+ fields[key] = true;
713
+ }
714
+ }
715
+ }
716
+ return fields;
717
+ }
718
+ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
719
+ const isParentNodeArray = Array.isArray(data);
720
+ if (isObject(data) || isParentNodeArray) {
721
+ for (const key in data) {
722
+ if (Array.isArray(data[key]) ||
723
+ (isObject(data[key]) && !objectHasFunction(data[key]))) {
724
+ if (isUndefined(formValues) ||
725
+ isPrimitive(dirtyFieldsFromValues[key])) {
726
+ dirtyFieldsFromValues[key] = Array.isArray(data[key])
727
+ ? markFieldsDirty(data[key], [])
728
+ : { ...markFieldsDirty(data[key]) };
729
+ }
730
+ else {
731
+ getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
732
+ }
733
+ }
734
+ else {
735
+ dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
736
+ }
737
+ }
738
+ }
739
+ return dirtyFieldsFromValues;
740
+ }
741
+ var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
742
+
743
+ var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
744
+ ? value
745
+ : valueAsNumber
746
+ ? value === ''
747
+ ? NaN
748
+ : value
749
+ ? +value
750
+ : value
751
+ : valueAsDate && isString(value)
752
+ ? new Date(value)
753
+ : setValueAs
754
+ ? setValueAs(value)
755
+ : value;
756
+
757
+ function getFieldValue(_f) {
758
+ const ref = _f.ref;
759
+ if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
760
+ return;
761
+ }
762
+ if (isFileInput(ref)) {
763
+ return ref.files;
764
+ }
765
+ if (isRadioInput(ref)) {
766
+ return getRadioValue(_f.refs).value;
767
+ }
768
+ if (isMultipleSelect(ref)) {
769
+ return [...ref.selectedOptions].map(({ value }) => value);
770
+ }
771
+ if (isCheckBoxInput(ref)) {
772
+ return getCheckboxValue(_f.refs).value;
773
+ }
774
+ return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
775
+ }
776
+
777
+ var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
778
+ const fields = {};
779
+ for (const name of fieldsNames) {
780
+ const field = get(_fields, name);
781
+ field && set(fields, name, field._f);
782
+ }
783
+ return {
784
+ criteriaMode,
785
+ names: [...fieldsNames],
786
+ fields,
787
+ shouldUseNativeValidation,
788
+ };
789
+ };
790
+
791
+ var getRuleValue = (rule) => isUndefined(rule)
792
+ ? rule
793
+ : isRegex(rule)
794
+ ? rule.source
795
+ : isObject(rule)
796
+ ? isRegex(rule.value)
797
+ ? rule.value.source
798
+ : rule.value
799
+ : rule;
800
+
801
+ var hasValidation = (options) => options.mount &&
802
+ (options.required ||
803
+ options.min ||
804
+ options.max ||
805
+ options.maxLength ||
806
+ options.minLength ||
807
+ options.pattern ||
808
+ options.validate);
809
+
810
+ function schemaErrorLookup(errors, _fields, name) {
811
+ const error = get(errors, name);
812
+ if (error || isKey(name)) {
813
+ return {
814
+ error,
815
+ name,
816
+ };
817
+ }
818
+ const names = name.split('.');
819
+ while (names.length) {
820
+ const fieldName = names.join('.');
821
+ const field = get(_fields, fieldName);
822
+ const foundError = get(errors, fieldName);
823
+ if (field && !Array.isArray(field) && name !== fieldName) {
824
+ return { name };
825
+ }
826
+ if (foundError && foundError.type) {
827
+ return {
828
+ name: fieldName,
829
+ error: foundError,
830
+ };
831
+ }
832
+ names.pop();
833
+ }
834
+ return {
835
+ name,
836
+ };
837
+ }
317
838
 
318
- var getValidationModes = (mode) => ({
319
- isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
320
- isOnBlur: mode === VALIDATION_MODE.onBlur,
321
- isOnChange: mode === VALIDATION_MODE.onChange,
322
- isOnAll: mode === VALIDATION_MODE.all,
323
- isOnTouch: mode === VALIDATION_MODE.onTouched,
839
+ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
840
+ if (mode.isOnAll) {
841
+ return false;
842
+ }
843
+ else if (!isSubmitted && mode.isOnTouch) {
844
+ return !(isTouched || isBlurEvent);
845
+ }
846
+ else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
847
+ return !isBlurEvent;
848
+ }
849
+ else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
850
+ return isBlurEvent;
851
+ }
852
+ return true;
853
+ };
854
+
855
+ var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
856
+
857
+ const defaultOptions = {
858
+ mode: VALIDATION_MODE.onSubmit,
859
+ reValidateMode: VALIDATION_MODE.onChange,
860
+ shouldFocusError: true,
861
+ };
862
+ function createFormControl(props = {}, flushRootRender) {
863
+ let _options = {
864
+ ...defaultOptions,
865
+ ...props,
866
+ };
867
+ let _formState = {
868
+ submitCount: 0,
869
+ isDirty: false,
870
+ isLoading: isFunction(_options.defaultValues),
871
+ isValidating: false,
872
+ isSubmitted: false,
873
+ isSubmitting: false,
874
+ isSubmitSuccessful: false,
875
+ isValid: false,
876
+ touchedFields: {},
877
+ dirtyFields: {},
878
+ errors: {},
879
+ };
880
+ let _fields = {};
881
+ let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
882
+ ? cloneObject(_options.defaultValues || _options.values) || {}
883
+ : {};
884
+ let _formValues = _options.shouldUnregister
885
+ ? {}
886
+ : cloneObject(_defaultValues);
887
+ let _state = {
888
+ action: false,
889
+ mount: false,
890
+ watch: false,
891
+ };
892
+ let _names = {
893
+ mount: new Set(),
894
+ unMount: new Set(),
895
+ array: new Set(),
896
+ watch: new Set(),
897
+ };
898
+ let delayErrorCallback;
899
+ let timer = 0;
900
+ const _proxyFormState = {
901
+ isDirty: false,
902
+ dirtyFields: false,
903
+ touchedFields: false,
904
+ isValidating: false,
905
+ isValid: false,
906
+ errors: false,
907
+ };
908
+ const _subjects = {
909
+ values: createSubject(),
910
+ array: createSubject(),
911
+ state: createSubject(),
912
+ };
913
+ const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
914
+ const validationModeBeforeSubmit = getValidationModes(_options.mode);
915
+ const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
916
+ const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
917
+ const debounce = (callback) => (wait) => {
918
+ clearTimeout(timer);
919
+ timer = setTimeout(callback, wait);
920
+ };
921
+ const _updateValid = async (shouldUpdateValid) => {
922
+ if (_proxyFormState.isValid || shouldUpdateValid) {
923
+ const isValid = _options.resolver
924
+ ? isEmptyObject((await _executeSchema()).errors)
925
+ : await executeBuiltInValidation(_fields, true);
926
+ if (isValid !== _formState.isValid) {
927
+ _subjects.state.next({
928
+ isValid,
929
+ });
930
+ }
931
+ }
932
+ };
933
+ const _updateIsValidating = (value) => _proxyFormState.isValidating &&
934
+ _subjects.state.next({
935
+ isValidating: value,
936
+ });
937
+ const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
938
+ if (args && method) {
939
+ _state.action = true;
940
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
941
+ const fieldValues = method(get(_fields, name), args.argA, args.argB);
942
+ shouldSetValues && set(_fields, name, fieldValues);
943
+ }
944
+ if (shouldUpdateFieldsAndState &&
945
+ Array.isArray(get(_formState.errors, name))) {
946
+ const errors = method(get(_formState.errors, name), args.argA, args.argB);
947
+ shouldSetValues && set(_formState.errors, name, errors);
948
+ unsetEmptyArray(_formState.errors, name);
949
+ }
950
+ if (_proxyFormState.touchedFields &&
951
+ shouldUpdateFieldsAndState &&
952
+ Array.isArray(get(_formState.touchedFields, name))) {
953
+ const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
954
+ shouldSetValues && set(_formState.touchedFields, name, touchedFields);
955
+ }
956
+ if (_proxyFormState.dirtyFields) {
957
+ _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
958
+ }
959
+ _subjects.state.next({
960
+ name,
961
+ isDirty: _getDirty(name, values),
962
+ dirtyFields: _formState.dirtyFields,
963
+ errors: _formState.errors,
964
+ isValid: _formState.isValid,
965
+ });
966
+ }
967
+ else {
968
+ set(_formValues, name, values);
969
+ }
970
+ };
971
+ const updateErrors = (name, error) => {
972
+ set(_formState.errors, name, error);
973
+ _subjects.state.next({
974
+ errors: _formState.errors,
975
+ });
976
+ };
977
+ const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
978
+ const field = get(_fields, name);
979
+ if (field) {
980
+ const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
981
+ isUndefined(defaultValue) ||
982
+ (ref && ref.defaultChecked) ||
983
+ shouldSkipSetValueAs
984
+ ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
985
+ : setFieldValue(name, defaultValue);
986
+ _state.mount && _updateValid();
987
+ }
988
+ };
989
+ const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
990
+ let shouldUpdateField = false;
991
+ let isPreviousDirty = false;
992
+ const output = {
993
+ name,
994
+ };
995
+ if (!isBlurEvent || shouldDirty) {
996
+ if (_proxyFormState.isDirty) {
997
+ isPreviousDirty = _formState.isDirty;
998
+ _formState.isDirty = output.isDirty = _getDirty();
999
+ shouldUpdateField = isPreviousDirty !== output.isDirty;
1000
+ }
1001
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1002
+ isPreviousDirty = get(_formState.dirtyFields, name);
1003
+ isCurrentFieldPristine
1004
+ ? unset(_formState.dirtyFields, name)
1005
+ : set(_formState.dirtyFields, name, true);
1006
+ output.dirtyFields = _formState.dirtyFields;
1007
+ shouldUpdateField =
1008
+ shouldUpdateField ||
1009
+ (_proxyFormState.dirtyFields &&
1010
+ isPreviousDirty !== !isCurrentFieldPristine);
1011
+ }
1012
+ if (isBlurEvent) {
1013
+ const isPreviousFieldTouched = get(_formState.touchedFields, name);
1014
+ if (!isPreviousFieldTouched) {
1015
+ set(_formState.touchedFields, name, isBlurEvent);
1016
+ output.touchedFields = _formState.touchedFields;
1017
+ shouldUpdateField =
1018
+ shouldUpdateField ||
1019
+ (_proxyFormState.touchedFields &&
1020
+ isPreviousFieldTouched !== isBlurEvent);
1021
+ }
1022
+ }
1023
+ shouldUpdateField && shouldRender && _subjects.state.next(output);
1024
+ return shouldUpdateField ? output : {};
1025
+ };
1026
+ const shouldRenderByError = (name, isValid, error, fieldState) => {
1027
+ const previousFieldError = get(_formState.errors, name);
1028
+ const shouldUpdateValid = _proxyFormState.isValid &&
1029
+ isBoolean(isValid) &&
1030
+ _formState.isValid !== isValid;
1031
+ if (props.delayError && error) {
1032
+ delayErrorCallback = debounce(() => updateErrors(name, error));
1033
+ delayErrorCallback(props.delayError);
1034
+ }
1035
+ else {
1036
+ clearTimeout(timer);
1037
+ delayErrorCallback = null;
1038
+ error
1039
+ ? set(_formState.errors, name, error)
1040
+ : unset(_formState.errors, name);
1041
+ }
1042
+ if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
1043
+ !isEmptyObject(fieldState) ||
1044
+ shouldUpdateValid) {
1045
+ const updatedFormState = {
1046
+ ...fieldState,
1047
+ ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
1048
+ errors: _formState.errors,
1049
+ name,
1050
+ };
1051
+ _formState = {
1052
+ ..._formState,
1053
+ ...updatedFormState,
1054
+ };
1055
+ _subjects.state.next(updatedFormState);
1056
+ }
1057
+ _updateIsValidating(false);
1058
+ };
1059
+ const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1060
+ const executeSchemaAndUpdateState = async (names) => {
1061
+ const { errors } = await _executeSchema(names);
1062
+ if (names) {
1063
+ for (const name of names) {
1064
+ const error = get(errors, name);
1065
+ error
1066
+ ? set(_formState.errors, name, error)
1067
+ : unset(_formState.errors, name);
1068
+ }
1069
+ }
1070
+ else {
1071
+ _formState.errors = errors;
1072
+ }
1073
+ return errors;
1074
+ };
1075
+ const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
1076
+ valid: true,
1077
+ }) => {
1078
+ for (const name in fields) {
1079
+ const field = fields[name];
1080
+ if (field) {
1081
+ const { _f, ...fieldValue } = field;
1082
+ if (_f) {
1083
+ const isFieldArrayRoot = _names.array.has(_f.name);
1084
+ const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1085
+ if (fieldError[_f.name]) {
1086
+ context.valid = false;
1087
+ if (shouldOnlyCheckValid) {
1088
+ break;
1089
+ }
1090
+ }
1091
+ !shouldOnlyCheckValid &&
1092
+ (get(fieldError, _f.name)
1093
+ ? isFieldArrayRoot
1094
+ ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name)
1095
+ : set(_formState.errors, _f.name, fieldError[_f.name])
1096
+ : unset(_formState.errors, _f.name));
1097
+ }
1098
+ fieldValue &&
1099
+ (await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
1100
+ }
1101
+ }
1102
+ return context.valid;
1103
+ };
1104
+ const _removeUnmounted = () => {
1105
+ for (const name of _names.unMount) {
1106
+ const field = get(_fields, name);
1107
+ field &&
1108
+ (field._f.refs
1109
+ ? field._f.refs.every((ref) => !live(ref))
1110
+ : !live(field._f.ref)) &&
1111
+ unregister(name);
1112
+ }
1113
+ _names.unMount = new Set();
1114
+ };
1115
+ const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
1116
+ !deepEqual(getValues(), _defaultValues));
1117
+ const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1118
+ ...(_state.mount
1119
+ ? _formValues
1120
+ : isUndefined(defaultValue)
1121
+ ? _defaultValues
1122
+ : isString(names)
1123
+ ? { [names]: defaultValue }
1124
+ : defaultValue),
1125
+ }, isGlobal, defaultValue);
1126
+ const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
1127
+ const setFieldValue = (name, value, options = {}) => {
1128
+ const field = get(_fields, name);
1129
+ let fieldValue = value;
1130
+ if (field) {
1131
+ const fieldReference = field._f;
1132
+ if (fieldReference) {
1133
+ !fieldReference.disabled &&
1134
+ set(_formValues, name, getFieldValueAs(value, fieldReference));
1135
+ fieldValue =
1136
+ isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
1137
+ ? ''
1138
+ : value;
1139
+ if (isMultipleSelect(fieldReference.ref)) {
1140
+ [...fieldReference.ref.options].forEach((optionRef) => (optionRef.selected = fieldValue.includes(optionRef.value)));
1141
+ }
1142
+ else if (fieldReference.refs) {
1143
+ if (isCheckBoxInput(fieldReference.ref)) {
1144
+ fieldReference.refs.length > 1
1145
+ ? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) &&
1146
+ (checkboxRef.checked = Array.isArray(fieldValue)
1147
+ ? !!fieldValue.find((data) => data === checkboxRef.value)
1148
+ : fieldValue === checkboxRef.value))
1149
+ : fieldReference.refs[0] &&
1150
+ (fieldReference.refs[0].checked = !!fieldValue);
1151
+ }
1152
+ else {
1153
+ fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
1154
+ }
1155
+ }
1156
+ else if (isFileInput(fieldReference.ref)) {
1157
+ fieldReference.ref.value = '';
1158
+ }
1159
+ else {
1160
+ fieldReference.ref.value = fieldValue;
1161
+ if (!fieldReference.ref.type) {
1162
+ _subjects.values.next({
1163
+ name,
1164
+ values: { ..._formValues },
1165
+ });
1166
+ }
1167
+ }
1168
+ }
1169
+ }
1170
+ (options.shouldDirty || options.shouldTouch) &&
1171
+ updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
1172
+ options.shouldValidate && trigger(name);
1173
+ };
1174
+ const setValues = (name, value, options) => {
1175
+ for (const fieldKey in value) {
1176
+ const fieldValue = value[fieldKey];
1177
+ const fieldName = `${name}.${fieldKey}`;
1178
+ const field = get(_fields, fieldName);
1179
+ (_names.array.has(name) ||
1180
+ !isPrimitive(fieldValue) ||
1181
+ (field && !field._f)) &&
1182
+ !isDateObject(fieldValue)
1183
+ ? setValues(fieldName, fieldValue, options)
1184
+ : setFieldValue(fieldName, fieldValue, options);
1185
+ }
1186
+ };
1187
+ const setValue = (name, value, options = {}) => {
1188
+ const field = get(_fields, name);
1189
+ const isFieldArray = _names.array.has(name);
1190
+ const cloneValue = cloneObject(value);
1191
+ set(_formValues, name, cloneValue);
1192
+ if (isFieldArray) {
1193
+ _subjects.array.next({
1194
+ name,
1195
+ values: { ..._formValues },
1196
+ });
1197
+ if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
1198
+ options.shouldDirty) {
1199
+ _subjects.state.next({
1200
+ name,
1201
+ dirtyFields: getDirtyFields(_defaultValues, _formValues),
1202
+ isDirty: _getDirty(name, cloneValue),
1203
+ });
1204
+ }
1205
+ }
1206
+ else {
1207
+ field && !field._f && !isNullOrUndefined(cloneValue)
1208
+ ? setValues(name, cloneValue, options)
1209
+ : setFieldValue(name, cloneValue, options);
1210
+ }
1211
+ isWatched(name, _names) && _subjects.state.next({ ..._formState });
1212
+ _subjects.values.next({
1213
+ name,
1214
+ values: { ..._formValues },
1215
+ });
1216
+ !_state.mount && flushRootRender();
1217
+ };
1218
+ const onChange = async (event) => {
1219
+ const target = event.target;
1220
+ let name = target.name;
1221
+ let isFieldValueUpdated = true;
1222
+ const field = get(_fields, name);
1223
+ const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1224
+ if (field) {
1225
+ let error;
1226
+ let isValid;
1227
+ const fieldValue = getCurrentFieldValue();
1228
+ const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1229
+ const shouldSkipValidation = (!hasValidation(field._f) &&
1230
+ !_options.resolver &&
1231
+ !get(_formState.errors, name) &&
1232
+ !field._f.deps) ||
1233
+ skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
1234
+ const watched = isWatched(name, _names, isBlurEvent);
1235
+ set(_formValues, name, fieldValue);
1236
+ if (isBlurEvent) {
1237
+ field._f.onBlur && field._f.onBlur(event);
1238
+ delayErrorCallback && delayErrorCallback(0);
1239
+ }
1240
+ else if (field._f.onChange) {
1241
+ field._f.onChange(event);
1242
+ }
1243
+ const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
1244
+ const shouldRender = !isEmptyObject(fieldState) || watched;
1245
+ !isBlurEvent &&
1246
+ _subjects.values.next({
1247
+ name,
1248
+ type: event.type,
1249
+ values: { ..._formValues },
1250
+ });
1251
+ if (shouldSkipValidation) {
1252
+ _proxyFormState.isValid && _updateValid();
1253
+ return (shouldRender &&
1254
+ _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1255
+ }
1256
+ !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1257
+ _updateIsValidating(true);
1258
+ if (_options.resolver) {
1259
+ const { errors } = await _executeSchema([name]);
1260
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1261
+ const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1262
+ error = errorLookupResult.error;
1263
+ name = errorLookupResult.name;
1264
+ isValid = isEmptyObject(errors);
1265
+ }
1266
+ else {
1267
+ error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1268
+ isFieldValueUpdated =
1269
+ isNaN(fieldValue) ||
1270
+ fieldValue === get(_formValues, name, fieldValue);
1271
+ if (isFieldValueUpdated) {
1272
+ if (error) {
1273
+ isValid = false;
1274
+ }
1275
+ else if (_proxyFormState.isValid) {
1276
+ isValid = await executeBuiltInValidation(_fields, true);
1277
+ }
1278
+ }
1279
+ }
1280
+ if (isFieldValueUpdated) {
1281
+ field._f.deps &&
1282
+ trigger(field._f.deps);
1283
+ shouldRenderByError(name, isValid, error, fieldState);
1284
+ }
1285
+ }
1286
+ };
1287
+ const trigger = async (name, options = {}) => {
1288
+ let isValid;
1289
+ let validationResult;
1290
+ const fieldNames = convertToArrayPayload(name);
1291
+ _updateIsValidating(true);
1292
+ if (_options.resolver) {
1293
+ const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1294
+ isValid = isEmptyObject(errors);
1295
+ validationResult = name
1296
+ ? !fieldNames.some((name) => get(errors, name))
1297
+ : isValid;
1298
+ }
1299
+ else if (name) {
1300
+ validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
1301
+ const field = get(_fields, fieldName);
1302
+ return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
1303
+ }))).every(Boolean);
1304
+ !(!validationResult && !_formState.isValid) && _updateValid();
1305
+ }
1306
+ else {
1307
+ validationResult = isValid = await executeBuiltInValidation(_fields);
1308
+ }
1309
+ _subjects.state.next({
1310
+ ...(!isString(name) ||
1311
+ (_proxyFormState.isValid && isValid !== _formState.isValid)
1312
+ ? {}
1313
+ : { name }),
1314
+ ...(_options.resolver || !name ? { isValid } : {}),
1315
+ errors: _formState.errors,
1316
+ isValidating: false,
1317
+ });
1318
+ options.shouldFocus &&
1319
+ !validationResult &&
1320
+ focusFieldBy(_fields, (key) => key && get(_formState.errors, key), name ? fieldNames : _names.mount);
1321
+ return validationResult;
1322
+ };
1323
+ const getValues = (fieldNames) => {
1324
+ const values = {
1325
+ ..._defaultValues,
1326
+ ...(_state.mount ? _formValues : {}),
1327
+ };
1328
+ return isUndefined(fieldNames)
1329
+ ? values
1330
+ : isString(fieldNames)
1331
+ ? get(values, fieldNames)
1332
+ : fieldNames.map((name) => get(values, name));
1333
+ };
1334
+ const getFieldState = (name, formState) => ({
1335
+ invalid: !!get((formState || _formState).errors, name),
1336
+ isDirty: !!get((formState || _formState).dirtyFields, name),
1337
+ isTouched: !!get((formState || _formState).touchedFields, name),
1338
+ error: get((formState || _formState).errors, name),
1339
+ });
1340
+ const clearErrors = (name) => {
1341
+ name &&
1342
+ convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
1343
+ _subjects.state.next({
1344
+ errors: name ? _formState.errors : {},
1345
+ });
1346
+ };
1347
+ const setError = (name, error, options) => {
1348
+ const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1349
+ set(_formState.errors, name, {
1350
+ ...error,
1351
+ ref,
1352
+ });
1353
+ _subjects.state.next({
1354
+ name,
1355
+ errors: _formState.errors,
1356
+ isValid: false,
1357
+ });
1358
+ options && options.shouldFocus && ref && ref.focus && ref.focus();
1359
+ };
1360
+ const watch = (name, defaultValue) => isFunction(name)
1361
+ ? _subjects.values.subscribe({
1362
+ next: (payload) => name(_getWatch(undefined, defaultValue), payload),
1363
+ })
1364
+ : _getWatch(name, defaultValue, true);
1365
+ const unregister = (name, options = {}) => {
1366
+ for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
1367
+ _names.mount.delete(fieldName);
1368
+ _names.array.delete(fieldName);
1369
+ if (!options.keepValue) {
1370
+ unset(_fields, fieldName);
1371
+ unset(_formValues, fieldName);
1372
+ }
1373
+ !options.keepError && unset(_formState.errors, fieldName);
1374
+ !options.keepDirty && unset(_formState.dirtyFields, fieldName);
1375
+ !options.keepTouched && unset(_formState.touchedFields, fieldName);
1376
+ !_options.shouldUnregister &&
1377
+ !options.keepDefaultValue &&
1378
+ unset(_defaultValues, fieldName);
1379
+ }
1380
+ _subjects.values.next({
1381
+ values: { ..._formValues },
1382
+ });
1383
+ _subjects.state.next({
1384
+ ..._formState,
1385
+ ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
1386
+ });
1387
+ !options.keepIsValid && _updateValid();
1388
+ };
1389
+ const _updateDisabledField = ({ disabled, name, field, fields, }) => {
1390
+ if (isBoolean(disabled)) {
1391
+ const value = disabled
1392
+ ? undefined
1393
+ : get(_formValues, name, getFieldValue(field ? field._f : get(fields, name)._f));
1394
+ set(_formValues, name, value);
1395
+ updateTouchAndDirty(name, value, false, false, true);
1396
+ }
1397
+ };
1398
+ const register = (name, options = {}) => {
1399
+ let field = get(_fields, name);
1400
+ const disabledIsDefined = isBoolean(options.disabled);
1401
+ set(_fields, name, {
1402
+ ...(field || {}),
1403
+ _f: {
1404
+ ...(field && field._f ? field._f : { ref: { name } }),
1405
+ name,
1406
+ mount: true,
1407
+ ...options,
1408
+ },
1409
+ });
1410
+ _names.mount.add(name);
1411
+ if (field) {
1412
+ _updateDisabledField({
1413
+ field,
1414
+ disabled: options.disabled,
1415
+ name,
1416
+ });
1417
+ }
1418
+ else {
1419
+ updateValidAndValue(name, true, options.value);
1420
+ }
1421
+ return {
1422
+ ...(disabledIsDefined ? { disabled: options.disabled } : {}),
1423
+ ...(_options.progressive
1424
+ ? {
1425
+ required: !!options.required,
1426
+ min: getRuleValue(options.min),
1427
+ max: getRuleValue(options.max),
1428
+ minLength: getRuleValue(options.minLength),
1429
+ maxLength: getRuleValue(options.maxLength),
1430
+ pattern: getRuleValue(options.pattern),
1431
+ }
1432
+ : {}),
1433
+ name,
1434
+ onChange,
1435
+ onBlur: onChange,
1436
+ ref: (ref) => {
1437
+ if (ref) {
1438
+ register(name, options);
1439
+ field = get(_fields, name);
1440
+ const fieldRef = isUndefined(ref.value)
1441
+ ? ref.querySelectorAll
1442
+ ? ref.querySelectorAll('input,select,textarea')[0] || ref
1443
+ : ref
1444
+ : ref;
1445
+ const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
1446
+ const refs = field._f.refs || [];
1447
+ if (radioOrCheckbox
1448
+ ? refs.find((option) => option === fieldRef)
1449
+ : fieldRef === field._f.ref) {
1450
+ return;
1451
+ }
1452
+ set(_fields, name, {
1453
+ _f: {
1454
+ ...field._f,
1455
+ ...(radioOrCheckbox
1456
+ ? {
1457
+ refs: [
1458
+ ...refs.filter(live),
1459
+ fieldRef,
1460
+ ...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
1461
+ ],
1462
+ ref: { type: fieldRef.type, name },
1463
+ }
1464
+ : { ref: fieldRef }),
1465
+ },
1466
+ });
1467
+ updateValidAndValue(name, false, undefined, fieldRef);
1468
+ }
1469
+ else {
1470
+ field = get(_fields, name, {});
1471
+ if (field._f) {
1472
+ field._f.mount = false;
1473
+ }
1474
+ (_options.shouldUnregister || options.shouldUnregister) &&
1475
+ !(isNameInFieldArray(_names.array, name) && _state.action) &&
1476
+ _names.unMount.add(name);
1477
+ }
1478
+ },
1479
+ };
1480
+ };
1481
+ const _focusError = () => _options.shouldFocusError &&
1482
+ focusFieldBy(_fields, (key) => key && get(_formState.errors, key), _names.mount);
1483
+ const handleSubmit = (onValid, onInvalid) => async (e) => {
1484
+ if (e) {
1485
+ e.preventDefault && e.preventDefault();
1486
+ e.persist && e.persist();
1487
+ }
1488
+ let fieldValues = cloneObject(_formValues);
1489
+ _subjects.state.next({
1490
+ isSubmitting: true,
1491
+ });
1492
+ if (_options.resolver) {
1493
+ const { errors, values } = await _executeSchema();
1494
+ _formState.errors = errors;
1495
+ fieldValues = values;
1496
+ }
1497
+ else {
1498
+ await executeBuiltInValidation(_fields);
1499
+ }
1500
+ unset(_formState.errors, 'root');
1501
+ if (isEmptyObject(_formState.errors)) {
1502
+ _subjects.state.next({
1503
+ errors: {},
1504
+ });
1505
+ await onValid(fieldValues, e);
1506
+ }
1507
+ else {
1508
+ if (onInvalid) {
1509
+ await onInvalid({ ..._formState.errors }, e);
1510
+ }
1511
+ _focusError();
1512
+ setTimeout(_focusError);
1513
+ }
1514
+ _subjects.state.next({
1515
+ isSubmitted: true,
1516
+ isSubmitting: false,
1517
+ isSubmitSuccessful: isEmptyObject(_formState.errors),
1518
+ submitCount: _formState.submitCount + 1,
1519
+ errors: _formState.errors,
1520
+ });
1521
+ };
1522
+ const resetField = (name, options = {}) => {
1523
+ if (get(_fields, name)) {
1524
+ if (isUndefined(options.defaultValue)) {
1525
+ setValue(name, get(_defaultValues, name));
1526
+ }
1527
+ else {
1528
+ setValue(name, options.defaultValue);
1529
+ set(_defaultValues, name, options.defaultValue);
1530
+ }
1531
+ if (!options.keepTouched) {
1532
+ unset(_formState.touchedFields, name);
1533
+ }
1534
+ if (!options.keepDirty) {
1535
+ unset(_formState.dirtyFields, name);
1536
+ _formState.isDirty = options.defaultValue
1537
+ ? _getDirty(name, get(_defaultValues, name))
1538
+ : _getDirty();
1539
+ }
1540
+ if (!options.keepError) {
1541
+ unset(_formState.errors, name);
1542
+ _proxyFormState.isValid && _updateValid();
1543
+ }
1544
+ _subjects.state.next({ ..._formState });
1545
+ }
1546
+ };
1547
+ const _reset = (formValues, keepStateOptions = {}) => {
1548
+ const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
1549
+ const cloneUpdatedValues = cloneObject(updatedValues);
1550
+ const values = formValues && !isEmptyObject(formValues)
1551
+ ? cloneUpdatedValues
1552
+ : _defaultValues;
1553
+ if (!keepStateOptions.keepDefaultValues) {
1554
+ _defaultValues = updatedValues;
1555
+ }
1556
+ if (!keepStateOptions.keepValues) {
1557
+ if (keepStateOptions.keepDirtyValues || shouldCaptureDirtyFields) {
1558
+ for (const fieldName of _names.mount) {
1559
+ get(_formState.dirtyFields, fieldName)
1560
+ ? set(values, fieldName, get(_formValues, fieldName))
1561
+ : setValue(fieldName, get(values, fieldName));
1562
+ }
1563
+ }
1564
+ else {
1565
+ if (isWeb && isUndefined(formValues)) {
1566
+ for (const name of _names.mount) {
1567
+ const field = get(_fields, name);
1568
+ if (field && field._f) {
1569
+ const fieldReference = Array.isArray(field._f.refs)
1570
+ ? field._f.refs[0]
1571
+ : field._f.ref;
1572
+ if (isHTMLElement(fieldReference)) {
1573
+ const form = fieldReference.closest('form');
1574
+ if (form) {
1575
+ form.reset();
1576
+ break;
1577
+ }
1578
+ }
1579
+ }
1580
+ }
1581
+ }
1582
+ _fields = {};
1583
+ }
1584
+ _formValues = props.shouldUnregister
1585
+ ? keepStateOptions.keepDefaultValues
1586
+ ? cloneObject(_defaultValues)
1587
+ : {}
1588
+ : cloneObject(values);
1589
+ _subjects.array.next({
1590
+ values: { ...values },
1591
+ });
1592
+ _subjects.values.next({
1593
+ values: { ...values },
1594
+ });
1595
+ }
1596
+ _names = {
1597
+ mount: new Set(),
1598
+ unMount: new Set(),
1599
+ array: new Set(),
1600
+ watch: new Set(),
1601
+ watchAll: false,
1602
+ focus: '',
1603
+ };
1604
+ !_state.mount && flushRootRender();
1605
+ _state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
1606
+ _state.watch = !!props.shouldUnregister;
1607
+ _subjects.state.next({
1608
+ submitCount: keepStateOptions.keepSubmitCount
1609
+ ? _formState.submitCount
1610
+ : 0,
1611
+ isDirty: keepStateOptions.keepDirty
1612
+ ? _formState.isDirty
1613
+ : !!(keepStateOptions.keepDefaultValues &&
1614
+ !deepEqual(formValues, _defaultValues)),
1615
+ isSubmitted: keepStateOptions.keepIsSubmitted
1616
+ ? _formState.isSubmitted
1617
+ : false,
1618
+ dirtyFields: keepStateOptions.keepDirtyValues
1619
+ ? _formState.dirtyFields
1620
+ : keepStateOptions.keepDefaultValues && formValues
1621
+ ? getDirtyFields(_defaultValues, formValues)
1622
+ : {},
1623
+ touchedFields: keepStateOptions.keepTouched
1624
+ ? _formState.touchedFields
1625
+ : {},
1626
+ errors: keepStateOptions.keepErrors ? _formState.errors : {},
1627
+ isSubmitting: false,
1628
+ isSubmitSuccessful: false,
1629
+ });
1630
+ };
1631
+ const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
1632
+ ? formValues(_formValues)
1633
+ : formValues, keepStateOptions);
1634
+ const setFocus = (name, options = {}) => {
1635
+ const field = get(_fields, name);
1636
+ const fieldReference = field && field._f;
1637
+ if (fieldReference) {
1638
+ const fieldRef = fieldReference.refs
1639
+ ? fieldReference.refs[0]
1640
+ : fieldReference.ref;
1641
+ if (fieldRef.focus) {
1642
+ fieldRef.focus();
1643
+ options.shouldSelect && fieldRef.select();
1644
+ }
1645
+ }
1646
+ };
1647
+ const _updateFormState = (updatedFormState) => {
1648
+ _formState = {
1649
+ ..._formState,
1650
+ ...updatedFormState,
1651
+ };
1652
+ };
1653
+ const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
1654
+ _options.defaultValues().then((values) => {
1655
+ reset(values, _options.resetOptions);
1656
+ _subjects.state.next({
1657
+ isLoading: false,
1658
+ });
1659
+ });
1660
+ return {
1661
+ control: {
1662
+ register,
1663
+ unregister,
1664
+ getFieldState,
1665
+ handleSubmit,
1666
+ setError,
1667
+ _executeSchema,
1668
+ _getWatch,
1669
+ _getDirty,
1670
+ _updateValid,
1671
+ _removeUnmounted,
1672
+ _updateFieldArray,
1673
+ _updateDisabledField,
1674
+ _getFieldArray,
1675
+ _reset,
1676
+ _resetDefaultValues,
1677
+ _updateFormState,
1678
+ _subjects,
1679
+ _proxyFormState,
1680
+ get _fields() {
1681
+ return _fields;
1682
+ },
1683
+ get _formValues() {
1684
+ return _formValues;
1685
+ },
1686
+ get _state() {
1687
+ return _state;
1688
+ },
1689
+ set _state(value) {
1690
+ _state = value;
1691
+ },
1692
+ get _defaultValues() {
1693
+ return _defaultValues;
1694
+ },
1695
+ get _names() {
1696
+ return _names;
1697
+ },
1698
+ set _names(value) {
1699
+ _names = value;
1700
+ },
1701
+ get _formState() {
1702
+ return _formState;
1703
+ },
1704
+ set _formState(value) {
1705
+ _formState = value;
1706
+ },
1707
+ get _options() {
1708
+ return _options;
1709
+ },
1710
+ set _options(value) {
1711
+ _options = {
1712
+ ..._options,
1713
+ ...value,
1714
+ };
1715
+ },
1716
+ },
1717
+ trigger,
1718
+ register,
1719
+ handleSubmit,
1720
+ watch,
1721
+ setValue,
1722
+ getValues,
1723
+ reset,
1724
+ resetField,
1725
+ clearErrors,
1726
+ unregister,
1727
+ setError,
1728
+ setFocus,
1729
+ getFieldState,
1730
+ };
1731
+ }
1732
+
1733
+ /**
1734
+ * Custom hook to manage the entire form.
1735
+ *
1736
+ * @remarks
1737
+ * [API](https://react-hook-form.com/docs/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
1738
+ *
1739
+ * @param props - form configuration and validation parameters.
1740
+ *
1741
+ * @returns methods - individual functions to manage the form state. {@link UseFormReturn}
1742
+ *
1743
+ * @example
1744
+ * ```tsx
1745
+ * function App() {
1746
+ * const { register, handleSubmit, watch, formState: { errors } } = useForm();
1747
+ * const onSubmit = data => console.log(data);
1748
+ *
1749
+ * console.log(watch("example"));
1750
+ *
1751
+ * return (
1752
+ * <form onSubmit={handleSubmit(onSubmit)}>
1753
+ * <input defaultValue="test" {...register("example")} />
1754
+ * <input {...register("exampleRequired", { required: true })} />
1755
+ * {errors.exampleRequired && <span>This field is required</span>}
1756
+ * <button>Submit</button>
1757
+ * </form>
1758
+ * );
1759
+ * }
1760
+ * ```
1761
+ */
1762
+ function useForm(props = {}) {
1763
+ const _formControl = React.useRef();
1764
+ const _values = React.useRef();
1765
+ const [formState, updateFormState] = React.useState({
1766
+ isDirty: false,
1767
+ isValidating: false,
1768
+ isLoading: isFunction(props.defaultValues),
1769
+ isSubmitted: false,
1770
+ isSubmitting: false,
1771
+ isSubmitSuccessful: false,
1772
+ isValid: false,
1773
+ submitCount: 0,
1774
+ dirtyFields: {},
1775
+ touchedFields: {},
1776
+ errors: {},
1777
+ defaultValues: isFunction(props.defaultValues)
1778
+ ? undefined
1779
+ : props.defaultValues,
1780
+ });
1781
+ if (!_formControl.current) {
1782
+ _formControl.current = {
1783
+ ...createFormControl(props, () => updateFormState((formState) => ({ ...formState }))),
1784
+ formState,
1785
+ };
1786
+ }
1787
+ const control = _formControl.current.control;
1788
+ control._options = props;
1789
+ useSubscribe({
1790
+ subject: control._subjects.state,
1791
+ next: (value) => {
1792
+ if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
1793
+ updateFormState({ ...control._formState });
1794
+ }
1795
+ },
1796
+ });
1797
+ React.useEffect(() => {
1798
+ if (props.values && !deepEqual(props.values, _values.current)) {
1799
+ control._reset(props.values, control._options.resetOptions);
1800
+ _values.current = props.values;
1801
+ }
1802
+ else {
1803
+ control._resetDefaultValues();
1804
+ }
1805
+ }, [props.values, control]);
1806
+ React.useEffect(() => {
1807
+ if (!control._state.mount) {
1808
+ control._updateValid();
1809
+ control._state.mount = true;
1810
+ }
1811
+ if (control._state.watch) {
1812
+ control._state.watch = false;
1813
+ control._subjects.state.next({ ...control._formState });
1814
+ }
1815
+ control._removeUnmounted();
1816
+ });
1817
+ _formControl.current.formState = getProxyFormState(formState, control);
1818
+ return _formControl.current;
1819
+ }
1820
+
1821
+ var theme = {
1822
+ breakpoints: ['40em', '52em', '64em'],
1823
+ space: ['0px', '4px', '8px', '16px', '32px', '64px', '128px', '256px', '512px'],
1824
+ fontSizes: ['12px', '14px', '16px', '20px', '24px', '32px', '48px', '64px', '72px'],
1825
+ marginPaddings: ['0.5rem', '1rem', '1.5rem', '2rem', '2.5rem', '3rem', '3.5rem', '4rem', '4.5rem', '5rem', '5.5rem', '6rem'],
1826
+ letterSpacings: ['-0.5px', '0px', '+0.5px'],
1827
+ radii: ['0px', '2px', '4px', '8px'],
1828
+ borderRadius: '6px',
1829
+ colors: {
1830
+ primary: '#000',
1831
+ base: '#4e4949',
1832
+ baseLt: '#817c7c',
1833
+ borderColor: '#d8d8d8',
1834
+ ntrlMin: '#fff',
1835
+ ntrlMinTen: '#e6e6e6',
1836
+ gray: '#efefef',
1837
+ darkerGray: '#454141'
1838
+ },
1839
+ rareStepColors: {
1840
+ primary: '#202b58',
1841
+ secondary: '#ef5c2d',
1842
+ ntrlMin: '#ffffff',
1843
+ ntrl40: '#f4f4f4',
1844
+ ntrl50: '#808080',
1845
+ ntrl60: '#e8e8e8',
1846
+ ntrl70: '#252525',
1847
+ ntrlMax: '#000000'
1848
+ },
1849
+ rareStepFontWeights: {
1850
+ normal: 400,
1851
+ medium: 500,
1852
+ semiBold: 600,
1853
+ bold: 700
1854
+ },
1855
+ rareStepFontSize: {
1856
+ h1: '36px',
1857
+ h2: '30px',
1858
+ h3: '24px',
1859
+ h4: '20px',
1860
+ h5: '16px',
1861
+ h6: '14px',
1862
+ footerTitle: '16px'
1863
+ },
1864
+ rareStepPageSizes: {
1865
+ mobile: '500px',
1866
+ tablet: '768px',
1867
+ desktop: '992px',
1868
+ screenl: '1280px',
1869
+ screenxl: '1680px',
1870
+ screenxxl: '1920px',
1871
+ container: '1600px'
1872
+ }
1873
+ };
1874
+
1875
+ var themed = (function (Component) {
1876
+ return /*#__PURE__*/forwardRef(function (props, ref) {
1877
+ return /*#__PURE__*/React.createElement(ThemeProvider, {
1878
+ theme: theme
1879
+ }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
1880
+ ref: ref
1881
+ })));
324
1882
  });
1883
+ });
1884
+
1885
+ var _templateObject;
1886
+ var FooterWrapper = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n {\n background-color: ", ";\n }\n"])), function (props) {
1887
+ return props.theme.colors.gray;
1888
+ });
1889
+
1890
+ var Event = function Event(instance, track) {
1891
+ var category = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
1892
+ var action = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
1893
+ var label = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
1894
+ var value = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
1895
+
1896
+ if (track) {
1897
+ instance.event({
1898
+ category: category,
1899
+ action: action,
1900
+ label: label,
1901
+ value: value
1902
+ });
1903
+ }
1904
+ };
325
1905
 
326
- var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
327
- (_names.watchAll ||
328
- _names.watch.has(name) ||
329
- [..._names.watch].some((watchName) => name.startsWith(watchName) &&
330
- /^\.\w+/.test(name.slice(watchName.length))));
331
-
332
- var updateFieldArrayRootError = (errors, error, name) => {
333
- const fieldArrayErrors = compact(get(errors, name));
334
- set(fieldArrayErrors, 'root', error[name]);
335
- set(errors, name, fieldArrayErrors);
336
- return errors;
337
- };
338
-
339
- var isBoolean = (value) => typeof value === 'boolean';
340
-
341
- var isFileInput = (element) => element.type === 'file';
342
-
343
- var isFunction = (value) => typeof value === 'function';
1906
+ var GALink = function GALink(props) {
1907
+ var gaOnClick = function gaOnClick(event) {
1908
+ Event(props.instance, props.track, 'Link', "Click on ".concat(props.href), props.label);
344
1909
 
345
- var isHTMLElement = (value) => {
346
- if (!isWeb) {
347
- return false;
348
- }
349
- const owner = value ? value.ownerDocument : 0;
350
- return (value instanceof
351
- (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
1910
+ if (typeof props.onClick === 'function') {
1911
+ props.onClick(event);
1912
+ }
352
1913
  };
353
1914
 
354
- var isMessage = (value) => isString(value);
355
-
356
- var isRadioInput = (element) => element.type === 'radio';
357
-
358
- var isRegex = (value) => value instanceof RegExp;
1915
+ return /*#__PURE__*/React.createElement("a", _extends({
1916
+ href: "/"
1917
+ }, props, {
1918
+ onClick: gaOnClick
1919
+ }), props.children);
1920
+ };
1921
+
1922
+ var _templateObject$1, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
1923
+ /* position relative is required for the Body element to be positioned correctly */
1924
+
1925
+ var relativeInlineStyle = css(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n position: relative;\n"])));
1926
+ var topMiddleBodyStyle = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 1;\n bottom: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n"])));
1927
+ var getTopMiddleArrowAfterStyle = function getTopMiddleArrowAfterStyle(props) {
1928
+ return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n /*Bottom Arrow*/\n top: 100%; /* At the bottom of the tooltip */\n left: calc(50% - ", ");\n border-width: ", ";\n border-style: solid;\n border-color: ", " transparent transparent transparent;\n"])), props.$apexWidth, props.$apexWidth, props.theme.colors.base);
1929
+ };
1930
+ var getBottomMiddleBodyStyle = function getBottomMiddleBodyStyle(props) {
1931
+ return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n top: 100%;\n left: calc(50% - ", " / 2);\n"])), props.$bodyWidth);
1932
+ };
1933
+ var getBottomMiddleArrowAfterStyle = function getBottomMiddleArrowAfterStyle(props) {
1934
+ return css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n /*Top Arrow*/\n bottom: 100%; /* At the top of the tooltip */\n top: initial;\n left: 50%;\n border-style: solid;\n border-color: transparent transparent ", " transparent;\n"])), props.theme.colors.base);
1935
+ };
1936
+
1937
+ var _templateObject$2;
1938
+
1939
+ var getBodyStyle = function getBodyStyle() {
1940
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1941
+ var _props$$toolTipPositi = props.$toolTipPosition,
1942
+ $toolTipPosition = _props$$toolTipPositi === void 0 ? '' : _props$$toolTipPositi;
1943
+
1944
+ switch ($toolTipPosition) {
1945
+ case 'top':
1946
+ return topMiddleBodyStyle;
1947
+
1948
+ case 'bottom':
1949
+ return getBottomMiddleBodyStyle(props);
1950
+
1951
+ default:
1952
+ return null;
1953
+ }
1954
+ };
359
1955
 
360
- const defaultResult = {
361
- value: false,
362
- isValid: false,
363
- };
364
- const validResult = { value: true, isValid: true };
365
- var getCheckboxValue = (options) => {
366
- if (Array.isArray(options)) {
367
- if (options.length > 1) {
368
- const values = options
369
- .filter((option) => option && option.checked && !option.disabled)
370
- .map((option) => option.value);
371
- return { value: values, isValid: !!values.length };
372
- }
373
- return options[0].checked && !options[0].disabled
374
- ? // @ts-expect-error expected to work in the browser
375
- options[0].attributes && !isUndefined(options[0].attributes.value)
376
- ? isUndefined(options[0].value) || options[0].value === ''
377
- ? validResult
378
- : { value: options[0].value, isValid: true }
379
- : validResult
380
- : defaultResult;
381
- }
382
- return defaultResult;
383
- };
1956
+ var getAfterStyling = function getAfterStyling() {
1957
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1958
+ var $toolTipPosition = props.$toolTipPosition;
384
1959
 
385
- const defaultReturn = {
386
- isValid: false,
387
- value: null,
388
- };
389
- var getRadioValue = (options) => Array.isArray(options)
390
- ? options.reduce((previous, option) => option && option.checked && !option.disabled
391
- ? {
392
- isValid: true,
393
- value: option.value,
394
- }
395
- : previous, defaultReturn)
396
- : defaultReturn;
397
-
398
- function getValidateError(result, ref, type = 'validate') {
399
- if (isMessage(result) ||
400
- (Array.isArray(result) && result.every(isMessage)) ||
401
- (isBoolean(result) && !result)) {
402
- return {
403
- type,
404
- message: isMessage(result) ? result : '',
405
- ref,
406
- };
407
- }
408
- }
1960
+ switch ($toolTipPosition) {
1961
+ case 'top':
1962
+ return getTopMiddleArrowAfterStyle(props);
409
1963
 
410
- var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
411
- ? validationData
412
- : {
413
- value: validationData,
414
- message: '',
415
- };
416
-
417
- var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
418
- const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
419
- const inputValue = get(formValues, name);
420
- if (!mount || disabled) {
421
- return {};
422
- }
423
- const inputRef = refs ? refs[0] : ref;
424
- const setCustomValidity = (message) => {
425
- if (shouldUseNativeValidation && inputRef.reportValidity) {
426
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
427
- inputRef.reportValidity();
428
- }
429
- };
430
- const error = {};
431
- const isRadio = isRadioInput(ref);
432
- const isCheckBox = isCheckBoxInput(ref);
433
- const isRadioOrCheckbox = isRadio || isCheckBox;
434
- const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
435
- isUndefined(ref.value) &&
436
- isUndefined(inputValue)) ||
437
- (isHTMLElement(ref) && ref.value === '') ||
438
- inputValue === '' ||
439
- (Array.isArray(inputValue) && !inputValue.length);
440
- const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
441
- const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
442
- const message = exceedMax ? maxLengthMessage : minLengthMessage;
443
- error[name] = {
444
- type: exceedMax ? maxType : minType,
445
- message,
446
- ref,
447
- ...appendErrorsCurry(exceedMax ? maxType : minType, message),
448
- };
449
- };
450
- if (isFieldArray
451
- ? !Array.isArray(inputValue) || !inputValue.length
452
- : required &&
453
- ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
454
- (isBoolean(inputValue) && !inputValue) ||
455
- (isCheckBox && !getCheckboxValue(refs).isValid) ||
456
- (isRadio && !getRadioValue(refs).isValid))) {
457
- const { value, message } = isMessage(required)
458
- ? { value: !!required, message: required }
459
- : getValueAndMessage(required);
460
- if (value) {
461
- error[name] = {
462
- type: INPUT_VALIDATION_RULES.required,
463
- message,
464
- ref: inputRef,
465
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
466
- };
467
- if (!validateAllFieldCriteria) {
468
- setCustomValidity(message);
469
- return error;
470
- }
471
- }
472
- }
473
- if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
474
- let exceedMax;
475
- let exceedMin;
476
- const maxOutput = getValueAndMessage(max);
477
- const minOutput = getValueAndMessage(min);
478
- if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
479
- const valueNumber = ref.valueAsNumber ||
480
- (inputValue ? +inputValue : inputValue);
481
- if (!isNullOrUndefined(maxOutput.value)) {
482
- exceedMax = valueNumber > maxOutput.value;
483
- }
484
- if (!isNullOrUndefined(minOutput.value)) {
485
- exceedMin = valueNumber < minOutput.value;
486
- }
487
- }
488
- else {
489
- const valueDate = ref.valueAsDate || new Date(inputValue);
490
- const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
491
- const isTime = ref.type == 'time';
492
- const isWeek = ref.type == 'week';
493
- if (isString(maxOutput.value) && inputValue) {
494
- exceedMax = isTime
495
- ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
496
- : isWeek
497
- ? inputValue > maxOutput.value
498
- : valueDate > new Date(maxOutput.value);
499
- }
500
- if (isString(minOutput.value) && inputValue) {
501
- exceedMin = isTime
502
- ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
503
- : isWeek
504
- ? inputValue < minOutput.value
505
- : valueDate < new Date(minOutput.value);
506
- }
507
- }
508
- if (exceedMax || exceedMin) {
509
- getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
510
- if (!validateAllFieldCriteria) {
511
- setCustomValidity(error[name].message);
512
- return error;
513
- }
514
- }
515
- }
516
- if ((maxLength || minLength) &&
517
- !isEmpty &&
518
- (isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
519
- const maxLengthOutput = getValueAndMessage(maxLength);
520
- const minLengthOutput = getValueAndMessage(minLength);
521
- const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
522
- inputValue.length > +maxLengthOutput.value;
523
- const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
524
- inputValue.length < +minLengthOutput.value;
525
- if (exceedMax || exceedMin) {
526
- getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
527
- if (!validateAllFieldCriteria) {
528
- setCustomValidity(error[name].message);
529
- return error;
530
- }
531
- }
532
- }
533
- if (pattern && !isEmpty && isString(inputValue)) {
534
- const { value: patternValue, message } = getValueAndMessage(pattern);
535
- if (isRegex(patternValue) && !inputValue.match(patternValue)) {
536
- error[name] = {
537
- type: INPUT_VALIDATION_RULES.pattern,
538
- message,
539
- ref,
540
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
541
- };
542
- if (!validateAllFieldCriteria) {
543
- setCustomValidity(message);
544
- return error;
545
- }
546
- }
547
- }
548
- if (validate) {
549
- if (isFunction(validate)) {
550
- const result = await validate(inputValue, formValues);
551
- const validateError = getValidateError(result, inputRef);
552
- if (validateError) {
553
- error[name] = {
554
- ...validateError,
555
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
556
- };
557
- if (!validateAllFieldCriteria) {
558
- setCustomValidity(validateError.message);
559
- return error;
560
- }
561
- }
562
- }
563
- else if (isObject(validate)) {
564
- let validationResult = {};
565
- for (const key in validate) {
566
- if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
567
- break;
568
- }
569
- const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
570
- if (validateError) {
571
- validationResult = {
572
- ...validateError,
573
- ...appendErrorsCurry(key, validateError.message),
574
- };
575
- setCustomValidity(validateError.message);
576
- if (validateAllFieldCriteria) {
577
- error[name] = validationResult;
578
- }
579
- }
580
- }
581
- if (!isEmptyObject(validationResult)) {
582
- error[name] = {
583
- ref: inputRef,
584
- ...validationResult,
585
- };
586
- if (!validateAllFieldCriteria) {
587
- return error;
588
- }
589
- }
590
- }
591
- }
592
- setCustomValidity(true);
593
- return error;
594
- };
1964
+ case 'bottom':
1965
+ return getBottomMiddleArrowAfterStyle(props);
595
1966
 
596
- function baseGet(object, updatePath) {
597
- const length = updatePath.slice(0, -1).length;
598
- let index = 0;
599
- while (index < length) {
600
- object = isUndefined(object) ? index++ : object[updatePath[index++]];
601
- }
602
- return object;
1967
+ default:
1968
+ return '';
603
1969
  }
604
- function isEmptyArray(obj) {
605
- for (const key in obj) {
606
- if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
607
- return false;
608
- }
609
- }
610
- return true;
611
- }
612
- function unset(object, path) {
613
- const paths = Array.isArray(path)
614
- ? path
615
- : isKey(path)
616
- ? [path]
617
- : stringToPath(path);
618
- const childObject = paths.length === 1 ? object : baseGet(object, paths);
619
- const index = paths.length - 1;
620
- const key = paths[index];
621
- if (childObject) {
622
- delete childObject[key];
623
- }
624
- if (index !== 0 &&
625
- ((isObject(childObject) && isEmptyObject(childObject)) ||
626
- (Array.isArray(childObject) && isEmptyArray(childObject)))) {
627
- unset(object, paths.slice(0, -1));
628
- }
629
- return object;
1970
+ };
1971
+
1972
+ var Body = styled.span(_templateObject$2 || (_templateObject$2 = _taggedTemplateLiteral(["\n ", ";\n visibility: hidden;\n opacity: 0;\n width: ", ";\n transition: visibility 0.3s linear, opacity 0.3s linear;\n background-color: ", ";\n color: white;\n text-align: center;\n border-radius: 5px;\n ", "\n &::after {\n content: ' ';\n position: absolute;\n ", "\n }\n"])), relativeInlineStyle, function (props) {
1973
+ return props.$bodyWidth;
1974
+ }, function (props) {
1975
+ return props.theme.colors.base || 'black';
1976
+ }, function (props) {
1977
+ return getBodyStyle(props);
1978
+ }, function (props) {
1979
+ return getAfterStyling(props);
1980
+ });
1981
+
1982
+ var _templateObject$3;
1983
+ var Container = styled.div(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteral(["\n ", ";\n cursor: pointer;\n &:hover ", " {\n opacity: 1;\n visibility: visible;\n }\n"])), relativeInlineStyle, Body);
1984
+
1985
+ /* eslint-disable react/require-default-props */
1986
+
1987
+ var Tooltip = function Tooltip(_ref) {
1988
+ var _ref$children = _ref.children,
1989
+ children = _ref$children === void 0 ? null : _ref$children,
1990
+ _ref$toolTipText = _ref.toolTipText,
1991
+ toolTipText = _ref$toolTipText === void 0 ? '' : _ref$toolTipText,
1992
+ _ref$toolTipPosition = _ref.toolTipPosition,
1993
+ toolTipPosition = _ref$toolTipPosition === void 0 ? 'top' : _ref$toolTipPosition,
1994
+ _ref$bodyWidth = _ref.bodyWidth,
1995
+ bodyWidth = _ref$bodyWidth === void 0 ? '8em' : _ref$bodyWidth,
1996
+ _ref$apexWidth = _ref.apexWidth,
1997
+ apexWidth = _ref$apexWidth === void 0 ? '5px' : _ref$apexWidth,
1998
+ _ref$containerClassNa = _ref.containerClassName,
1999
+ containerClassName = _ref$containerClassNa === void 0 ? '' : _ref$containerClassNa,
2000
+ _ref$bodyClassName = _ref.bodyClassName,
2001
+ bodyClassName = _ref$bodyClassName === void 0 ? '' : _ref$bodyClassName;
2002
+ return /*#__PURE__*/React.createElement(Container, {
2003
+ className: containerClassName
2004
+ }, children, /*#__PURE__*/React.createElement(Body, {
2005
+ $toolTipPosition: toolTipPosition,
2006
+ $bodyWidth: bodyWidth,
2007
+ $apexWidth: apexWidth,
2008
+ className: bodyClassName
2009
+ }, toolTipText));
2010
+ };
2011
+
2012
+ var Tooltip$1 = themed(Tooltip);
2013
+
2014
+ var CurrencySelect = function CurrencySelect(_ref) {
2015
+ var currency = _ref.currency,
2016
+ currencyOptions = _ref.currencyOptions,
2017
+ onCurrencyChange = _ref.onCurrencyChange,
2018
+ _ref$isCurrencySelect = _ref.isCurrencySelectionDisabled,
2019
+ isCurrencySelectionDisabled = _ref$isCurrencySelect === void 0 ? false : _ref$isCurrencySelect,
2020
+ _ref$tooltipContent = _ref.tooltipContent,
2021
+ tooltipContent = _ref$tooltipContent === void 0 ? '' : _ref$tooltipContent;
2022
+
2023
+ if (!currencyOptions || currencyOptions.length === 0) {
2024
+ return null;
630
2025
  }
631
2026
 
632
- function createSubject() {
633
- let _observers = [];
634
- const next = (value) => {
635
- for (const observer of _observers) {
636
- observer.next && observer.next(value);
637
- }
638
- };
639
- const subscribe = (observer) => {
640
- _observers.push(observer);
641
- return {
642
- unsubscribe: () => {
643
- _observers = _observers.filter((o) => o !== observer);
644
- },
645
- };
646
- };
647
- const unsubscribe = () => {
648
- _observers = [];
649
- };
650
- return {
651
- get observers() {
652
- return _observers;
653
- },
654
- next,
655
- subscribe,
656
- unsubscribe,
657
- };
658
- }
659
-
660
- var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
2027
+ var selectedOption = currencyOptions.find(function (opt) {
2028
+ return opt.value === currency;
2029
+ });
661
2030
 
662
- function deepEqual(object1, object2) {
663
- if (isPrimitive(object1) || isPrimitive(object2)) {
664
- return object1 === object2;
665
- }
666
- if (isDateObject(object1) && isDateObject(object2)) {
667
- return object1.getTime() === object2.getTime();
668
- }
669
- const keys1 = Object.keys(object1);
670
- const keys2 = Object.keys(object2);
671
- if (keys1.length !== keys2.length) {
672
- return false;
673
- }
674
- for (const key of keys1) {
675
- const val1 = object1[key];
676
- if (!keys2.includes(key)) {
677
- return false;
678
- }
679
- if (key !== 'ref') {
680
- const val2 = object2[key];
681
- if ((isDateObject(val1) && isDateObject(val2)) ||
682
- (isObject(val1) && isObject(val2)) ||
683
- (Array.isArray(val1) && Array.isArray(val2))
684
- ? !deepEqual(val1, val2)
685
- : val1 !== val2) {
686
- return false;
687
- }
688
- }
689
- }
690
- return true;
2031
+ if (!selectedOption) {
2032
+ return null;
691
2033
  }
692
2034
 
693
- var isMultipleSelect = (element) => element.type === `select-multiple`;
694
-
695
- var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
696
-
697
- var live = (ref) => isHTMLElement(ref) && ref.isConnected;
698
-
699
- var objectHasFunction = (data) => {
700
- for (const key in data) {
701
- if (isFunction(data[key])) {
702
- return true;
703
- }
704
- }
705
- return false;
2035
+ return /*#__PURE__*/React.createElement(Tooltip$1, {
2036
+ toolTipText: isCurrencySelectionDisabled ? tooltipContent : '',
2037
+ toolTipPosition: "bottom",
2038
+ bodyWidth: "160px"
2039
+ }, /*#__PURE__*/React.createElement("div", {
2040
+ className: "currency-select-container ".concat(isCurrencySelectionDisabled ? 'disabled' : '')
2041
+ }, /*#__PURE__*/React.createElement("div", {
2042
+ className: "currency-flag"
2043
+ }, /*#__PURE__*/React.createElement("img", {
2044
+ src: selectedOption.flagSrc,
2045
+ alt: "".concat(currency, " flag")
2046
+ })), /*#__PURE__*/React.createElement("select", {
2047
+ value: currency,
2048
+ onChange: function onChange(e) {
2049
+ return onCurrencyChange(e.target.value);
2050
+ },
2051
+ className: "currency-select",
2052
+ disabled: isCurrencySelectionDisabled
2053
+ }, currencyOptions.map(function (option) {
2054
+ return /*#__PURE__*/React.createElement("option", {
2055
+ key: option.value,
2056
+ value: option.value
2057
+ }, option.value, " (", option.symbol, ")");
2058
+ }))));
2059
+ };
2060
+
2061
+ var LuxityFooter = function LuxityFooter(_ref) {
2062
+ var _ref$showNewsletter = _ref.showNewsletter,
2063
+ showNewsletter = _ref$showNewsletter === void 0 ? true : _ref$showNewsletter,
2064
+ _ref$buyLinks = _ref.buyLinks,
2065
+ buyLinks = _ref$buyLinks === void 0 ? [] : _ref$buyLinks,
2066
+ _ref$sellLinks = _ref.sellLinks,
2067
+ sellLinks = _ref$sellLinks === void 0 ? [] : _ref$sellLinks,
2068
+ _ref$companyLinks = _ref.companyLinks,
2069
+ companyLinks = _ref$companyLinks === void 0 ? [] : _ref$companyLinks,
2070
+ _ref$storeLinks = _ref.storeLinks,
2071
+ storeLinks = _ref$storeLinks === void 0 ? [] : _ref$storeLinks,
2072
+ _ref$popularLinks = _ref.popularLinks,
2073
+ popularLinks = _ref$popularLinks === void 0 ? [] : _ref$popularLinks,
2074
+ _ref$socialLinks = _ref.socialLinks,
2075
+ socialLinks = _ref$socialLinks === void 0 ? [] : _ref$socialLinks,
2076
+ _ref$contactLinks = _ref.contactLinks,
2077
+ contactLinks = _ref$contactLinks === void 0 ? [] : _ref$contactLinks,
2078
+ visaImgSrc = _ref.visaImgSrc,
2079
+ masterCardSrc = _ref.masterCardSrc,
2080
+ logoSrc = _ref.logoSrc,
2081
+ formIconSrc = _ref.formIconSrc,
2082
+ onSubmit = _ref.onSubmit,
2083
+ currency = _ref.currency,
2084
+ currencyOptions = _ref.currencyOptions,
2085
+ onCurrencyChange = _ref.onCurrencyChange,
2086
+ isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
2087
+ tooltipContent = _ref.tooltipContent;
2088
+ var currentYear = new Date().getFullYear();
2089
+
2090
+ var _useForm = useForm(),
2091
+ handleSubmit = _useForm.handleSubmit,
2092
+ register = _useForm.register,
2093
+ errors = _useForm.formState.errors,
2094
+ reset = _useForm.reset,
2095
+ setError = _useForm.setError;
2096
+
2097
+ var renderLinks = function renderLinks(links, title) {
2098
+ return !!links.length && /*#__PURE__*/React.createElement("div", {
2099
+ className: "footer__link-container"
2100
+ }, /*#__PURE__*/React.createElement("div", {
2101
+ className: "footer__link-title"
2102
+ }, title), /*#__PURE__*/React.createElement("div", {
2103
+ className: "footer__links"
2104
+ }, links.map(function (link) {
2105
+ return /*#__PURE__*/React.createElement("div", {
2106
+ className: "footer__link-wrapper",
2107
+ key: link.label
2108
+ }, link.icon && /*#__PURE__*/React.createElement("img", {
2109
+ className: "footer__link-icon",
2110
+ src: link.icon,
2111
+ alt: link.label
2112
+ }), /*#__PURE__*/React.createElement(GALink, {
2113
+ instance: link.instance,
2114
+ href: link.href,
2115
+ label: link.label,
2116
+ className: "footer__link",
2117
+ rel: "noopener noreferrer",
2118
+ track: link === null || link === void 0 ? void 0 : link.track,
2119
+ target: link.target
2120
+ }, link.iconClassName && /*#__PURE__*/React.createElement("i", {
2121
+ className: link.iconClassName
2122
+ }), link.label));
2123
+ })));
706
2124
  };
707
2125
 
708
- function markFieldsDirty(data, fields = {}) {
709
- const isParentNodeArray = Array.isArray(data);
710
- if (isObject(data) || isParentNodeArray) {
711
- for (const key in data) {
712
- if (Array.isArray(data[key]) ||
713
- (isObject(data[key]) && !objectHasFunction(data[key]))) {
714
- fields[key] = Array.isArray(data[key]) ? [] : {};
715
- markFieldsDirty(data[key], fields[key]);
716
- }
717
- else if (!isNullOrUndefined(data[key])) {
718
- fields[key] = true;
719
- }
720
- }
721
- }
722
- return fields;
723
- }
724
- function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
725
- const isParentNodeArray = Array.isArray(data);
726
- if (isObject(data) || isParentNodeArray) {
727
- for (const key in data) {
728
- if (Array.isArray(data[key]) ||
729
- (isObject(data[key]) && !objectHasFunction(data[key]))) {
730
- if (isUndefined(formValues) ||
731
- isPrimitive(dirtyFieldsFromValues[key])) {
732
- dirtyFieldsFromValues[key] = Array.isArray(data[key])
733
- ? markFieldsDirty(data[key], [])
734
- : { ...markFieldsDirty(data[key]) };
735
- }
736
- else {
737
- getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
738
- }
739
- }
740
- else {
741
- dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
742
- }
743
- }
744
- }
745
- return dirtyFieldsFromValues;
746
- }
747
- var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
748
-
749
- var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
750
- ? value
751
- : valueAsNumber
752
- ? value === ''
753
- ? NaN
754
- : value
755
- ? +value
756
- : value
757
- : valueAsDate && isString(value)
758
- ? new Date(value)
759
- : setValueAs
760
- ? setValueAs(value)
761
- : value;
762
-
763
- function getFieldValue(_f) {
764
- const ref = _f.ref;
765
- if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
766
- return;
767
- }
768
- if (isFileInput(ref)) {
769
- return ref.files;
770
- }
771
- if (isRadioInput(ref)) {
772
- return getRadioValue(_f.refs).value;
773
- }
774
- if (isMultipleSelect(ref)) {
775
- return [...ref.selectedOptions].map(({ value }) => value);
776
- }
777
- if (isCheckBoxInput(ref)) {
778
- return getCheckboxValue(_f.refs).value;
779
- }
780
- return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
781
- }
782
-
783
- var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
784
- const fields = {};
785
- for (const name of fieldsNames) {
786
- const field = get(_fields, name);
787
- field && set(fields, name, field._f);
788
- }
789
- return {
790
- criteriaMode,
791
- names: [...fieldsNames],
792
- fields,
793
- shouldUseNativeValidation,
794
- };
2126
+ var renderSocialLinks = function renderSocialLinks(links) {
2127
+ return /*#__PURE__*/React.createElement("div", {
2128
+ className: "footer__link-container"
2129
+ }, /*#__PURE__*/React.createElement("div", {
2130
+ className: "flex gap-2 mb-5"
2131
+ }, links.map(function (link) {
2132
+ return /*#__PURE__*/React.createElement("a", {
2133
+ key: link.label,
2134
+ href: link.href,
2135
+ target: "_blank",
2136
+ rel: "noopener noreferrer",
2137
+ className: ""
2138
+ }, link.icon && /*#__PURE__*/React.createElement("img", {
2139
+ className: "footer__link-icon",
2140
+ src: link.icon,
2141
+ alt: link.label,
2142
+ width: 30,
2143
+ height: 30
2144
+ }));
2145
+ })), /*#__PURE__*/React.createElement("div", {
2146
+ className: "footer__links"
2147
+ }, !!contactLinks.map && contactLinks.map(function (link) {
2148
+ return !link.isContact ? /*#__PURE__*/React.createElement(GALink, {
2149
+ key: link.label,
2150
+ instance: link.instance,
2151
+ href: link.href,
2152
+ label: link.label,
2153
+ className: "footer__link",
2154
+ rel: "noopener noreferrer",
2155
+ track: link === null || link === void 0 ? void 0 : link.track,
2156
+ target: link.target
2157
+ }, link.label) : /*#__PURE__*/React.createElement("div", {
2158
+ key: link.label,
2159
+ className: "footer__text"
2160
+ }, link.label);
2161
+ })));
795
2162
  };
796
2163
 
797
- var getRuleValue = (rule) => isUndefined(rule)
798
- ? rule
799
- : isRegex(rule)
800
- ? rule.source
801
- : isObject(rule)
802
- ? isRegex(rule.value)
803
- ? rule.value.source
804
- : rule.value
805
- : rule;
806
-
807
- var hasValidation = (options) => options.mount &&
808
- (options.required ||
809
- options.min ||
810
- options.max ||
811
- options.maxLength ||
812
- options.minLength ||
813
- options.pattern ||
814
- options.validate);
815
-
816
- function schemaErrorLookup(errors, _fields, name) {
817
- const error = get(errors, name);
818
- if (error || isKey(name)) {
819
- return {
820
- error,
821
- name,
822
- };
2164
+ var AccordionSection = function AccordionSection(_ref2) {
2165
+ var title = _ref2.title,
2166
+ links = _ref2.links;
2167
+
2168
+ var _useState = useState(false),
2169
+ _useState2 = _slicedToArray(_useState, 2),
2170
+ isOpen = _useState2[0],
2171
+ setIsOpen = _useState2[1];
2172
+
2173
+ var contentRef = useRef(null);
2174
+ return /*#__PURE__*/React.createElement("div", {
2175
+ className: "border-b border-gray-200"
2176
+ }, /*#__PURE__*/React.createElement("button", {
2177
+ type: "button",
2178
+ className: "w-full py-3 px-3 flex justify-between items-center",
2179
+ onClick: function onClick() {
2180
+ return setIsOpen(!isOpen);
823
2181
  }
824
- const names = name.split('.');
825
- while (names.length) {
826
- const fieldName = names.join('.');
827
- const field = get(_fields, fieldName);
828
- const foundError = get(errors, fieldName);
829
- if (field && !Array.isArray(field) && name !== fieldName) {
830
- return { name };
831
- }
832
- if (foundError && foundError.type) {
833
- return {
834
- name: fieldName,
835
- error: foundError,
836
- };
837
- }
838
- names.pop();
839
- }
840
- return {
841
- name,
842
- };
843
- }
844
-
845
- var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
846
- if (mode.isOnAll) {
847
- return false;
2182
+ }, /*#__PURE__*/React.createElement("span", {
2183
+ className: "footer__link-title"
2184
+ }, title), /*#__PURE__*/React.createElement("span", null, isOpen ? '-' : '+')), /*#__PURE__*/React.createElement("div", {
2185
+ ref: contentRef,
2186
+ className: "px-3 overflow-hidden transition-all duration-500 ease-in-out",
2187
+ style: {
2188
+ maxHeight: isOpen ? "".concat(contentRef.current.scrollHeight, "px") : '0'
848
2189
  }
849
- else if (!isSubmitted && mode.isOnTouch) {
850
- return !(isTouched || isBlurEvent);
851
- }
852
- else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
853
- return !isBlurEvent;
854
- }
855
- else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
856
- return isBlurEvent;
857
- }
858
- return true;
2190
+ }, links.map(function (link) {
2191
+ return /*#__PURE__*/React.createElement("a", {
2192
+ key: link.label,
2193
+ href: link.href,
2194
+ className: "footer__link block"
2195
+ }, link.label);
2196
+ })));
859
2197
  };
860
2198
 
861
- var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
862
-
863
- const defaultOptions = {
864
- mode: VALIDATION_MODE.onSubmit,
865
- reValidateMode: VALIDATION_MODE.onChange,
866
- shouldFocusError: true,
867
- };
868
- function createFormControl(props = {}, flushRootRender) {
869
- let _options = {
870
- ...defaultOptions,
871
- ...props,
872
- };
873
- let _formState = {
874
- submitCount: 0,
875
- isDirty: false,
876
- isLoading: isFunction(_options.defaultValues),
877
- isValidating: false,
878
- isSubmitted: false,
879
- isSubmitting: false,
880
- isSubmitSuccessful: false,
881
- isValid: false,
882
- touchedFields: {},
883
- dirtyFields: {},
884
- errors: {},
885
- };
886
- let _fields = {};
887
- let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
888
- ? cloneObject(_options.defaultValues || _options.values) || {}
889
- : {};
890
- let _formValues = _options.shouldUnregister
891
- ? {}
892
- : cloneObject(_defaultValues);
893
- let _state = {
894
- action: false,
895
- mount: false,
896
- watch: false,
897
- };
898
- let _names = {
899
- mount: new Set(),
900
- unMount: new Set(),
901
- array: new Set(),
902
- watch: new Set(),
903
- };
904
- let delayErrorCallback;
905
- let timer = 0;
906
- const _proxyFormState = {
907
- isDirty: false,
908
- dirtyFields: false,
909
- touchedFields: false,
910
- isValidating: false,
911
- isValid: false,
912
- errors: false,
913
- };
914
- const _subjects = {
915
- values: createSubject(),
916
- array: createSubject(),
917
- state: createSubject(),
918
- };
919
- const shouldCaptureDirtyFields = props.resetOptions && props.resetOptions.keepDirtyValues;
920
- const validationModeBeforeSubmit = getValidationModes(_options.mode);
921
- const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
922
- const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
923
- const debounce = (callback) => (wait) => {
924
- clearTimeout(timer);
925
- timer = setTimeout(callback, wait);
926
- };
927
- const _updateValid = async (shouldUpdateValid) => {
928
- if (_proxyFormState.isValid || shouldUpdateValid) {
929
- const isValid = _options.resolver
930
- ? isEmptyObject((await _executeSchema()).errors)
931
- : await executeBuiltInValidation(_fields, true);
932
- if (isValid !== _formState.isValid) {
933
- _subjects.state.next({
934
- isValid,
935
- });
936
- }
937
- }
938
- };
939
- const _updateIsValidating = (value) => _proxyFormState.isValidating &&
940
- _subjects.state.next({
941
- isValidating: value,
942
- });
943
- const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
944
- if (args && method) {
945
- _state.action = true;
946
- if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
947
- const fieldValues = method(get(_fields, name), args.argA, args.argB);
948
- shouldSetValues && set(_fields, name, fieldValues);
949
- }
950
- if (shouldUpdateFieldsAndState &&
951
- Array.isArray(get(_formState.errors, name))) {
952
- const errors = method(get(_formState.errors, name), args.argA, args.argB);
953
- shouldSetValues && set(_formState.errors, name, errors);
954
- unsetEmptyArray(_formState.errors, name);
955
- }
956
- if (_proxyFormState.touchedFields &&
957
- shouldUpdateFieldsAndState &&
958
- Array.isArray(get(_formState.touchedFields, name))) {
959
- const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
960
- shouldSetValues && set(_formState.touchedFields, name, touchedFields);
961
- }
962
- if (_proxyFormState.dirtyFields) {
963
- _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
964
- }
965
- _subjects.state.next({
966
- name,
967
- isDirty: _getDirty(name, values),
968
- dirtyFields: _formState.dirtyFields,
969
- errors: _formState.errors,
970
- isValid: _formState.isValid,
971
- });
972
- }
973
- else {
974
- set(_formValues, name, values);
975
- }
976
- };
977
- const updateErrors = (name, error) => {
978
- set(_formState.errors, name, error);
979
- _subjects.state.next({
980
- errors: _formState.errors,
981
- });
982
- };
983
- const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
984
- const field = get(_fields, name);
985
- if (field) {
986
- const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
987
- isUndefined(defaultValue) ||
988
- (ref && ref.defaultChecked) ||
989
- shouldSkipSetValueAs
990
- ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
991
- : setFieldValue(name, defaultValue);
992
- _state.mount && _updateValid();
993
- }
994
- };
995
- const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
996
- let shouldUpdateField = false;
997
- let isPreviousDirty = false;
998
- const output = {
999
- name,
1000
- };
1001
- if (!isBlurEvent || shouldDirty) {
1002
- if (_proxyFormState.isDirty) {
1003
- isPreviousDirty = _formState.isDirty;
1004
- _formState.isDirty = output.isDirty = _getDirty();
1005
- shouldUpdateField = isPreviousDirty !== output.isDirty;
1006
- }
1007
- const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1008
- isPreviousDirty = get(_formState.dirtyFields, name);
1009
- isCurrentFieldPristine
1010
- ? unset(_formState.dirtyFields, name)
1011
- : set(_formState.dirtyFields, name, true);
1012
- output.dirtyFields = _formState.dirtyFields;
1013
- shouldUpdateField =
1014
- shouldUpdateField ||
1015
- (_proxyFormState.dirtyFields &&
1016
- isPreviousDirty !== !isCurrentFieldPristine);
1017
- }
1018
- if (isBlurEvent) {
1019
- const isPreviousFieldTouched = get(_formState.touchedFields, name);
1020
- if (!isPreviousFieldTouched) {
1021
- set(_formState.touchedFields, name, isBlurEvent);
1022
- output.touchedFields = _formState.touchedFields;
1023
- shouldUpdateField =
1024
- shouldUpdateField ||
1025
- (_proxyFormState.touchedFields &&
1026
- isPreviousFieldTouched !== isBlurEvent);
1027
- }
1028
- }
1029
- shouldUpdateField && shouldRender && _subjects.state.next(output);
1030
- return shouldUpdateField ? output : {};
1031
- };
1032
- const shouldRenderByError = (name, isValid, error, fieldState) => {
1033
- const previousFieldError = get(_formState.errors, name);
1034
- const shouldUpdateValid = _proxyFormState.isValid &&
1035
- isBoolean(isValid) &&
1036
- _formState.isValid !== isValid;
1037
- if (props.delayError && error) {
1038
- delayErrorCallback = debounce(() => updateErrors(name, error));
1039
- delayErrorCallback(props.delayError);
1040
- }
1041
- else {
1042
- clearTimeout(timer);
1043
- delayErrorCallback = null;
1044
- error
1045
- ? set(_formState.errors, name, error)
1046
- : unset(_formState.errors, name);
1047
- }
1048
- if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
1049
- !isEmptyObject(fieldState) ||
1050
- shouldUpdateValid) {
1051
- const updatedFormState = {
1052
- ...fieldState,
1053
- ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
1054
- errors: _formState.errors,
1055
- name,
1056
- };
1057
- _formState = {
1058
- ..._formState,
1059
- ...updatedFormState,
1060
- };
1061
- _subjects.state.next(updatedFormState);
1062
- }
1063
- _updateIsValidating(false);
1064
- };
1065
- const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1066
- const executeSchemaAndUpdateState = async (names) => {
1067
- const { errors } = await _executeSchema(names);
1068
- if (names) {
1069
- for (const name of names) {
1070
- const error = get(errors, name);
1071
- error
1072
- ? set(_formState.errors, name, error)
1073
- : unset(_formState.errors, name);
1074
- }
1075
- }
1076
- else {
1077
- _formState.errors = errors;
1078
- }
1079
- return errors;
1080
- };
1081
- const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
1082
- valid: true,
1083
- }) => {
1084
- for (const name in fields) {
1085
- const field = fields[name];
1086
- if (field) {
1087
- const { _f, ...fieldValue } = field;
1088
- if (_f) {
1089
- const isFieldArrayRoot = _names.array.has(_f.name);
1090
- const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1091
- if (fieldError[_f.name]) {
1092
- context.valid = false;
1093
- if (shouldOnlyCheckValid) {
1094
- break;
1095
- }
1096
- }
1097
- !shouldOnlyCheckValid &&
1098
- (get(fieldError, _f.name)
1099
- ? isFieldArrayRoot
1100
- ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name)
1101
- : set(_formState.errors, _f.name, fieldError[_f.name])
1102
- : unset(_formState.errors, _f.name));
1103
- }
1104
- fieldValue &&
1105
- (await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
1106
- }
1107
- }
1108
- return context.valid;
1109
- };
1110
- const _removeUnmounted = () => {
1111
- for (const name of _names.unMount) {
1112
- const field = get(_fields, name);
1113
- field &&
1114
- (field._f.refs
1115
- ? field._f.refs.every((ref) => !live(ref))
1116
- : !live(field._f.ref)) &&
1117
- unregister(name);
1118
- }
1119
- _names.unMount = new Set();
1120
- };
1121
- const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
1122
- !deepEqual(getValues(), _defaultValues));
1123
- const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1124
- ...(_state.mount
1125
- ? _formValues
1126
- : isUndefined(defaultValue)
1127
- ? _defaultValues
1128
- : isString(names)
1129
- ? { [names]: defaultValue }
1130
- : defaultValue),
1131
- }, isGlobal, defaultValue);
1132
- const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
1133
- const setFieldValue = (name, value, options = {}) => {
1134
- const field = get(_fields, name);
1135
- let fieldValue = value;
1136
- if (field) {
1137
- const fieldReference = field._f;
1138
- if (fieldReference) {
1139
- !fieldReference.disabled &&
1140
- set(_formValues, name, getFieldValueAs(value, fieldReference));
1141
- fieldValue =
1142
- isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
1143
- ? ''
1144
- : value;
1145
- if (isMultipleSelect(fieldReference.ref)) {
1146
- [...fieldReference.ref.options].forEach((optionRef) => (optionRef.selected = fieldValue.includes(optionRef.value)));
1147
- }
1148
- else if (fieldReference.refs) {
1149
- if (isCheckBoxInput(fieldReference.ref)) {
1150
- fieldReference.refs.length > 1
1151
- ? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) &&
1152
- (checkboxRef.checked = Array.isArray(fieldValue)
1153
- ? !!fieldValue.find((data) => data === checkboxRef.value)
1154
- : fieldValue === checkboxRef.value))
1155
- : fieldReference.refs[0] &&
1156
- (fieldReference.refs[0].checked = !!fieldValue);
1157
- }
1158
- else {
1159
- fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
1160
- }
1161
- }
1162
- else if (isFileInput(fieldReference.ref)) {
1163
- fieldReference.ref.value = '';
1164
- }
1165
- else {
1166
- fieldReference.ref.value = fieldValue;
1167
- if (!fieldReference.ref.type) {
1168
- _subjects.values.next({
1169
- name,
1170
- values: { ..._formValues },
1171
- });
1172
- }
1173
- }
1174
- }
1175
- }
1176
- (options.shouldDirty || options.shouldTouch) &&
1177
- updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
1178
- options.shouldValidate && trigger(name);
1179
- };
1180
- const setValues = (name, value, options) => {
1181
- for (const fieldKey in value) {
1182
- const fieldValue = value[fieldKey];
1183
- const fieldName = `${name}.${fieldKey}`;
1184
- const field = get(_fields, fieldName);
1185
- (_names.array.has(name) ||
1186
- !isPrimitive(fieldValue) ||
1187
- (field && !field._f)) &&
1188
- !isDateObject(fieldValue)
1189
- ? setValues(fieldName, fieldValue, options)
1190
- : setFieldValue(fieldName, fieldValue, options);
1191
- }
1192
- };
1193
- const setValue = (name, value, options = {}) => {
1194
- const field = get(_fields, name);
1195
- const isFieldArray = _names.array.has(name);
1196
- const cloneValue = cloneObject(value);
1197
- set(_formValues, name, cloneValue);
1198
- if (isFieldArray) {
1199
- _subjects.array.next({
1200
- name,
1201
- values: { ..._formValues },
1202
- });
1203
- if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
1204
- options.shouldDirty) {
1205
- _subjects.state.next({
1206
- name,
1207
- dirtyFields: getDirtyFields(_defaultValues, _formValues),
1208
- isDirty: _getDirty(name, cloneValue),
1209
- });
1210
- }
1211
- }
1212
- else {
1213
- field && !field._f && !isNullOrUndefined(cloneValue)
1214
- ? setValues(name, cloneValue, options)
1215
- : setFieldValue(name, cloneValue, options);
1216
- }
1217
- isWatched(name, _names) && _subjects.state.next({ ..._formState });
1218
- _subjects.values.next({
1219
- name,
1220
- values: { ..._formValues },
1221
- });
1222
- !_state.mount && flushRootRender();
1223
- };
1224
- const onChange = async (event) => {
1225
- const target = event.target;
1226
- let name = target.name;
1227
- let isFieldValueUpdated = true;
1228
- const field = get(_fields, name);
1229
- const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1230
- if (field) {
1231
- let error;
1232
- let isValid;
1233
- const fieldValue = getCurrentFieldValue();
1234
- const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1235
- const shouldSkipValidation = (!hasValidation(field._f) &&
1236
- !_options.resolver &&
1237
- !get(_formState.errors, name) &&
1238
- !field._f.deps) ||
1239
- skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
1240
- const watched = isWatched(name, _names, isBlurEvent);
1241
- set(_formValues, name, fieldValue);
1242
- if (isBlurEvent) {
1243
- field._f.onBlur && field._f.onBlur(event);
1244
- delayErrorCallback && delayErrorCallback(0);
1245
- }
1246
- else if (field._f.onChange) {
1247
- field._f.onChange(event);
1248
- }
1249
- const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
1250
- const shouldRender = !isEmptyObject(fieldState) || watched;
1251
- !isBlurEvent &&
1252
- _subjects.values.next({
1253
- name,
1254
- type: event.type,
1255
- values: { ..._formValues },
1256
- });
1257
- if (shouldSkipValidation) {
1258
- _proxyFormState.isValid && _updateValid();
1259
- return (shouldRender &&
1260
- _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1261
- }
1262
- !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1263
- _updateIsValidating(true);
1264
- if (_options.resolver) {
1265
- const { errors } = await _executeSchema([name]);
1266
- const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1267
- const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1268
- error = errorLookupResult.error;
1269
- name = errorLookupResult.name;
1270
- isValid = isEmptyObject(errors);
1271
- }
1272
- else {
1273
- error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1274
- isFieldValueUpdated =
1275
- isNaN(fieldValue) ||
1276
- fieldValue === get(_formValues, name, fieldValue);
1277
- if (isFieldValueUpdated) {
1278
- if (error) {
1279
- isValid = false;
1280
- }
1281
- else if (_proxyFormState.isValid) {
1282
- isValid = await executeBuiltInValidation(_fields, true);
1283
- }
1284
- }
1285
- }
1286
- if (isFieldValueUpdated) {
1287
- field._f.deps &&
1288
- trigger(field._f.deps);
1289
- shouldRenderByError(name, isValid, error, fieldState);
1290
- }
1291
- }
1292
- };
1293
- const trigger = async (name, options = {}) => {
1294
- let isValid;
1295
- let validationResult;
1296
- const fieldNames = convertToArrayPayload(name);
1297
- _updateIsValidating(true);
1298
- if (_options.resolver) {
1299
- const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1300
- isValid = isEmptyObject(errors);
1301
- validationResult = name
1302
- ? !fieldNames.some((name) => get(errors, name))
1303
- : isValid;
1304
- }
1305
- else if (name) {
1306
- validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
1307
- const field = get(_fields, fieldName);
1308
- return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
1309
- }))).every(Boolean);
1310
- !(!validationResult && !_formState.isValid) && _updateValid();
1311
- }
1312
- else {
1313
- validationResult = isValid = await executeBuiltInValidation(_fields);
1314
- }
1315
- _subjects.state.next({
1316
- ...(!isString(name) ||
1317
- (_proxyFormState.isValid && isValid !== _formState.isValid)
1318
- ? {}
1319
- : { name }),
1320
- ...(_options.resolver || !name ? { isValid } : {}),
1321
- errors: _formState.errors,
1322
- isValidating: false,
1323
- });
1324
- options.shouldFocus &&
1325
- !validationResult &&
1326
- focusFieldBy(_fields, (key) => key && get(_formState.errors, key), name ? fieldNames : _names.mount);
1327
- return validationResult;
1328
- };
1329
- const getValues = (fieldNames) => {
1330
- const values = {
1331
- ..._defaultValues,
1332
- ...(_state.mount ? _formValues : {}),
1333
- };
1334
- return isUndefined(fieldNames)
1335
- ? values
1336
- : isString(fieldNames)
1337
- ? get(values, fieldNames)
1338
- : fieldNames.map((name) => get(values, name));
1339
- };
1340
- const getFieldState = (name, formState) => ({
1341
- invalid: !!get((formState || _formState).errors, name),
1342
- isDirty: !!get((formState || _formState).dirtyFields, name),
1343
- isTouched: !!get((formState || _formState).touchedFields, name),
1344
- error: get((formState || _formState).errors, name),
1345
- });
1346
- const clearErrors = (name) => {
1347
- name &&
1348
- convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
1349
- _subjects.state.next({
1350
- errors: name ? _formState.errors : {},
1351
- });
1352
- };
1353
- const setError = (name, error, options) => {
1354
- const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1355
- set(_formState.errors, name, {
1356
- ...error,
1357
- ref,
1358
- });
1359
- _subjects.state.next({
1360
- name,
1361
- errors: _formState.errors,
1362
- isValid: false,
1363
- });
1364
- options && options.shouldFocus && ref && ref.focus && ref.focus();
1365
- };
1366
- const watch = (name, defaultValue) => isFunction(name)
1367
- ? _subjects.values.subscribe({
1368
- next: (payload) => name(_getWatch(undefined, defaultValue), payload),
1369
- })
1370
- : _getWatch(name, defaultValue, true);
1371
- const unregister = (name, options = {}) => {
1372
- for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
1373
- _names.mount.delete(fieldName);
1374
- _names.array.delete(fieldName);
1375
- if (!options.keepValue) {
1376
- unset(_fields, fieldName);
1377
- unset(_formValues, fieldName);
1378
- }
1379
- !options.keepError && unset(_formState.errors, fieldName);
1380
- !options.keepDirty && unset(_formState.dirtyFields, fieldName);
1381
- !options.keepTouched && unset(_formState.touchedFields, fieldName);
1382
- !_options.shouldUnregister &&
1383
- !options.keepDefaultValue &&
1384
- unset(_defaultValues, fieldName);
1385
- }
1386
- _subjects.values.next({
1387
- values: { ..._formValues },
1388
- });
1389
- _subjects.state.next({
1390
- ..._formState,
1391
- ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
1392
- });
1393
- !options.keepIsValid && _updateValid();
1394
- };
1395
- const _updateDisabledField = ({ disabled, name, field, fields, }) => {
1396
- if (isBoolean(disabled)) {
1397
- const value = disabled
1398
- ? undefined
1399
- : get(_formValues, name, getFieldValue(field ? field._f : get(fields, name)._f));
1400
- set(_formValues, name, value);
1401
- updateTouchAndDirty(name, value, false, false, true);
1402
- }
1403
- };
1404
- const register = (name, options = {}) => {
1405
- let field = get(_fields, name);
1406
- const disabledIsDefined = isBoolean(options.disabled);
1407
- set(_fields, name, {
1408
- ...(field || {}),
1409
- _f: {
1410
- ...(field && field._f ? field._f : { ref: { name } }),
1411
- name,
1412
- mount: true,
1413
- ...options,
1414
- },
1415
- });
1416
- _names.mount.add(name);
1417
- if (field) {
1418
- _updateDisabledField({
1419
- field,
1420
- disabled: options.disabled,
1421
- name,
1422
- });
1423
- }
1424
- else {
1425
- updateValidAndValue(name, true, options.value);
1426
- }
1427
- return {
1428
- ...(disabledIsDefined ? { disabled: options.disabled } : {}),
1429
- ...(_options.progressive
1430
- ? {
1431
- required: !!options.required,
1432
- min: getRuleValue(options.min),
1433
- max: getRuleValue(options.max),
1434
- minLength: getRuleValue(options.minLength),
1435
- maxLength: getRuleValue(options.maxLength),
1436
- pattern: getRuleValue(options.pattern),
1437
- }
1438
- : {}),
1439
- name,
1440
- onChange,
1441
- onBlur: onChange,
1442
- ref: (ref) => {
1443
- if (ref) {
1444
- register(name, options);
1445
- field = get(_fields, name);
1446
- const fieldRef = isUndefined(ref.value)
1447
- ? ref.querySelectorAll
1448
- ? ref.querySelectorAll('input,select,textarea')[0] || ref
1449
- : ref
1450
- : ref;
1451
- const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
1452
- const refs = field._f.refs || [];
1453
- if (radioOrCheckbox
1454
- ? refs.find((option) => option === fieldRef)
1455
- : fieldRef === field._f.ref) {
1456
- return;
1457
- }
1458
- set(_fields, name, {
1459
- _f: {
1460
- ...field._f,
1461
- ...(radioOrCheckbox
1462
- ? {
1463
- refs: [
1464
- ...refs.filter(live),
1465
- fieldRef,
1466
- ...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
1467
- ],
1468
- ref: { type: fieldRef.type, name },
1469
- }
1470
- : { ref: fieldRef }),
1471
- },
1472
- });
1473
- updateValidAndValue(name, false, undefined, fieldRef);
1474
- }
1475
- else {
1476
- field = get(_fields, name, {});
1477
- if (field._f) {
1478
- field._f.mount = false;
1479
- }
1480
- (_options.shouldUnregister || options.shouldUnregister) &&
1481
- !(isNameInFieldArray(_names.array, name) && _state.action) &&
1482
- _names.unMount.add(name);
1483
- }
1484
- },
1485
- };
1486
- };
1487
- const _focusError = () => _options.shouldFocusError &&
1488
- focusFieldBy(_fields, (key) => key && get(_formState.errors, key), _names.mount);
1489
- const handleSubmit = (onValid, onInvalid) => async (e) => {
1490
- if (e) {
1491
- e.preventDefault && e.preventDefault();
1492
- e.persist && e.persist();
1493
- }
1494
- let fieldValues = cloneObject(_formValues);
1495
- _subjects.state.next({
1496
- isSubmitting: true,
1497
- });
1498
- if (_options.resolver) {
1499
- const { errors, values } = await _executeSchema();
1500
- _formState.errors = errors;
1501
- fieldValues = values;
1502
- }
1503
- else {
1504
- await executeBuiltInValidation(_fields);
1505
- }
1506
- unset(_formState.errors, 'root');
1507
- if (isEmptyObject(_formState.errors)) {
1508
- _subjects.state.next({
1509
- errors: {},
1510
- });
1511
- await onValid(fieldValues, e);
1512
- }
1513
- else {
1514
- if (onInvalid) {
1515
- await onInvalid({ ..._formState.errors }, e);
1516
- }
1517
- _focusError();
1518
- setTimeout(_focusError);
1519
- }
1520
- _subjects.state.next({
1521
- isSubmitted: true,
1522
- isSubmitting: false,
1523
- isSubmitSuccessful: isEmptyObject(_formState.errors),
1524
- submitCount: _formState.submitCount + 1,
1525
- errors: _formState.errors,
1526
- });
1527
- };
1528
- const resetField = (name, options = {}) => {
1529
- if (get(_fields, name)) {
1530
- if (isUndefined(options.defaultValue)) {
1531
- setValue(name, get(_defaultValues, name));
1532
- }
1533
- else {
1534
- setValue(name, options.defaultValue);
1535
- set(_defaultValues, name, options.defaultValue);
1536
- }
1537
- if (!options.keepTouched) {
1538
- unset(_formState.touchedFields, name);
1539
- }
1540
- if (!options.keepDirty) {
1541
- unset(_formState.dirtyFields, name);
1542
- _formState.isDirty = options.defaultValue
1543
- ? _getDirty(name, get(_defaultValues, name))
1544
- : _getDirty();
1545
- }
1546
- if (!options.keepError) {
1547
- unset(_formState.errors, name);
1548
- _proxyFormState.isValid && _updateValid();
1549
- }
1550
- _subjects.state.next({ ..._formState });
1551
- }
1552
- };
1553
- const _reset = (formValues, keepStateOptions = {}) => {
1554
- const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
1555
- const cloneUpdatedValues = cloneObject(updatedValues);
1556
- const values = formValues && !isEmptyObject(formValues)
1557
- ? cloneUpdatedValues
1558
- : _defaultValues;
1559
- if (!keepStateOptions.keepDefaultValues) {
1560
- _defaultValues = updatedValues;
1561
- }
1562
- if (!keepStateOptions.keepValues) {
1563
- if (keepStateOptions.keepDirtyValues || shouldCaptureDirtyFields) {
1564
- for (const fieldName of _names.mount) {
1565
- get(_formState.dirtyFields, fieldName)
1566
- ? set(values, fieldName, get(_formValues, fieldName))
1567
- : setValue(fieldName, get(values, fieldName));
1568
- }
1569
- }
1570
- else {
1571
- if (isWeb && isUndefined(formValues)) {
1572
- for (const name of _names.mount) {
1573
- const field = get(_fields, name);
1574
- if (field && field._f) {
1575
- const fieldReference = Array.isArray(field._f.refs)
1576
- ? field._f.refs[0]
1577
- : field._f.ref;
1578
- if (isHTMLElement(fieldReference)) {
1579
- const form = fieldReference.closest('form');
1580
- if (form) {
1581
- form.reset();
1582
- break;
1583
- }
1584
- }
1585
- }
1586
- }
1587
- }
1588
- _fields = {};
1589
- }
1590
- _formValues = props.shouldUnregister
1591
- ? keepStateOptions.keepDefaultValues
1592
- ? cloneObject(_defaultValues)
1593
- : {}
1594
- : cloneObject(values);
1595
- _subjects.array.next({
1596
- values: { ...values },
1597
- });
1598
- _subjects.values.next({
1599
- values: { ...values },
1600
- });
1601
- }
1602
- _names = {
1603
- mount: new Set(),
1604
- unMount: new Set(),
1605
- array: new Set(),
1606
- watch: new Set(),
1607
- watchAll: false,
1608
- focus: '',
1609
- };
1610
- !_state.mount && flushRootRender();
1611
- _state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
1612
- _state.watch = !!props.shouldUnregister;
1613
- _subjects.state.next({
1614
- submitCount: keepStateOptions.keepSubmitCount
1615
- ? _formState.submitCount
1616
- : 0,
1617
- isDirty: keepStateOptions.keepDirty
1618
- ? _formState.isDirty
1619
- : !!(keepStateOptions.keepDefaultValues &&
1620
- !deepEqual(formValues, _defaultValues)),
1621
- isSubmitted: keepStateOptions.keepIsSubmitted
1622
- ? _formState.isSubmitted
1623
- : false,
1624
- dirtyFields: keepStateOptions.keepDirtyValues
1625
- ? _formState.dirtyFields
1626
- : keepStateOptions.keepDefaultValues && formValues
1627
- ? getDirtyFields(_defaultValues, formValues)
1628
- : {},
1629
- touchedFields: keepStateOptions.keepTouched
1630
- ? _formState.touchedFields
1631
- : {},
1632
- errors: keepStateOptions.keepErrors ? _formState.errors : {},
1633
- isSubmitting: false,
1634
- isSubmitSuccessful: false,
1635
- });
1636
- };
1637
- const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
1638
- ? formValues(_formValues)
1639
- : formValues, keepStateOptions);
1640
- const setFocus = (name, options = {}) => {
1641
- const field = get(_fields, name);
1642
- const fieldReference = field && field._f;
1643
- if (fieldReference) {
1644
- const fieldRef = fieldReference.refs
1645
- ? fieldReference.refs[0]
1646
- : fieldReference.ref;
1647
- if (fieldRef.focus) {
1648
- fieldRef.focus();
1649
- options.shouldSelect && fieldRef.select();
1650
- }
1651
- }
1652
- };
1653
- const _updateFormState = (updatedFormState) => {
1654
- _formState = {
1655
- ..._formState,
1656
- ...updatedFormState,
1657
- };
1658
- };
1659
- const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
1660
- _options.defaultValues().then((values) => {
1661
- reset(values, _options.resetOptions);
1662
- _subjects.state.next({
1663
- isLoading: false,
1664
- });
1665
- });
1666
- return {
1667
- control: {
1668
- register,
1669
- unregister,
1670
- getFieldState,
1671
- handleSubmit,
1672
- setError,
1673
- _executeSchema,
1674
- _getWatch,
1675
- _getDirty,
1676
- _updateValid,
1677
- _removeUnmounted,
1678
- _updateFieldArray,
1679
- _updateDisabledField,
1680
- _getFieldArray,
1681
- _reset,
1682
- _resetDefaultValues,
1683
- _updateFormState,
1684
- _subjects,
1685
- _proxyFormState,
1686
- get _fields() {
1687
- return _fields;
1688
- },
1689
- get _formValues() {
1690
- return _formValues;
1691
- },
1692
- get _state() {
1693
- return _state;
1694
- },
1695
- set _state(value) {
1696
- _state = value;
1697
- },
1698
- get _defaultValues() {
1699
- return _defaultValues;
1700
- },
1701
- get _names() {
1702
- return _names;
1703
- },
1704
- set _names(value) {
1705
- _names = value;
1706
- },
1707
- get _formState() {
1708
- return _formState;
1709
- },
1710
- set _formState(value) {
1711
- _formState = value;
1712
- },
1713
- get _options() {
1714
- return _options;
1715
- },
1716
- set _options(value) {
1717
- _options = {
1718
- ..._options,
1719
- ...value,
1720
- };
1721
- },
1722
- },
1723
- trigger,
1724
- register,
1725
- handleSubmit,
1726
- watch,
1727
- setValue,
1728
- getValues,
1729
- reset,
1730
- resetField,
1731
- clearErrors,
1732
- unregister,
1733
- setError,
1734
- setFocus,
1735
- getFieldState,
1736
- };
1737
- }
1738
-
1739
- /**
1740
- * Custom hook to manage the entire form.
1741
- *
1742
- * @remarks
1743
- * [API](https://react-hook-form.com/docs/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
1744
- *
1745
- * @param props - form configuration and validation parameters.
1746
- *
1747
- * @returns methods - individual functions to manage the form state. {@link UseFormReturn}
1748
- *
1749
- * @example
1750
- * ```tsx
1751
- * function App() {
1752
- * const { register, handleSubmit, watch, formState: { errors } } = useForm();
1753
- * const onSubmit = data => console.log(data);
1754
- *
1755
- * console.log(watch("example"));
1756
- *
1757
- * return (
1758
- * <form onSubmit={handleSubmit(onSubmit)}>
1759
- * <input defaultValue="test" {...register("example")} />
1760
- * <input {...register("exampleRequired", { required: true })} />
1761
- * {errors.exampleRequired && <span>This field is required</span>}
1762
- * <button>Submit</button>
1763
- * </form>
1764
- * );
1765
- * }
1766
- * ```
1767
- */
1768
- function useForm(props = {}) {
1769
- const _formControl = React__default.useRef();
1770
- const _values = React__default.useRef();
1771
- const [formState, updateFormState] = React__default.useState({
1772
- isDirty: false,
1773
- isValidating: false,
1774
- isLoading: isFunction(props.defaultValues),
1775
- isSubmitted: false,
1776
- isSubmitting: false,
1777
- isSubmitSuccessful: false,
1778
- isValid: false,
1779
- submitCount: 0,
1780
- dirtyFields: {},
1781
- touchedFields: {},
1782
- errors: {},
1783
- defaultValues: isFunction(props.defaultValues)
1784
- ? undefined
1785
- : props.defaultValues,
1786
- });
1787
- if (!_formControl.current) {
1788
- _formControl.current = {
1789
- ...createFormControl(props, () => updateFormState((formState) => ({ ...formState }))),
1790
- formState,
1791
- };
2199
+ var submitForm = function submitForm(data) {
2200
+ onSubmit(data).then(function (res) {
2201
+ if (res.success) {
2202
+ reset();
2203
+ } else {
2204
+ setError('email', {
2205
+ type: 'custom',
2206
+ message: res.errorMessage
2207
+ });
1792
2208
  }
1793
- const control = _formControl.current.control;
1794
- control._options = props;
1795
- useSubscribe({
1796
- subject: control._subjects.state,
1797
- next: (value) => {
1798
- if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
1799
- updateFormState({ ...control._formState });
1800
- }
1801
- },
1802
- });
1803
- React__default.useEffect(() => {
1804
- if (props.values && !deepEqual(props.values, _values.current)) {
1805
- control._reset(props.values, control._options.resetOptions);
1806
- _values.current = props.values;
1807
- }
1808
- else {
1809
- control._resetDefaultValues();
1810
- }
1811
- }, [props.values, control]);
1812
- React__default.useEffect(() => {
1813
- if (!control._state.mount) {
1814
- control._updateValid();
1815
- control._state.mount = true;
1816
- }
1817
- if (control._state.watch) {
1818
- control._state.watch = false;
1819
- control._subjects.state.next({ ...control._formState });
1820
- }
1821
- control._removeUnmounted();
1822
- });
1823
- _formControl.current.formState = getProxyFormState(formState, control);
1824
- return _formControl.current;
1825
- }
1826
-
1827
- var theme = {
1828
- breakpoints: ['40em', '52em', '64em'],
1829
- space: ['0px', '4px', '8px', '16px', '32px', '64px', '128px', '256px', '512px'],
1830
- fontSizes: ['12px', '14px', '16px', '20px', '24px', '32px', '48px', '64px', '72px'],
1831
- marginPaddings: ['0.5rem', '1rem', '1.5rem', '2rem', '2.5rem', '3rem', '3.5rem', '4rem', '4.5rem', '5rem', '5.5rem', '6rem'],
1832
- letterSpacings: ['-0.5px', '0px', '+0.5px'],
1833
- radii: ['0px', '2px', '4px', '8px'],
1834
- borderRadius: '6px',
1835
- colors: {
1836
- primary: '#000',
1837
- base: '#4e4949',
1838
- baseLt: '#817c7c',
1839
- borderColor: '#d8d8d8',
1840
- ntrlMin: '#fff',
1841
- ntrlMinTen: '#e6e6e6',
1842
- gray: '#efefef',
1843
- darkerGray: '#454141'
1844
- },
1845
- rareStepColors: {
1846
- primary: '#202b58',
1847
- secondary: '#ef5c2d',
1848
- ntrlMin: '#ffffff',
1849
- ntrl40: '#f4f4f4',
1850
- ntrl50: '#808080',
1851
- ntrl60: '#e8e8e8',
1852
- ntrl70: '#252525',
1853
- ntrlMax: '#000000'
1854
- },
1855
- rareStepFontWeights: {
1856
- normal: 400,
1857
- medium: 500,
1858
- semiBold: 600,
1859
- bold: 700
1860
- },
1861
- rareStepFontSize: {
1862
- h1: '36px',
1863
- h2: '30px',
1864
- h3: '24px',
1865
- h4: '20px',
1866
- h5: '16px',
1867
- h6: '14px',
1868
- footerTitle: '16px'
1869
- },
1870
- rareStepPageSizes: {
1871
- mobile: '500px',
1872
- tablet: '768px',
1873
- desktop: '992px',
1874
- screenl: '1280px',
1875
- screenxl: '1680px',
1876
- screenxxl: '1920px',
1877
- container: '1600px'
1878
- }
1879
- };
1880
-
1881
- var themed = (function (Component) {
1882
- return /*#__PURE__*/React.forwardRef(function (props, ref) {
1883
- return /*#__PURE__*/React__default.createElement(styled.ThemeProvider, {
1884
- theme: theme
1885
- }, /*#__PURE__*/React__default.createElement(Component, _extends({}, props, {
1886
- ref: ref
1887
- })));
1888
2209
  });
1889
- });
1890
-
1891
- var _templateObject;
1892
- var FooterWrapper = styled__default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n {\n background-color: ", ";\n }\n"])), function (props) {
1893
- return props.theme.colors.gray;
1894
- });
1895
-
1896
- var Event = function Event(instance, track) {
1897
- var category = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
1898
- var action = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
1899
- var label = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
1900
- var value = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
1901
-
1902
- if (track) {
1903
- instance.event({
1904
- category: category,
1905
- action: action,
1906
- label: label,
1907
- value: value
1908
- });
1909
- }
1910
- };
1911
-
1912
- var GALink = function GALink(props) {
1913
- var gaOnClick = function gaOnClick(event) {
1914
- Event(props.instance, props.track, 'Link', "Click on ".concat(props.href), props.label);
1915
-
1916
- if (typeof props.onClick === 'function') {
1917
- props.onClick(event);
1918
- }
1919
- };
1920
-
1921
- return /*#__PURE__*/React__default.createElement("a", _extends({
1922
- href: "/"
1923
- }, props, {
1924
- onClick: gaOnClick
1925
- }), props.children);
1926
- };
1927
-
1928
- var _templateObject$1, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
1929
- /* position relative is required for the Body element to be positioned correctly */
1930
-
1931
- var relativeInlineStyle = styled.css(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n position: relative;\n"])));
1932
- var topMiddleBodyStyle = styled.css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n z-index: 1;\n bottom: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n"])));
1933
- var getTopMiddleArrowAfterStyle = function getTopMiddleArrowAfterStyle(props) {
1934
- return styled.css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n /*Bottom Arrow*/\n top: 100%; /* At the bottom of the tooltip */\n left: calc(50% - ", ");\n border-width: ", ";\n border-style: solid;\n border-color: ", " transparent transparent transparent;\n"])), props.$apexWidth, props.$apexWidth, props.theme.colors.base);
1935
- };
1936
- var getBottomMiddleBodyStyle = function getBottomMiddleBodyStyle(props) {
1937
- return styled.css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n top: 100%;\n left: calc(50% - ", " / 2);\n"])), props.$bodyWidth);
1938
- };
1939
- var getBottomMiddleArrowAfterStyle = function getBottomMiddleArrowAfterStyle(props) {
1940
- return styled.css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n /*Top Arrow*/\n bottom: 100%; /* At the top of the tooltip */\n top: initial;\n left: 50%;\n border-style: solid;\n border-color: transparent transparent ", " transparent;\n"])), props.theme.colors.base);
1941
- };
1942
-
1943
- var _templateObject$2;
1944
-
1945
- var getBodyStyle = function getBodyStyle() {
1946
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1947
- var _props$$toolTipPositi = props.$toolTipPosition,
1948
- $toolTipPosition = _props$$toolTipPositi === void 0 ? '' : _props$$toolTipPositi;
1949
-
1950
- switch ($toolTipPosition) {
1951
- case 'top':
1952
- return topMiddleBodyStyle;
1953
-
1954
- case 'bottom':
1955
- return getBottomMiddleBodyStyle(props);
1956
-
1957
- default:
1958
- return null;
1959
- }
1960
2210
  };
1961
2211
 
1962
- var getAfterStyling = function getAfterStyling() {
1963
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1964
- var $toolTipPosition = props.$toolTipPosition;
1965
-
1966
- switch ($toolTipPosition) {
1967
- case 'top':
1968
- return getTopMiddleArrowAfterStyle(props);
1969
-
1970
- case 'bottom':
1971
- return getBottomMiddleArrowAfterStyle(props);
1972
-
1973
- default:
1974
- return '';
2212
+ return /*#__PURE__*/React.createElement(FooterWrapper, null, showNewsletter && /*#__PURE__*/React.createElement("div", {
2213
+ className: "footer__newsletter-section"
2214
+ }, /*#__PURE__*/React.createElement("div", {
2215
+ className: "footer__newsletter-wrapper"
2216
+ }, /*#__PURE__*/React.createElement("div", {
2217
+ className: "footer__title-wrapper"
2218
+ }, /*#__PURE__*/React.createElement("div", {
2219
+ className: "footer__newsletter-title"
2220
+ }, "Sign up for our newsletter"), /*#__PURE__*/React.createElement("p", {
2221
+ className: "footer__newsletter-text"
2222
+ }, "By signing up you agree to our terms & conditions and privacy policy. You can unsubscribe anytime.")), /*#__PURE__*/React.createElement("div", {
2223
+ className: "footer__newsletter-form"
2224
+ }, /*#__PURE__*/React.createElement("form", {
2225
+ onSubmit: handleSubmit(submitForm)
2226
+ }, /*#__PURE__*/React.createElement("input", _extends({}, register('email', {
2227
+ required: 'The email field is required.',
2228
+ pattern: {
2229
+ value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
2230
+ message: 'Invalid email address'
1975
2231
  }
1976
- };
1977
-
1978
- var Body = styled__default.span(_templateObject$2 || (_templateObject$2 = _taggedTemplateLiteral(["\n ", ";\n visibility: hidden;\n opacity: 0;\n width: ", ";\n transition: visibility 0.3s linear, opacity 0.3s linear;\n background-color: ", ";\n color: white;\n text-align: center;\n border-radius: 5px;\n ", "\n &::after {\n content: ' ';\n position: absolute;\n ", "\n }\n"])), relativeInlineStyle, function (props) {
1979
- return props.$bodyWidth;
1980
- }, function (props) {
1981
- return props.theme.colors.base || 'black';
1982
- }, function (props) {
1983
- return getBodyStyle(props);
1984
- }, function (props) {
1985
- return getAfterStyling(props);
1986
- });
1987
-
1988
- var _templateObject$3;
1989
- var Container = styled__default.div(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteral(["\n ", ";\n cursor: pointer;\n &:hover ", " {\n opacity: 1;\n visibility: visible;\n }\n"])), relativeInlineStyle, Body);
1990
-
1991
- /* eslint-disable react/require-default-props */
1992
-
1993
- var Tooltip = function Tooltip(_ref) {
1994
- var _ref$children = _ref.children,
1995
- children = _ref$children === void 0 ? null : _ref$children,
1996
- _ref$toolTipText = _ref.toolTipText,
1997
- toolTipText = _ref$toolTipText === void 0 ? '' : _ref$toolTipText,
1998
- _ref$toolTipPosition = _ref.toolTipPosition,
1999
- toolTipPosition = _ref$toolTipPosition === void 0 ? 'top' : _ref$toolTipPosition,
2000
- _ref$bodyWidth = _ref.bodyWidth,
2001
- bodyWidth = _ref$bodyWidth === void 0 ? '8em' : _ref$bodyWidth,
2002
- _ref$apexWidth = _ref.apexWidth,
2003
- apexWidth = _ref$apexWidth === void 0 ? '5px' : _ref$apexWidth,
2004
- _ref$containerClassNa = _ref.containerClassName,
2005
- containerClassName = _ref$containerClassNa === void 0 ? '' : _ref$containerClassNa,
2006
- _ref$bodyClassName = _ref.bodyClassName,
2007
- bodyClassName = _ref$bodyClassName === void 0 ? '' : _ref$bodyClassName;
2008
- return /*#__PURE__*/React__default.createElement(Container, {
2009
- className: containerClassName
2010
- }, children, /*#__PURE__*/React__default.createElement(Body, {
2011
- $toolTipPosition: toolTipPosition,
2012
- $bodyWidth: bodyWidth,
2013
- $apexWidth: apexWidth,
2014
- className: bodyClassName
2015
- }, toolTipText));
2016
- };
2017
-
2018
- var Tooltip$1 = themed(Tooltip);
2019
-
2020
- var CurrencySelect = function CurrencySelect(_ref) {
2021
- var currency = _ref.currency,
2022
- currencyOptions = _ref.currencyOptions,
2023
- onCurrencyChange = _ref.onCurrencyChange,
2024
- _ref$isCurrencySelect = _ref.isCurrencySelectionDisabled,
2025
- isCurrencySelectionDisabled = _ref$isCurrencySelect === void 0 ? false : _ref$isCurrencySelect,
2026
- _ref$tooltipContent = _ref.tooltipContent,
2027
- tooltipContent = _ref$tooltipContent === void 0 ? '' : _ref$tooltipContent;
2028
-
2029
- if (!currencyOptions || currencyOptions.length === 0) {
2030
- return null;
2031
- }
2032
-
2033
- var selectedOption = currencyOptions.find(function (opt) {
2034
- return opt.value === currency;
2035
- });
2036
-
2037
- if (!selectedOption) {
2038
- return null;
2039
- }
2040
-
2041
- return /*#__PURE__*/React__default.createElement(Tooltip$1, {
2042
- toolTipText: isCurrencySelectionDisabled ? tooltipContent : '',
2043
- toolTipPosition: "bottom",
2044
- bodyWidth: "160px"
2045
- }, /*#__PURE__*/React__default.createElement("div", {
2046
- className: "currency-select-container ".concat(isCurrencySelectionDisabled ? 'disabled' : '')
2047
- }, /*#__PURE__*/React__default.createElement("div", {
2048
- className: "currency-flag"
2049
- }, /*#__PURE__*/React__default.createElement("img", {
2050
- src: selectedOption.flagSrc,
2051
- alt: "".concat(currency, " flag")
2052
- })), /*#__PURE__*/React__default.createElement("select", {
2053
- value: currency,
2054
- onChange: function onChange(e) {
2055
- return onCurrencyChange(e.target.value);
2056
- },
2057
- className: "currency-select",
2058
- disabled: isCurrencySelectionDisabled
2059
- }, currencyOptions.map(function (option) {
2060
- return /*#__PURE__*/React__default.createElement("option", {
2061
- key: option.value,
2062
- value: option.value
2063
- }, option.value, " (", option.symbol, ")");
2064
- }))));
2065
- };
2066
-
2067
- var LuxityFooter = function LuxityFooter(_ref) {
2068
- var _ref$showNewsletter = _ref.showNewsletter,
2069
- showNewsletter = _ref$showNewsletter === void 0 ? true : _ref$showNewsletter,
2070
- _ref$buyLinks = _ref.buyLinks,
2071
- buyLinks = _ref$buyLinks === void 0 ? [] : _ref$buyLinks,
2072
- _ref$sellLinks = _ref.sellLinks,
2073
- sellLinks = _ref$sellLinks === void 0 ? [] : _ref$sellLinks,
2074
- _ref$companyLinks = _ref.companyLinks,
2075
- companyLinks = _ref$companyLinks === void 0 ? [] : _ref$companyLinks,
2076
- _ref$storeLinks = _ref.storeLinks,
2077
- storeLinks = _ref$storeLinks === void 0 ? [] : _ref$storeLinks,
2078
- _ref$popularLinks = _ref.popularLinks,
2079
- popularLinks = _ref$popularLinks === void 0 ? [] : _ref$popularLinks,
2080
- _ref$socialLinks = _ref.socialLinks,
2081
- socialLinks = _ref$socialLinks === void 0 ? [] : _ref$socialLinks,
2082
- _ref$contactLinks = _ref.contactLinks,
2083
- contactLinks = _ref$contactLinks === void 0 ? [] : _ref$contactLinks,
2084
- visaImgSrc = _ref.visaImgSrc,
2085
- masterCardSrc = _ref.masterCardSrc,
2086
- logoSrc = _ref.logoSrc,
2087
- formIconSrc = _ref.formIconSrc,
2088
- onSubmit = _ref.onSubmit,
2089
- currency = _ref.currency,
2090
- currencyOptions = _ref.currencyOptions,
2091
- onCurrencyChange = _ref.onCurrencyChange,
2092
- isCurrencySelectionDisabled = _ref.isCurrencySelectionDisabled,
2093
- tooltipContent = _ref.tooltipContent;
2094
- var currentYear = new Date().getFullYear();
2095
-
2096
- var _useForm = useForm(),
2097
- handleSubmit = _useForm.handleSubmit,
2098
- register = _useForm.register,
2099
- errors = _useForm.formState.errors,
2100
- reset = _useForm.reset,
2101
- setError = _useForm.setError;
2102
-
2103
- var renderLinks = function renderLinks(links, title) {
2104
- return !!links.length && /*#__PURE__*/React__default.createElement("div", {
2105
- className: "footer__link-container"
2106
- }, /*#__PURE__*/React__default.createElement("div", {
2107
- className: "footer__link-title"
2108
- }, title), /*#__PURE__*/React__default.createElement("div", {
2109
- className: "footer__links"
2110
- }, links.map(function (link) {
2111
- return /*#__PURE__*/React__default.createElement("div", {
2112
- className: "footer__link-wrapper",
2113
- key: link.label
2114
- }, link.icon && /*#__PURE__*/React__default.createElement("img", {
2115
- className: "footer__link-icon",
2116
- src: link.icon,
2117
- alt: link.label
2118
- }), /*#__PURE__*/React__default.createElement(GALink, {
2119
- instance: link.instance,
2120
- href: link.href,
2121
- label: link.label,
2122
- className: "footer__link",
2123
- rel: "noopener noreferrer",
2124
- track: link === null || link === void 0 ? void 0 : link.track,
2125
- target: link.target
2126
- }, link.iconClassName && /*#__PURE__*/React__default.createElement("i", {
2127
- className: link.iconClassName
2128
- }), link.label));
2129
- })));
2130
- };
2131
-
2132
- var renderSocialLinks = function renderSocialLinks(links) {
2133
- return /*#__PURE__*/React__default.createElement("div", {
2134
- className: "footer__link-container"
2135
- }, /*#__PURE__*/React__default.createElement("div", {
2136
- className: "flex gap-2 mb-5"
2137
- }, links.map(function (link) {
2138
- return /*#__PURE__*/React__default.createElement("a", {
2139
- key: link.label,
2140
- href: link.href,
2141
- target: "_blank",
2142
- rel: "noopener noreferrer",
2143
- className: ""
2144
- }, link.icon && /*#__PURE__*/React__default.createElement("img", {
2145
- className: "footer__link-icon",
2146
- src: link.icon,
2147
- alt: link.label,
2148
- width: 30,
2149
- height: 30
2150
- }));
2151
- })), /*#__PURE__*/React__default.createElement("div", {
2152
- className: "footer__links"
2153
- }, !!contactLinks.map && contactLinks.map(function (link) {
2154
- return !link.isContact ? /*#__PURE__*/React__default.createElement(GALink, {
2155
- key: link.label,
2156
- instance: link.instance,
2157
- href: link.href,
2158
- label: link.label,
2159
- className: "footer__link",
2160
- rel: "noopener noreferrer",
2161
- track: link === null || link === void 0 ? void 0 : link.track,
2162
- target: link.target
2163
- }, link.label) : /*#__PURE__*/React__default.createElement("div", {
2164
- key: link.label,
2165
- className: "footer__text"
2166
- }, link.label);
2167
- })));
2168
- };
2169
-
2170
- var AccordionSection = function AccordionSection(_ref2) {
2171
- var title = _ref2.title,
2172
- links = _ref2.links;
2173
-
2174
- var _useState = React.useState(false),
2175
- _useState2 = _slicedToArray(_useState, 2),
2176
- isOpen = _useState2[0],
2177
- setIsOpen = _useState2[1];
2178
-
2179
- var contentRef = React.useRef(null);
2180
- return /*#__PURE__*/React__default.createElement("div", {
2181
- className: "border-b border-gray-200"
2182
- }, /*#__PURE__*/React__default.createElement("button", {
2183
- type: "button",
2184
- className: "w-full py-3 px-3 flex justify-between items-center",
2185
- onClick: function onClick() {
2186
- return setIsOpen(!isOpen);
2187
- }
2188
- }, /*#__PURE__*/React__default.createElement("span", {
2189
- className: "footer__link-title"
2190
- }, title), /*#__PURE__*/React__default.createElement("span", null, isOpen ? '-' : '+')), /*#__PURE__*/React__default.createElement("div", {
2191
- ref: contentRef,
2192
- className: "px-3 overflow-hidden transition-all duration-500 ease-in-out",
2193
- style: {
2194
- maxHeight: isOpen ? "".concat(contentRef.current.scrollHeight, "px") : '0'
2195
- }
2196
- }, links.map(function (link) {
2197
- return /*#__PURE__*/React__default.createElement("a", {
2198
- key: link.label,
2199
- href: link.href,
2200
- className: "footer__link block"
2201
- }, link.label);
2202
- })));
2203
- };
2204
-
2205
- var submitForm = function submitForm(data) {
2206
- onSubmit(data).then(function (res) {
2207
- if (res.success) {
2208
- reset();
2209
- } else {
2210
- setError('email', {
2211
- type: 'custom',
2212
- message: res.errorMessage
2213
- });
2214
- }
2215
- });
2216
- };
2217
-
2218
- return /*#__PURE__*/React__default.createElement(FooterWrapper, null, showNewsletter && /*#__PURE__*/React__default.createElement("div", {
2219
- className: "footer__newsletter-section"
2220
- }, /*#__PURE__*/React__default.createElement("div", {
2221
- className: "footer__newsletter-wrapper"
2222
- }, /*#__PURE__*/React__default.createElement("div", {
2223
- className: "footer__title-wrapper"
2224
- }, /*#__PURE__*/React__default.createElement("div", {
2225
- className: "footer__newsletter-title"
2226
- }, "Sign up for our newsletter"), /*#__PURE__*/React__default.createElement("p", {
2227
- className: "footer__newsletter-text"
2228
- }, "By signing up you agree to our terms & conditions and privacy policy. You can unsubscribe anytime.")), /*#__PURE__*/React__default.createElement("div", {
2229
- className: "footer__newsletter-form"
2230
- }, /*#__PURE__*/React__default.createElement("form", {
2231
- onSubmit: handleSubmit(submitForm)
2232
- }, /*#__PURE__*/React__default.createElement("input", _extends({}, register('email', {
2233
- required: 'The email field is required.',
2234
- pattern: {
2235
- value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
2236
- message: 'Invalid email address'
2237
- }
2238
- }), {
2239
- placeholder: "Your Sexy Email",
2240
- className: "footer__form-input"
2241
- })), errors.email && /*#__PURE__*/React__default.createElement("span", {
2242
- className: "footer__form-errors"
2243
- }, errors.email.message), /*#__PURE__*/React__default.createElement("button", {
2244
- type: "submit"
2245
- }, /*#__PURE__*/React__default.createElement("img", {
2246
- className: "footer__newsletter-icon",
2247
- src: formIconSrc,
2248
- alt: "submit"
2249
- })))))), /*#__PURE__*/React__default.createElement("div", {
2250
- className: "footer__wrapper footer__wrapper--desktop"
2251
- }, /*#__PURE__*/React__default.createElement("div", {
2252
- className: "footer__main-section"
2253
- }, /*#__PURE__*/React__default.createElement("div", {
2254
- className: "footer__logo-wrapper"
2255
- }, /*#__PURE__*/React__default.createElement("img", {
2256
- className: "footer__logo",
2257
- src: logoSrc,
2258
- alt: "luxity-logo"
2259
- })), renderLinks(buyLinks, 'Buy'), renderLinks(popularLinks, 'Popular'), renderLinks(sellLinks, 'Sell'), renderLinks(companyLinks, 'Company'), renderLinks(storeLinks, 'Connect'), renderSocialLinks(socialLinks)), /*#__PURE__*/React__default.createElement("div", {
2260
- className: "footer__copyrights-section"
2261
- }, /*#__PURE__*/React__default.createElement("div", {
2262
- className: "footer__payment-icons"
2263
- }, /*#__PURE__*/React__default.createElement("img", {
2264
- src: masterCardSrc,
2265
- alt: "mastercard",
2266
- width: 100,
2267
- height: 100
2268
- }), /*#__PURE__*/React__default.createElement("img", {
2269
- src: visaImgSrc,
2270
- alt: "visa",
2271
- width: 70,
2272
- height: 70
2273
- })), /*#__PURE__*/React__default.createElement("p", {
2274
- className: "footer__copyright"
2275
- }, "Copyright ", currentYear, " | Luxity (Pty) LTD | All Rights Reserved"))), /*#__PURE__*/React__default.createElement("div", {
2276
- className: "footer__wrapper footer__wrapper--mobile"
2277
- }, /*#__PURE__*/React__default.createElement(CurrencySelect, {
2278
- currency: currency,
2279
- currencyOptions: currencyOptions,
2280
- onCurrencyChange: onCurrencyChange,
2281
- isCurrencySelectionDisabled: isCurrencySelectionDisabled,
2282
- tooltipContent: tooltipContent
2283
- }), /*#__PURE__*/React__default.createElement(AccordionSection, {
2284
- title: "BUY",
2285
- links: buyLinks
2286
- }), /*#__PURE__*/React__default.createElement(AccordionSection, {
2287
- title: "POPULAR",
2288
- links: popularLinks
2289
- }), !!sellLinks.length && /*#__PURE__*/React__default.createElement(AccordionSection, {
2290
- title: "SELL",
2291
- links: sellLinks
2292
- }), /*#__PURE__*/React__default.createElement(AccordionSection, {
2293
- title: "COMPANY",
2294
- links: companyLinks
2295
- }), !!storeLinks.length && /*#__PURE__*/React__default.createElement(AccordionSection, {
2296
- title: "CONNECT",
2297
- links: storeLinks
2298
- }), /*#__PURE__*/React__default.createElement("div", {
2299
- className: "mt-5"
2300
- }, renderSocialLinks(socialLinks)), /*#__PURE__*/React__default.createElement("p", {
2301
- className: "footer__copyright footer__copyright--mobile"
2302
- }, "Copyright ", currentYear, " | Luxity (Pty) LTD | All Rights Reserved")));
2303
- };
2304
-
2305
- var index = themed(LuxityFooter);
2306
-
2307
- return index;
2308
-
2309
- })));
2232
+ }), {
2233
+ placeholder: "Your Sexy Email",
2234
+ className: "footer__form-input"
2235
+ })), errors.email && /*#__PURE__*/React.createElement("span", {
2236
+ className: "footer__form-errors"
2237
+ }, errors.email.message), /*#__PURE__*/React.createElement("button", {
2238
+ type: "submit"
2239
+ }, /*#__PURE__*/React.createElement("img", {
2240
+ className: "footer__newsletter-icon",
2241
+ src: formIconSrc,
2242
+ alt: "submit"
2243
+ })))))), /*#__PURE__*/React.createElement("div", {
2244
+ className: "footer__wrapper footer__wrapper--desktop"
2245
+ }, /*#__PURE__*/React.createElement("div", {
2246
+ className: "footer__main-section"
2247
+ }, /*#__PURE__*/React.createElement("div", {
2248
+ className: "footer__logo-wrapper"
2249
+ }, /*#__PURE__*/React.createElement("img", {
2250
+ className: "footer__logo",
2251
+ src: logoSrc,
2252
+ alt: "luxity-logo"
2253
+ })), renderLinks(buyLinks, 'Buy'), renderLinks(popularLinks, 'Popular'), renderLinks(sellLinks, 'Sell'), renderLinks(companyLinks, 'Company'), renderLinks(storeLinks, 'Connect'), renderSocialLinks(socialLinks)), /*#__PURE__*/React.createElement("div", {
2254
+ className: "footer__copyrights-section"
2255
+ }, /*#__PURE__*/React.createElement("div", {
2256
+ className: "footer__payment-icons"
2257
+ }, /*#__PURE__*/React.createElement("img", {
2258
+ src: masterCardSrc,
2259
+ alt: "mastercard",
2260
+ width: 100,
2261
+ height: 100
2262
+ }), /*#__PURE__*/React.createElement("img", {
2263
+ src: visaImgSrc,
2264
+ alt: "visa",
2265
+ width: 70,
2266
+ height: 70
2267
+ })), /*#__PURE__*/React.createElement("p", {
2268
+ className: "footer__copyright"
2269
+ }, "Copyright ", currentYear, " | Luxity (Pty) LTD | All Rights Reserved"))), /*#__PURE__*/React.createElement("div", {
2270
+ className: "footer__wrapper footer__wrapper--mobile"
2271
+ }, /*#__PURE__*/React.createElement(CurrencySelect, {
2272
+ currency: currency,
2273
+ currencyOptions: currencyOptions,
2274
+ onCurrencyChange: onCurrencyChange,
2275
+ isCurrencySelectionDisabled: isCurrencySelectionDisabled,
2276
+ tooltipContent: tooltipContent
2277
+ }), /*#__PURE__*/React.createElement(AccordionSection, {
2278
+ title: "BUY",
2279
+ links: buyLinks
2280
+ }), /*#__PURE__*/React.createElement(AccordionSection, {
2281
+ title: "POPULAR",
2282
+ links: popularLinks
2283
+ }), !!sellLinks.length && /*#__PURE__*/React.createElement(AccordionSection, {
2284
+ title: "SELL",
2285
+ links: sellLinks
2286
+ }), /*#__PURE__*/React.createElement(AccordionSection, {
2287
+ title: "COMPANY",
2288
+ links: companyLinks
2289
+ }), !!storeLinks.length && /*#__PURE__*/React.createElement(AccordionSection, {
2290
+ title: "CONNECT",
2291
+ links: storeLinks
2292
+ }), /*#__PURE__*/React.createElement("div", {
2293
+ className: "mt-5"
2294
+ }, renderSocialLinks(socialLinks)), /*#__PURE__*/React.createElement("p", {
2295
+ className: "footer__copyright footer__copyright--mobile"
2296
+ }, "Copyright ", currentYear, " | Luxity (Pty) LTD | All Rights Reserved")));
2297
+ };
2298
+
2299
+ var index = themed(LuxityFooter);
2300
+
2301
+ export default index;