@nuskin/shipping-address-form 1.7.8-state-dropdown.3 → 1.7.8-state-dropdown.4

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 (50) hide show
  1. package/dist/addressLookup/components/SmartyIntlResults.js +243 -1056
  2. package/dist/addressLookup/components/SmartyIntlResults.js.map +1 -1
  3. package/dist/addressLookup/components/SmartyUSResults.js +255 -1057
  4. package/dist/addressLookup/components/SmartyUSResults.js.map +1 -1
  5. package/dist/addressLookup/components/smartyResults/AddressFieldRow.js +155 -0
  6. package/dist/addressLookup/components/smartyResults/AddressFieldRow.js.map +1 -0
  7. package/dist/addressLookup/components/smartyResults/AddressMapModal.js +49 -0
  8. package/dist/addressLookup/components/smartyResults/AddressMapModal.js.map +1 -0
  9. package/dist/addressLookup/components/smartyResults/LookupActions.js +65 -0
  10. package/dist/addressLookup/components/smartyResults/LookupActions.js.map +1 -0
  11. package/dist/addressLookup/components/smartyResults/LookupResults.js +96 -0
  12. package/dist/addressLookup/components/smartyResults/LookupResults.js.map +1 -0
  13. package/dist/addressLookup/components/smartyResults/SuggestionList.js +40 -0
  14. package/dist/addressLookup/components/smartyResults/SuggestionList.js.map +1 -0
  15. package/dist/addressLookup/components/smartyResults/ValidationSuggestionList.js +53 -0
  16. package/dist/addressLookup/components/smartyResults/ValidationSuggestionList.js.map +1 -0
  17. package/dist/addressLookup/components/smartyResults/smartyResultsHandlers.js +286 -0
  18. package/dist/addressLookup/components/smartyResults/smartyResultsHandlers.js.map +1 -0
  19. package/dist/addressLookup/components/smartyResults/useSmartyAddressController.js +376 -0
  20. package/dist/addressLookup/components/smartyResults/useSmartyAddressController.js.map +1 -0
  21. package/dist/addressLookup/components/smartyResults/useSmartyResultsEffects.js +300 -0
  22. package/dist/addressLookup/components/smartyResults/useSmartyResultsEffects.js.map +1 -0
  23. package/dist/addressLookup/components/smartyResults/useSmartyServiceErrors.js +84 -0
  24. package/dist/addressLookup/components/smartyResults/useSmartyServiceErrors.js.map +1 -0
  25. package/dist/addressLookup/hooks/useAddressFieldValidation.js +113 -0
  26. package/dist/addressLookup/hooks/useAddressFieldValidation.js.map +1 -0
  27. package/dist/addressLookup/hooks/useSuggestionKeyboardNav.js +70 -0
  28. package/dist/addressLookup/hooks/useSuggestionKeyboardNav.js.map +1 -0
  29. package/dist/addressLookup/styles/addressLookup.css +19 -0
  30. package/dist/addressLookup/utils/addressMapping.js +5 -4
  31. package/dist/addressLookup/utils/addressMapping.js.map +1 -1
  32. package/dist/addressLookup/utils/addressStrings.js +2 -2
  33. package/dist/addressLookup/utils/addressStrings.js.map +1 -1
  34. package/dist/addressLookup/utils/smartyResultsFieldMeta.js +38 -0
  35. package/dist/addressLookup/utils/smartyResultsFieldMeta.js.map +1 -0
  36. package/dist/shippingAddressForm/ShippingAddressForm.js +39 -110
  37. package/dist/shippingAddressForm/ShippingAddressForm.js.map +1 -1
  38. package/dist/shippingAddressForm/components/CountrySelectorField.js +51 -0
  39. package/dist/shippingAddressForm/components/CountrySelectorField.js.map +1 -0
  40. package/dist/shippingAddressForm/components/ShippingCheckboxSection.js +71 -0
  41. package/dist/shippingAddressForm/components/ShippingCheckboxSection.js.map +1 -0
  42. package/dist/shippingAddressForm/components/ShippingFormActions.js +53 -0
  43. package/dist/shippingAddressForm/components/ShippingFormActions.js.map +1 -0
  44. package/dist/shippingAddressForm/components/shippingFormControls.js +31 -0
  45. package/dist/shippingAddressForm/components/shippingFormControls.js.map +1 -0
  46. package/dist/shippingAddressForm/hooks/useShippingFormState.js +1 -1
  47. package/dist/shippingAddressForm/hooks/useShippingFormState.js.map +1 -1
  48. package/dist/shippingAddressForm/utils/shippingStrings.js +3 -2
  49. package/dist/shippingAddressForm/utils/shippingStrings.js.map +1 -1
  50. package/package.json +1 -1
@@ -5,1074 +5,283 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
- var _react = require("react");
9
8
  var _useSmartyInternationalLookup = _interopRequireDefault(require("../hooks/useSmartyInternationalLookup"));
10
9
  var _useIntlAddressValidation = _interopRequireDefault(require("../hooks/useIntlAddressValidation"));
11
- var _useAddressFieldLabels = _interopRequireDefault(require("../hooks/useAddressFieldLabels"));
12
- var _useAddressForm = _interopRequireDefault(require("../hooks/useAddressForm"));
13
- var _useInitialAddressVerification = _interopRequireDefault(require("../hooks/useInitialAddressVerification"));
14
- var _useAddressMapModal = _interopRequireDefault(require("../hooks/useAddressMapModal"));
10
+ var _useSmartyAddressController = _interopRequireDefault(require("./smartyResults/useSmartyAddressController"));
15
11
  var _addressMapping = require("../utils/addressMapping");
16
12
  var _addressWrapper = require("../utils/addressWrapper");
17
13
  var _addressStatus = require("../utils/addressStatus");
18
- var _addressVerification = require("../utils/addressVerification");
19
- var _validators = require("../utils/validators");
20
- var _fieldValidation = require("../../utils/fieldValidation");
21
14
  var _componentPropTypes = require("../utils/componentPropTypes");
22
- var _LocationPinIcon = _interopRequireDefault(require("./LocationPinIcon"));
23
- var _foundationUiComponents = require("@nuskin/foundation-ui-components");
15
+ var _AddressFieldRow = _interopRequireDefault(require("./smartyResults/AddressFieldRow"));
16
+ var _LookupActions = _interopRequireDefault(require("./smartyResults/LookupActions"));
17
+ var _LookupResults = _interopRequireDefault(require("./smartyResults/LookupResults"));
18
+ var _AddressMapModal = _interopRequireDefault(require("./smartyResults/AddressMapModal"));
24
19
  var _jsxRuntime = require("react/jsx-runtime");
25
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
26
- const stripGeocode = (address = {}) => {
27
- const nextAddress = {
28
- ...address
29
- };
30
- delete nextAddress.latitude;
31
- delete nextAddress.longitude;
32
- return nextAddress;
21
+ const VALIDATION_RESULTS_VISIBLE_SOURCES = ['map', 'initial'];
22
+ const getLookupSuggestionKey = suggestion => suggestion.address_id || [suggestion.displayText, suggestion.street, suggestion.address_text, suggestion.locality, suggestion.administrative_area, suggestion.postal_code, suggestion.entries].filter(value => value !== undefined && value !== null).join('|');
23
+ const getValidationSuggestionKey = suggestion => {
24
+ var _suggestion$component, _suggestion$component2, _suggestion$component3, _suggestion$component4, _suggestion$component5;
25
+ return [suggestion.displayText, suggestion.address1, suggestion.address2, suggestion.address3, (_suggestion$component = suggestion.components) === null || _suggestion$component === void 0 ? void 0 : _suggestion$component.thoroughfare, (_suggestion$component2 = suggestion.components) === null || _suggestion$component2 === void 0 ? void 0 : _suggestion$component2.premise, (_suggestion$component3 = suggestion.components) === null || _suggestion$component3 === void 0 ? void 0 : _suggestion$component3.locality, (_suggestion$component4 = suggestion.components) === null || _suggestion$component4 === void 0 ? void 0 : _suggestion$component4.administrative_area, (_suggestion$component5 = suggestion.components) === null || _suggestion$component5 === void 0 ? void 0 : _suggestion$component5.postal_code].filter(value => value !== undefined && value !== null).join('|');
33
26
  };
34
- const FIELD_TEST_IDS = {
35
- address1: "qa-address1",
36
- address2: "qa-address2",
37
- district: "qa-address-county",
38
- region: "qa-address-region",
39
- city: "qa-address-city",
40
- postalCode: "qa-address-zip"
27
+ const getValidationSummaryTitle = (suggestion, fieldLabels) => {
28
+ var _suggestion$validatio, _suggestion$validatio2, _suggestion$validatio3, _suggestion$validatio4, _suggestion$validatio5, _suggestion$validatio6, _suggestion$validatio7;
29
+ const code = (_suggestion$validatio = suggestion.validationSummary) === null || _suggestion$validatio === void 0 ? void 0 : _suggestion$validatio.code;
30
+ switch (code) {
31
+ case 'verified':
32
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedTitle) || ((_suggestion$validatio2 = suggestion.validationSummary) === null || _suggestion$validatio2 === void 0 ? void 0 : _suggestion$validatio2.title) || 'Verified';
33
+ case 'verified-sub-building-changed':
34
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedSubBuildingChangedTitle) || ((_suggestion$validatio3 = suggestion.validationSummary) === null || _suggestion$validatio3 === void 0 ? void 0 : _suggestion$validatio3.title) || 'Verified with unit changes';
35
+ case 'partial':
36
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlPartialTitle) || ((_suggestion$validatio4 = suggestion.validationSummary) === null || _suggestion$validatio4 === void 0 ? void 0 : _suggestion$validatio4.title) || 'Partially verified';
37
+ case 'ambiguous':
38
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlAmbiguousTitle) || ((_suggestion$validatio5 = suggestion.validationSummary) === null || _suggestion$validatio5 === void 0 ? void 0 : _suggestion$validatio5.title) || 'Multiple matches found';
39
+ case 'not-verified':
40
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlNotVerifiedTitle) || ((_suggestion$validatio6 = suggestion.validationSummary) === null || _suggestion$validatio6 === void 0 ? void 0 : _suggestion$validatio6.title) || 'Not verified';
41
+ default:
42
+ return ((_suggestion$validatio7 = suggestion.validationSummary) === null || _suggestion$validatio7 === void 0 ? void 0 : _suggestion$validatio7.title) || 'Unknown';
43
+ }
41
44
  };
42
- const FIELD_IDS = {
43
- address1: 'address-address1',
44
- address2: 'address-address2',
45
- district: 'address-county',
46
- region: 'address-region',
47
- city: 'address-city',
48
- postalCode: 'address-zip'
45
+ const getValidationSummaryMessage = (suggestion, fieldLabels) => {
46
+ var _suggestion$validatio8, _suggestion$validatio9, _suggestion$validatio0, _suggestion$validatio1, _suggestion$validatio10, _suggestion$validatio11, _suggestion$validatio12;
47
+ const code = (_suggestion$validatio8 = suggestion.validationSummary) === null || _suggestion$validatio8 === void 0 ? void 0 : _suggestion$validatio8.code;
48
+ switch (code) {
49
+ case 'verified':
50
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedMessage) || ((_suggestion$validatio9 = suggestion.validationSummary) === null || _suggestion$validatio9 === void 0 ? void 0 : _suggestion$validatio9.message) || '';
51
+ case 'verified-sub-building-changed':
52
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedSubBuildingChangedMessage) || ((_suggestion$validatio0 = suggestion.validationSummary) === null || _suggestion$validatio0 === void 0 ? void 0 : _suggestion$validatio0.message) || '';
53
+ case 'partial':
54
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlPartialMessage) || ((_suggestion$validatio1 = suggestion.validationSummary) === null || _suggestion$validatio1 === void 0 ? void 0 : _suggestion$validatio1.message) || '';
55
+ case 'ambiguous':
56
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlAmbiguousMessage) || ((_suggestion$validatio10 = suggestion.validationSummary) === null || _suggestion$validatio10 === void 0 ? void 0 : _suggestion$validatio10.message) || '';
57
+ case 'not-verified':
58
+ return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlNotVerifiedMessage) || ((_suggestion$validatio11 = suggestion.validationSummary) === null || _suggestion$validatio11 === void 0 ? void 0 : _suggestion$validatio11.message) || '';
59
+ default:
60
+ return ((_suggestion$validatio12 = suggestion.validationSummary) === null || _suggestion$validatio12 === void 0 ? void 0 : _suggestion$validatio12.message) || '';
61
+ }
49
62
  };
50
- const getFieldTestId = field => FIELD_TEST_IDS[field] || `qa-address-${field}`;
51
- const getFieldId = field => FIELD_IDS[field] || `address-${field}`;
52
- const LOOKUP_LIST_BUTTON_SELECTOR = ".ns-address-lookup__list-button";
53
- const SmartyIntlResults = ({
54
- countryCode,
55
- onSelect,
56
- initialAddress = null,
57
- readOnlyView = false,
58
- validationRequestId = 0,
59
- language = "en",
60
- strings = null,
61
- formDefinition = null,
62
- deferFormLookup = false,
63
- showValidFields = false,
64
- suppressRequiredFieldsHint = false
65
- }) => {
66
- var _formDefinition$addre;
67
- const [mode, setMode] = (0, _react.useState)("autocomplete");
68
- const [query, setQuery] = (0, _react.useState)("");
69
- const [selectedAddress, setSelectedAddress] = (0, _react.useState)(null);
70
- const [selectedIntlAddressId, setSelectedIntlAddressId] = (0, _react.useState)(null);
71
- const [formData, setFormData] = (0, _react.useState)(initialAddress || {});
72
- const [verificationStatus, setVerificationStatus] = (0, _react.useState)((0, _addressVerification.getIncomingVerificationStatus)(initialAddress));
73
- const [customError, setCustomError] = (0, _react.useState)(null);
74
- const [validationTrigger, setValidationTrigger] = (0, _react.useState)(0);
75
- const [validationTriggerSource, setValidationTriggerSource] = (0, _react.useState)(null);
76
- const [showValidationSuggestions, setShowValidationSuggestions] = (0, _react.useState)(false);
77
- const [mapAddressLines, setMapAddressLines] = (0, _react.useState)([]);
78
- const [hasPendingLookupDraft, setHasPendingLookupDraft] = (0, _react.useState)(false);
79
- const [touchedFields, setTouchedFields] = (0, _react.useState)({});
80
- const [showAllRequiredErrors, setShowAllRequiredErrors] = (0, _react.useState)(false);
81
- const [lookupServiceError, setLookupServiceError] = (0, _react.useState)(null);
82
- const [validationServiceError, setValidationServiceError] = (0, _react.useState)(null);
83
- const shouldSearchRef = (0, _react.useRef)(true);
84
- const fieldTimerRef = (0, _react.useRef)(null);
85
- const componentRef = (0, _react.useRef)(null);
86
- const suggestionsListRef = (0, _react.useRef)(null);
87
- const lastCommittedAddressRef = (0, _react.useRef)(initialAddress || {});
88
- const lookupDraftOriginalRef = (0, _react.useRef)(initialAddress || {});
89
- const appliedSelectionKeyRef = (0, _react.useRef)(null);
90
- const mapValidationStartedRef = (0, _react.useRef)(false);
91
- const autoApplyValidationStartedRef = (0, _react.useRef)(false);
92
- const hasInitializedAddressRef = (0, _react.useRef)(false);
93
- (0, _react.useEffect)(() => {
94
- if (!initialAddress || hasInitializedAddressRef.current) {
95
- return;
96
- }
97
- hasInitializedAddressRef.current = true;
98
- setFormData(initialAddress);
99
- setVerificationStatus((0, _addressVerification.getIncomingVerificationStatus)(initialAddress));
100
- shouldSearchRef.current = false;
101
- lastCommittedAddressRef.current = initialAddress;
102
- lookupDraftOriginalRef.current = initialAddress;
103
- setTouchedFields({});
104
- setShowAllRequiredErrors(false);
105
- setLookupServiceError(null);
106
- setValidationServiceError(null);
107
- setMapAddressLines([]);
108
- }, [initialAddress]);
109
- (0, _react.useEffect)(() => {
110
- return () => {
111
- if (fieldTimerRef.current) {
112
- clearTimeout(fieldTimerRef.current);
113
- }
114
- };
115
- }, []);
116
- const isAutocompleteMode = mode === "autocomplete";
117
- const {
118
- labels: fieldLabels,
119
- isLoading: areLabelsLoading
120
- } = (0, _useAddressFieldLabels.default)(countryCode, language, strings);
121
- const shouldLoadAddressForm = !formDefinition && !deferFormLookup;
122
- const {
123
- addressForm: loadedAddressForm,
124
- isLoading: isFormLoading
125
- } = (0, _useAddressForm.default)(countryCode, shouldLoadAddressForm);
126
- const providedAddressForm = formDefinition !== null && formDefinition !== void 0 && (_formDefinition$addre = formDefinition.addressElements) !== null && _formDefinition$addre !== void 0 && _formDefinition$addre.length ? formDefinition : null;
127
- const resolvedAddressForm = providedAddressForm || loadedAddressForm;
128
- const entryMode = (resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.entryMode) || "both";
129
- const allowValidation = (resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.validationMode) !== "disabled" && !readOnlyView;
130
- const lookupField = (resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.lookupField) || "address1";
131
- (0, _react.useEffect)(() => {
132
- setMode(entryMode === "manual" ? "manual" : "autocomplete");
133
- }, [entryMode]);
134
- const requiredFields = (0, _addressStatus.getRequiredFieldsFromAddressForm)(resolvedAddressForm);
135
- const hasEmailField = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).some(field => field.field === "email");
136
- const hasMapCoordinates = (formData === null || formData === void 0 ? void 0 : formData.latitude) !== undefined && (formData === null || formData === void 0 ? void 0 : formData.longitude) !== undefined;
137
- const hasLookupValue = Boolean(String((formData === null || formData === void 0 ? void 0 : formData[lookupField]) || "").trim());
138
- const canAttemptMap = Boolean(!isAutocompleteMode && hasLookupValue || isAutocompleteMode && ["autocomplete", "verified", "partial"].includes(verificationStatus) && hasLookupValue);
139
- const showMapAction = !readOnlyView && (hasMapCoordinates || allowValidation && canAttemptMap);
140
- const mapInfoLines = (mapAddressLines.length ? mapAddressLines : [formData.address1, formData.address2, formData.district, [formData.postalCode, formData.city].filter(Boolean).join(" "), formData.region]).filter(Boolean);
141
- const {
142
- mapContainerRef,
143
- pendingMapOpen,
144
- setPendingMapOpen,
145
- setShowMapModal,
146
- showMapModal
147
- } = (0, _useAddressMapModal.default)({
63
+ const isAcceptableInitialValidationResult = validatedAddress => {
64
+ var _validatedAddress$val;
65
+ return ['verified', 'verified-sub-building-changed', 'partial'].includes(validatedAddress === null || validatedAddress === void 0 || (_validatedAddress$val = validatedAddress.validationSummary) === null || _validatedAddress$val === void 0 ? void 0 : _validatedAddress$val.code);
66
+ };
67
+ const mapVerificationStatus = validatedAddress => {
68
+ var _validatedAddress$ana;
69
+ switch ((_validatedAddress$ana = validatedAddress.analysis) === null || _validatedAddress$ana === void 0 ? void 0 : _validatedAddress$ana.verification_status) {
70
+ case 'Verified':
71
+ return 'verified';
72
+ case 'Partial':
73
+ return 'partial';
74
+ default:
75
+ return 'unverified';
76
+ }
77
+ };
78
+ const intlAdapterBase = {
79
+ autocompleteSource: 'smarty-intl',
80
+ validationSource: 'smarty-intl',
81
+ mapEligibleStatuses: ['autocomplete', 'verified', 'partial'],
82
+ validationResultsVisibleSources: VALIDATION_RESULTS_VISIBLE_SOURCES,
83
+ dismissClearsCustomError: true,
84
+ mapNoResultsRequiresNoServiceError: false,
85
+ modeSwitchResetsMapStarted: false,
86
+ resetVerificationOnManual: true,
87
+ alwaysResetMapStartedOnValidationSelect: true,
88
+ useLookupResults: ({
89
+ query,
90
+ shouldSearch,
91
+ isAutocompleteMode,
92
+ readOnlyView,
93
+ selectedLookupTarget,
94
+ countryCode
95
+ }) => (0, _useSmartyInternationalLookup.default)(!readOnlyView && shouldSearch && isAutocompleteMode ? query : '', countryCode, selectedLookupTarget, 500),
96
+ useValidationResults: ({
148
97
  formData,
149
- infoLines: mapInfoLines,
150
- hasMapCoordinates,
151
- openInMapsLabel: fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.openInMaps,
152
- shouldPrepareMap: showMapAction
153
- });
154
- const {
155
- suggestions,
156
- loading,
157
- error,
158
- rateLimited
159
- } = (0, _useSmartyInternationalLookup.default)(!readOnlyView && shouldSearchRef.current && isAutocompleteMode ? query : "", countryCode, selectedIntlAddressId, 500);
160
- const {
161
- suggestions: validationSuggestions,
162
- loading: validationLoading,
163
- error: validationError,
164
- rateLimited: validationRateLimited
165
- } = (0, _useIntlAddressValidation.default)(formData, countryCode, allowValidation ? validationTrigger : 0, lookupField);
166
- const lookupValue = formData[lookupField];
167
- const lookupErrorMessage = lookupServiceError !== null && lookupServiceError !== void 0 && lookupServiceError.rateLimited ? (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.rateLimited) || "Too many requests. Please wait a moment and try again." : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.lookupError) || "We could not look up that address right now.";
168
- const validationErrorMessage = validationServiceError !== null && validationServiceError !== void 0 && validationServiceError.rateLimited ? (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.rateLimited) || "Too many requests. Please wait a moment and try again." : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validationError) || "We could not validate that address right now.";
169
- (0, _react.useEffect)(() => {
170
- if (!validationRequestId) {
171
- return;
172
- }
173
- setShowAllRequiredErrors(true);
174
- const currentStatus = (0, _addressStatus.buildAddressStatus)({
175
- countryCode,
176
- addressForm: resolvedAddressForm,
177
- formData,
178
- verificationStatus,
179
- mode,
180
- requireValidation: allowValidation
181
- });
182
- onSelect === null || onSelect === void 0 || onSelect({
183
- type: "validation-request",
184
- address: formData,
185
- status: currentStatus
186
- });
187
- if (allowValidation && currentStatus.needsValidation) {
188
- if (String(formData[lookupField] || '').trim()) {
189
- clearServiceErrors({
190
- lookup: false,
191
- validation: true,
192
- custom: false
193
- });
194
- setShowValidationSuggestions(true);
195
- setValidationTriggerSource('save');
196
- setValidationTrigger(prev => prev + 1);
197
- } else {
198
- // Nothing to validate; emit a terminal status so save-pending is cleared instead of hanging.
199
- onSelect === null || onSelect === void 0 || onSelect({
200
- type: 'validation-request',
201
- address: formData,
202
- status: (0, _addressStatus.buildAddressStatus)({
203
- countryCode,
204
- addressForm: resolvedAddressForm,
205
- formData,
206
- verificationStatus,
207
- mode,
208
- requireValidation: allowValidation,
209
- validationAttempted: true
210
- })
211
- });
212
- }
213
- }
214
- }, [allowValidation, validationRequestId]);
215
- (0, _react.useEffect)(() => {
216
- if (!error) {
217
- setLookupServiceError(null);
218
- return;
219
- }
220
- setLookupServiceError({
221
- rateLimited,
222
- rawMessage: error
223
- });
224
- }, [error, rateLimited]);
225
- (0, _react.useEffect)(() => {
226
- if (!validationError) {
227
- setValidationServiceError(null);
228
- return;
229
- }
230
- setValidationServiceError({
231
- rateLimited: validationRateLimited,
232
- rawMessage: validationError
233
- });
234
- setPendingMapOpen(false);
235
- mapValidationStartedRef.current = false;
236
- }, [validationError, validationRateLimited]);
237
- (0, _react.useEffect)(() => {
238
- if (!lookupServiceError) {
239
- return;
240
- }
241
- onSelect === null || onSelect === void 0 || onSelect({
242
- type: "lookup-error",
243
- address: formData,
244
- status: (0, _addressStatus.buildAddressStatus)({
245
- countryCode,
246
- addressForm: resolvedAddressForm,
247
- formData,
248
- verificationStatus,
249
- mode,
250
- requireValidation: allowValidation
251
- }),
252
- error: {
253
- kind: lookupServiceError.rateLimited ? "rate-limited" : "api",
254
- source: "autocomplete",
255
- message: lookupErrorMessage
256
- }
257
- });
258
- }, [lookupServiceError]);
259
- (0, _react.useEffect)(() => {
260
- if (!validationServiceError) {
261
- return;
262
- }
263
- onSelect === null || onSelect === void 0 || onSelect({
264
- type: "validation-error",
265
- address: formData,
266
- status: (0, _addressStatus.buildAddressStatus)({
267
- countryCode,
268
- addressForm: resolvedAddressForm,
269
- formData,
270
- verificationStatus,
271
- mode,
272
- requireValidation: allowValidation
273
- }),
274
- error: {
275
- kind: validationServiceError.rateLimited ? "rate-limited" : "api",
276
- source: "validation",
277
- message: validationErrorMessage
278
- }
279
- });
280
- }, [validationServiceError]);
281
- const clearServiceErrors = ({
282
- lookup = true,
283
- validation = true,
284
- custom = false
285
- } = {}) => {
286
- if (lookup) {
287
- setLookupServiceError(null);
288
- }
289
- if (validation) {
290
- setValidationServiceError(null);
291
- }
292
- if (custom) {
293
- setCustomError(null);
294
- }
295
- };
296
- const stripUnusedEmail = (address = {}) => {
297
- if (hasEmailField) {
298
- return address;
299
- }
300
- const nextAddress = {
301
- ...address
302
- };
303
- delete nextAddress.email;
304
- return nextAddress;
305
- };
306
- const buildTrackedAddress = (address = {}, status = "unverified", source = null) => stripUnusedEmail((0, _addressVerification.withAddressVerification)(address, status, source));
307
- const isAcceptableInitialValidationResult = validatedAddress => {
308
- var _validatedAddress$val;
309
- return ["verified", "verified-sub-building-changed", "partial"].includes(validatedAddress === null || validatedAddress === void 0 || (_validatedAddress$val = validatedAddress.validationSummary) === null || _validatedAddress$val === void 0 ? void 0 : _validatedAddress$val.code);
310
- };
311
- (0, _useInitialAddressVerification.default)({
312
- initialAddress,
313
- countryCode,
98
+ trigger,
314
99
  lookupField,
315
- requireValidation: allowValidation,
100
+ countryCode
101
+ }) => (0, _useIntlAddressValidation.default)(formData, countryCode, trigger, lookupField),
102
+ computeMapInfoLines: formData => [formData.address1, formData.address2, formData.district, [formData.postalCode, formData.city].filter(Boolean).join(' '), formData.region],
103
+ getAutocompleteSelectionKey: address => address.address_id || `${address.street || ''}|${address.locality || ''}|${address.postal_code || ''}`,
104
+ mapAutocompleteSelection: ({
105
+ selectedAddress,
106
+ resolvedAddressForm
107
+ }) => (0, _addressMapping.buildIntlAutocompleteAddressMapping)(selectedAddress, resolvedAddressForm),
108
+ shouldVerifyAfterAutocomplete: ({
316
109
  resolvedAddressForm,
317
- setValidationServiceError,
318
- setCustomError,
319
- setShowValidationSuggestions,
320
- setValidationTriggerSource,
321
- setValidationTrigger
322
- });
323
- (0, _react.useEffect)(() => {
324
- if (selectedIntlAddressId) {
325
- if (suggestions.length === 1 && suggestions[0].isDetailed) {
326
- setSelectedAddress(suggestions[0]);
327
- setSelectedIntlAddressId(null);
328
- setQuery("");
329
- setCustomError(null);
330
- } else if (suggestions.length === 0 && !loading) {
331
- setCustomError("Unable to retrieve address details. Please try another address or enter manually.");
332
- setSelectedIntlAddressId(null);
333
- setQuery("");
334
- }
335
- } else if (suggestions.length > 0 && !suggestions[0].isDetailed && !selectedAddress) {
336
- setSelectedAddress(null);
337
- setCustomError(null);
338
- }
339
- }, [suggestions, selectedIntlAddressId, selectedAddress, loading]);
340
- (0, _react.useEffect)(() => {
341
- if (lookupValue !== undefined && shouldSearchRef.current && !selectedAddress) {
342
- setQuery(lookupValue);
343
- }
344
- }, [lookupValue, selectedAddress]);
345
- (0, _react.useEffect)(() => {
346
- var _suggestionButtons$;
347
- const shouldShowValidationResults = allowValidation && showValidationSuggestions && validationSuggestions.length > 0 && !validationLoading && (!isAutocompleteMode || ["map", "initial"].includes(validationTriggerSource));
348
- if (!shouldShowValidationResults) {
349
- return;
350
- }
351
- const suggestionButtons = getVisibleSuggestionButtons();
352
- if (suggestionButtons.length === 0 || suggestionButtons.includes(document.activeElement)) {
353
- return;
354
- }
355
- (_suggestionButtons$ = suggestionButtons[0]) === null || _suggestionButtons$ === void 0 || _suggestionButtons$.focus();
356
- }, [isAutocompleteMode, allowValidation, showValidationSuggestions, validationLoading, validationSuggestions, validationTriggerSource]);
357
- (0, _react.useEffect)(() => {
358
- var _getLookupInputElemen;
359
- const shouldRefocusLookupField = isAutocompleteMode && selectedIntlAddressId && suggestions.length > 0 && !selectedAddress && !loading;
360
- if (!shouldRefocusLookupField) {
361
- return;
362
- }
363
- (_getLookupInputElemen = getLookupInputElement()) === null || _getLookupInputElemen === void 0 || _getLookupInputElemen.focus();
364
- }, [isAutocompleteMode, selectedIntlAddressId, suggestions, selectedAddress, loading]);
365
- (0, _react.useEffect)(() => {
366
- if (validationTrigger > 0 && ['autocomplete', 'map', 'initial', 'save'].includes(validationTriggerSource)) {
367
- autoApplyValidationStartedRef.current = false;
368
- }
369
- }, [validationTrigger, validationTriggerSource]);
370
- (0, _react.useEffect)(() => {
371
- if (validationTriggerSource === "map" && validationLoading) {
372
- mapValidationStartedRef.current = true;
373
- }
374
- if (validationLoading && ['autocomplete', 'map', 'initial', 'save'].includes(validationTriggerSource)) {
375
- autoApplyValidationStartedRef.current = true;
376
- }
377
- }, [validationLoading, validationTriggerSource]);
378
- (0, _react.useEffect)(() => {
379
- if (validationTriggerSource === "map" && mapValidationStartedRef.current && showValidationSuggestions && !validationLoading && validationSuggestions.length === 0) {
380
- setPendingMapOpen(false);
381
- mapValidationStartedRef.current = false;
382
- }
383
- }, [validationLoading, validationSuggestions, validationTriggerSource, showValidationSuggestions]);
384
- (0, _react.useEffect)(() => {
385
- if (!hasPendingLookupDraft || suggestions.length === 0) {
386
- return undefined;
387
- }
388
- const handleDocumentMouseDown = event => {
389
- const component = componentRef.current;
390
- if (component !== null && component !== void 0 && component.contains(event.target)) {
391
- return;
392
- }
393
- const suggestionsList = suggestionsListRef.current;
394
- if ((suggestionsList === null || suggestionsList === void 0 ? void 0 : suggestionsList.contains(event.target)) === false) {
395
- shouldSearchRef.current = false;
396
- setQuery("");
397
- setSelectedAddress(null);
398
- setSelectedIntlAddressId(null);
399
- setShowValidationSuggestions(false);
400
- clearServiceErrors({
401
- custom: true
402
- });
403
- setFormData(lookupDraftOriginalRef.current);
404
- setHasPendingLookupDraft(false);
405
- }
406
- };
407
- document.addEventListener("pointerdown", handleDocumentMouseDown);
408
- return () => {
409
- document.removeEventListener("pointerdown", handleDocumentMouseDown);
410
- };
411
- }, [hasPendingLookupDraft, suggestions]);
412
- (0, _react.useEffect)(() => {
413
- if (isAutocompleteMode || !showValidationSuggestions || validationLoading || validationSuggestions.length === 0) {
414
- return undefined;
415
- }
416
- const handleDocumentPointerDown = event => {
417
- var _componentRef$current;
418
- if ((_componentRef$current = componentRef.current) !== null && _componentRef$current !== void 0 && _componentRef$current.contains(event.target)) {
419
- return;
420
- }
421
- setShowValidationSuggestions(false);
422
- };
423
- document.addEventListener("pointerdown", handleDocumentPointerDown);
424
- return () => {
425
- document.removeEventListener("pointerdown", handleDocumentPointerDown);
426
- };
427
- }, [isAutocompleteMode, showValidationSuggestions, validationLoading, validationSuggestions]);
428
- (0, _react.useEffect)(() => {
429
- if (selectedAddress) {
430
- const selectionKey = selectedAddress.address_id || `${selectedAddress.street || ""}|${selectedAddress.locality || ""}|${selectedAddress.postal_code || ""}`;
431
- if (appliedSelectionKeyRef.current === selectionKey) {
432
- return;
433
- }
434
- appliedSelectionKeyRef.current = selectionKey;
435
- const mapped = (0, _addressMapping.buildIntlAutocompleteAddressMapping)(selectedAddress, resolvedAddressForm);
436
- const updatedFormData = {
437
- ...stripGeocode(formData),
438
- ...mapped,
439
- email: formData.email
440
- };
441
- const normalizedFormData = buildTrackedAddress(updatedFormData, "autocomplete", "smarty-intl");
442
- setFormData(normalizedFormData);
443
- setMapAddressLines([]);
444
- lastCommittedAddressRef.current = normalizedFormData;
445
- lookupDraftOriginalRef.current = normalizedFormData;
446
- setHasPendingLookupDraft(false);
447
- clearServiceErrors({
448
- custom: true
449
- });
450
- const currentVerificationStatus = "autocomplete";
451
- setVerificationStatus(currentVerificationStatus);
452
- onSelect === null || onSelect === void 0 || onSelect({
453
- type: "autocomplete",
454
- address: normalizedFormData,
455
- status: (0, _addressStatus.buildAddressStatus)({
456
- countryCode,
457
- addressForm: resolvedAddressForm,
458
- formData: normalizedFormData,
459
- verificationStatus: currentVerificationStatus,
460
- mode,
461
- requireValidation: allowValidation
462
- })
463
- });
464
- if ((0, _addressStatus.shouldVerifyAutocompleteSelection)({
465
- addressForm: resolvedAddressForm,
466
- formData: normalizedFormData,
467
- requireValidation: allowValidation
468
- })) {
469
- // Trigger validation instead of directly selecting.
470
- // Keep suggestions visible in case multiple candidates are returned.
471
- setShowValidationSuggestions(true);
472
- setValidationTriggerSource("autocomplete");
473
- setValidationTrigger(prev => prev + 1);
474
- }
475
- }
476
- }, [selectedAddress]);
477
- const handleInputChange = e => {
478
- const value = (0, _validators.normalizeAddressFieldValue)(lookupField, e.target.value);
479
- shouldSearchRef.current = true;
480
- appliedSelectionKeyRef.current = null;
481
- setSelectedAddress(null);
482
- setSelectedIntlAddressId(null);
483
- setShowValidationSuggestions(false);
484
- setShowMapModal(false);
485
- setPendingMapOpen(false);
486
- mapValidationStartedRef.current = false;
487
- setMapAddressLines([]);
488
- setValidationTriggerSource(null);
489
- clearServiceErrors({
490
- custom: true
491
- });
492
- if (!hasPendingLookupDraft) {
493
- lookupDraftOriginalRef.current = formData;
494
- setHasPendingLookupDraft(true);
495
- }
496
- const updatedFormData = stripUnusedEmail({
497
- ...stripGeocode(formData),
498
- [lookupField]: value
499
- });
500
- setFormData(buildTrackedAddress(updatedFormData, "unverified"));
501
- setVerificationStatus("unverified");
502
- };
503
- const isFieldRequired = field => requiredFields.includes(field);
504
- const isFieldBlank = field => String(formData[field] || "").trim() === "";
505
- const hasInvalidPostalCodeFormat = field => {
506
- if (field !== "postalCode") {
507
- return false;
508
- }
509
- const value = String(formData.postalCode || "").trim();
510
- if (!value || !resolvedAddressForm.postalCodeRegex) {
511
- return false;
512
- }
513
- return !resolvedAddressForm.postalCodeRegex.test((0, _validators.normalizePostalCodeValue)(value));
514
- };
515
- const hasInvalidEmailFormat = field => {
516
- if (field !== "email") {
517
- return false;
518
- }
519
- const value = String(formData.email || "").trim();
520
- if (!value) {
521
- return false;
522
- }
523
- return !(0, _validators.isValidEmail)(value);
524
- };
525
- const hasIllegalCharacters = field => {
526
- const fieldConfig = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).find(el => el.field === field);
527
- if (!(fieldConfig !== null && fieldConfig !== void 0 && fieldConfig.allowedCharacters)) {
528
- return false;
529
- }
530
- const value = String(formData[field] || '').trim();
531
- return value !== '' && !fieldConfig.allowedCharacters.test(value);
532
- };
533
- const shouldShowFieldError = field => {
534
- const shouldShowValidation = Boolean(showAllRequiredErrors || touchedFields[field]);
535
- if (!shouldShowValidation) {
536
- return false;
537
- }
538
- const requiredError = isFieldRequired(field) && isFieldBlank(field);
539
- return requiredError || hasInvalidPostalCodeFormat(field) || hasInvalidEmailFormat(field) || hasIllegalCharacters(field);
540
- };
541
- const handleFieldBlur = field => {
542
- if (readOnlyView) {
543
- return;
544
- }
545
- const fieldConfig = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).find(el => el.field === field);
546
- const hasCharRestriction = Boolean(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.allowedCharacters);
547
- if (!isFieldRequired(field) && !hasCharRestriction && field !== 'email' && field !== 'postalCode') {
548
- return;
549
- }
550
- setTouchedFields(prev => ({
551
- ...prev,
552
- [field]: true
553
- }));
554
- };
555
- const getFieldErrorMessage = field => {
556
- if (!shouldShowFieldError(field)) {
557
- return "";
558
- }
559
- if (isFieldRequired(field) && isFieldBlank(field)) {
560
- if (areLabelsLoading) {
561
- return '';
562
- }
563
- const fieldConfig = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).find(el => el.field === field);
564
- const fieldDisplayLabel = (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels[field]) || (fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.label);
565
- return fieldDisplayLabel ? `${fieldDisplayLabel} ${(fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.fieldRequiredSuffix) || 'is required'}` : fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.fieldRequired;
566
- }
567
- if (hasInvalidPostalCodeFormat(field)) {
568
- return areLabelsLoading ? "" : fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.invalidPostalCode;
569
- }
570
- if (hasInvalidEmailFormat(field)) {
571
- return areLabelsLoading ? "" : fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.invalidEmail;
572
- }
573
- if (hasIllegalCharacters(field)) {
574
- return areLabelsLoading ? '' : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.illegalCharacters) || 'Contains invalid characters.';
575
- }
576
- return '';
577
- };
578
- const hasVisibleFieldError = field => shouldShowFieldError(field);
579
- const handleEditableFieldChange = (field, value) => {
580
- const normalizedValue = (0, _validators.normalizeAddressFieldValue)(field, value);
581
- if (field === lookupField) {
582
- setShowValidationSuggestions(false);
583
- }
584
- setShowMapModal(false);
585
- setPendingMapOpen(false);
586
- mapValidationStartedRef.current = false;
587
- setMapAddressLines([]);
588
- clearServiceErrors({
589
- custom: true
590
- });
591
- const requiredFieldsForVerification = (resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.requiredFields) || requiredFields;
592
- const nextVerificationStatus = (0, _addressVerification.getManualEditVerificationStatus)(field, verificationStatus, lookupField, requiredFieldsForVerification);
593
- const updatedFormData = (0, _addressVerification.withManualAddressVerificationEdit)(field, stripUnusedEmail({
594
- ...stripGeocode(formData),
595
- [field]: normalizedValue
596
- }), nextVerificationStatus);
597
- setFormData(updatedFormData);
598
- setVerificationStatus(nextVerificationStatus);
599
- if (fieldTimerRef.current) {
600
- clearTimeout(fieldTimerRef.current);
601
- }
602
- fieldTimerRef.current = setTimeout(() => {
603
- const payload = {
604
- type: "field-change",
605
- field,
606
- value: normalizedValue,
607
- address: updatedFormData,
608
- status: (0, _addressStatus.buildAddressStatus)({
609
- countryCode,
610
- addressForm: resolvedAddressForm,
611
- formData: updatedFormData,
612
- verificationStatus: nextVerificationStatus,
613
- mode,
614
- requireValidation: allowValidation
615
- })
616
- };
617
- if (hasEmailField && field === "email" && value) {
618
- payload.isValidEmail = (0, _validators.isValidEmail)(normalizedValue);
619
- }
620
- onSelect === null || onSelect === void 0 || onSelect(payload);
621
- }, 500);
622
- };
623
- const handleSelect = address => {
624
- clearServiceErrors({
625
- lookup: true,
626
- validation: false,
627
- custom: true
628
- });
110
+ formData,
111
+ allowValidation
112
+ }) => (0, _addressStatus.shouldVerifyAutocompleteSelection)({
113
+ addressForm: resolvedAddressForm,
114
+ formData,
115
+ requireValidation: allowValidation
116
+ }),
117
+ applyLookupSelect: (address, {
118
+ shouldSearchRef,
119
+ appliedSelectionKeyRef,
120
+ setSelectedLookupTarget,
121
+ setSelectedAddress,
122
+ setQuery
123
+ }) => {
629
124
  if (address.entries > 1 || address.entries === 1 && address.isDetailed === false) {
630
125
  shouldSearchRef.current = true;
631
126
  appliedSelectionKeyRef.current = null;
632
- setSelectedIntlAddressId(address.address_id);
127
+ setSelectedLookupTarget(address.address_id);
633
128
  setQuery(address.displayText);
634
129
  } else {
635
130
  shouldSearchRef.current = false;
636
131
  appliedSelectionKeyRef.current = null;
637
- setSelectedIntlAddressId(null);
132
+ setSelectedLookupTarget(null);
638
133
  setSelectedAddress(address);
639
- setQuery("");
134
+ setQuery('');
640
135
  }
641
- };
642
- const handleValidationSelect = validatedAddress => {
643
- var _validatedAddress$met, _validatedAddress$met2;
644
- clearServiceErrors({
645
- lookup: false,
646
- validation: true,
647
- custom: false
648
- });
136
+ },
137
+ mapValidationSelection: ({
138
+ validatedAddress,
139
+ resolvedAddressForm,
140
+ formData
141
+ }) => {
649
142
  const config = resolvedAddressForm.addressElements || [];
650
143
  const {
651
144
  mapped: formattedMapped,
652
- mapAddressLines: nextMapAddressLines
145
+ mapAddressLines
653
146
  } = (0, _addressMapping.buildIntlConfiguredVerificationMapping)(validatedAddress, resolvedAddressForm);
654
- let mapped = (0, _addressMapping.preserveBlankConfiguredMappings)(formattedMapped, formData, config, "verification");
655
-
656
- // Preserve user-entered address2 if verification didn't return one
147
+ const mapped = (0, _addressMapping.preserveBlankConfiguredMappings)(formattedMapped, formData, config, 'verification');
657
148
  if (!mapped.address2 && formData.address2) {
658
149
  mapped.address2 = formData.address2;
659
150
  }
660
-
661
- // Apply address wrapping if enabled
662
151
  if (resolvedAddressForm.wrapAddress1ToAddress2) {
663
- const address1Field = config.find(f => f.field === "address1");
152
+ const address1Field = config.find(f => f.field === 'address1');
664
153
  if (address1Field !== null && address1Field !== void 0 && address1Field.maxLength) {
665
154
  const wrapped = (0, _addressWrapper.wrapAddress1ToAddress2)(mapped.address1, mapped.address2, address1Field.maxLength);
666
155
  mapped.address1 = wrapped.address1;
667
156
  mapped.address2 = wrapped.address2;
668
157
  }
669
158
  }
670
- const updatedFormData = {
671
- ...stripGeocode(formData),
672
- ...mapped,
673
- email: formData.email,
674
- latitude: (_validatedAddress$met = validatedAddress.metadata) === null || _validatedAddress$met === void 0 ? void 0 : _validatedAddress$met.latitude,
675
- longitude: (_validatedAddress$met2 = validatedAddress.metadata) === null || _validatedAddress$met2 === void 0 ? void 0 : _validatedAddress$met2.longitude
159
+ return {
160
+ mapped,
161
+ mapAddressLines,
162
+ verificationStatus: mapVerificationStatus(validatedAddress)
676
163
  };
677
- const currentVerificationStatus = (_validatedAddress$ana => {
678
- switch ((_validatedAddress$ana = validatedAddress.analysis) === null || _validatedAddress$ana === void 0 ? void 0 : _validatedAddress$ana.verification_status) {
679
- case "Verified":
680
- return "verified";
681
- case "Partial":
682
- return "partial";
683
- default:
684
- return "unverified";
685
- }
686
- })();
687
- const normalizedFormData = buildTrackedAddress(updatedFormData, currentVerificationStatus, 'smarty-intl');
688
- const wasTriggeredBySave = validationTriggerSource === 'save';
689
- setShowValidationSuggestions(false);
690
- setValidationTriggerSource(null);
691
- setFormData(normalizedFormData);
692
- setMapAddressLines(nextMapAddressLines);
693
- lastCommittedAddressRef.current = normalizedFormData;
694
- lookupDraftOriginalRef.current = normalizedFormData;
695
- setHasPendingLookupDraft(false);
696
- setVerificationStatus(currentVerificationStatus);
697
- autoApplyValidationStartedRef.current = false;
698
- if (pendingMapOpen) {
699
- setPendingMapOpen(false);
700
- setShowMapModal(true);
701
- }
702
- mapValidationStartedRef.current = false;
703
- const validationStatus = (0, _addressStatus.buildAddressStatus)({
704
- countryCode,
705
- addressForm: resolvedAddressForm,
706
- formData: normalizedFormData,
707
- verificationStatus: currentVerificationStatus,
708
- mode,
709
- requireValidation: allowValidation,
710
- validationAttempted: true
711
- });
712
- onSelect === null || onSelect === void 0 || onSelect({
713
- type: "validation",
714
- address: normalizedFormData,
715
- verification: validatedAddress.analysis,
716
- status: validationStatus
717
- });
718
- if (wasTriggeredBySave) {
719
- onSelect === null || onSelect === void 0 || onSelect({
720
- type: 'validation-request',
721
- address: normalizedFormData,
722
- status: validationStatus
723
- });
724
- }
725
- };
726
- const handleValidate = () => {
727
- if (!allowValidation) {
728
- return;
729
- }
730
- clearServiceErrors({
731
- lookup: false,
732
- validation: true,
733
- custom: false
734
- });
735
- setShowValidationSuggestions(true);
736
- setValidationTriggerSource("manual");
737
- setValidationTrigger(prev => prev + 1);
738
- };
739
- const getFieldKey = fieldConfig => fieldConfig.field;
740
- const getSuggestionKey = suggestion => suggestion.address_id || [suggestion.displayText, suggestion.street, suggestion.address_text, suggestion.locality, suggestion.administrative_area, suggestion.postal_code, suggestion.entries].filter(value => value !== undefined && value !== null).join("|");
741
- const getValidationSuggestionKey = suggestion => {
742
- var _suggestion$component, _suggestion$component2, _suggestion$component3, _suggestion$component4, _suggestion$component5;
743
- return [suggestion.displayText, suggestion.address1, suggestion.address2, suggestion.address3, (_suggestion$component = suggestion.components) === null || _suggestion$component === void 0 ? void 0 : _suggestion$component.thoroughfare, (_suggestion$component2 = suggestion.components) === null || _suggestion$component2 === void 0 ? void 0 : _suggestion$component2.premise, (_suggestion$component3 = suggestion.components) === null || _suggestion$component3 === void 0 ? void 0 : _suggestion$component3.locality, (_suggestion$component4 = suggestion.components) === null || _suggestion$component4 === void 0 ? void 0 : _suggestion$component4.administrative_area, (_suggestion$component5 = suggestion.components) === null || _suggestion$component5 === void 0 ? void 0 : _suggestion$component5.postal_code].filter(value => value !== undefined && value !== null).join("|");
744
- };
745
- const getIntlValidationSummaryTitle = suggestion => {
746
- var _suggestion$validatio, _suggestion$validatio2, _suggestion$validatio3, _suggestion$validatio4, _suggestion$validatio5, _suggestion$validatio6, _suggestion$validatio7;
747
- const code = (_suggestion$validatio = suggestion.validationSummary) === null || _suggestion$validatio === void 0 ? void 0 : _suggestion$validatio.code;
748
- switch (code) {
749
- case "verified":
750
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedTitle) || ((_suggestion$validatio2 = suggestion.validationSummary) === null || _suggestion$validatio2 === void 0 ? void 0 : _suggestion$validatio2.title) || "Verified";
751
- case "verified-sub-building-changed":
752
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedSubBuildingChangedTitle) || ((_suggestion$validatio3 = suggestion.validationSummary) === null || _suggestion$validatio3 === void 0 ? void 0 : _suggestion$validatio3.title) || "Verified with unit changes";
753
- case "partial":
754
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlPartialTitle) || ((_suggestion$validatio4 = suggestion.validationSummary) === null || _suggestion$validatio4 === void 0 ? void 0 : _suggestion$validatio4.title) || "Partially verified";
755
- case "ambiguous":
756
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlAmbiguousTitle) || ((_suggestion$validatio5 = suggestion.validationSummary) === null || _suggestion$validatio5 === void 0 ? void 0 : _suggestion$validatio5.title) || "Multiple matches found";
757
- case "not-verified":
758
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlNotVerifiedTitle) || ((_suggestion$validatio6 = suggestion.validationSummary) === null || _suggestion$validatio6 === void 0 ? void 0 : _suggestion$validatio6.title) || "Not verified";
759
- default:
760
- return ((_suggestion$validatio7 = suggestion.validationSummary) === null || _suggestion$validatio7 === void 0 ? void 0 : _suggestion$validatio7.title) || "Unknown";
761
- }
762
- };
763
- const getIntlValidationSummaryMessage = suggestion => {
764
- var _suggestion$validatio8, _suggestion$validatio9, _suggestion$validatio0, _suggestion$validatio1, _suggestion$validatio10, _suggestion$validatio11, _suggestion$validatio12;
765
- const code = (_suggestion$validatio8 = suggestion.validationSummary) === null || _suggestion$validatio8 === void 0 ? void 0 : _suggestion$validatio8.code;
766
- switch (code) {
767
- case "verified":
768
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedMessage) || ((_suggestion$validatio9 = suggestion.validationSummary) === null || _suggestion$validatio9 === void 0 ? void 0 : _suggestion$validatio9.message) || "";
769
- case "verified-sub-building-changed":
770
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlVerifiedSubBuildingChangedMessage) || ((_suggestion$validatio0 = suggestion.validationSummary) === null || _suggestion$validatio0 === void 0 ? void 0 : _suggestion$validatio0.message) || "";
771
- case "partial":
772
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlPartialMessage) || ((_suggestion$validatio1 = suggestion.validationSummary) === null || _suggestion$validatio1 === void 0 ? void 0 : _suggestion$validatio1.message) || "";
773
- case "ambiguous":
774
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlAmbiguousMessage) || ((_suggestion$validatio10 = suggestion.validationSummary) === null || _suggestion$validatio10 === void 0 ? void 0 : _suggestion$validatio10.message) || "";
775
- case "not-verified":
776
- return (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlNotVerifiedMessage) || ((_suggestion$validatio11 = suggestion.validationSummary) === null || _suggestion$validatio11 === void 0 ? void 0 : _suggestion$validatio11.message) || "";
777
- default:
778
- return ((_suggestion$validatio12 = suggestion.validationSummary) === null || _suggestion$validatio12 === void 0 ? void 0 : _suggestion$validatio12.message) || "";
779
- }
780
- };
781
- const handleOpenMap = () => {
782
- if (hasMapCoordinates) {
783
- setShowMapModal(true);
784
- return;
785
- }
786
- if (!allowValidation || !canAttemptMap || validationLoading) {
787
- return;
788
- }
789
- clearServiceErrors({
790
- lookup: false,
791
- validation: true,
792
- custom: false
793
- });
794
- mapValidationStartedRef.current = false;
795
- setPendingMapOpen(true);
796
- setShowValidationSuggestions(true);
797
- setValidationTriggerSource("map");
798
- setValidationTrigger(prev => prev + 1);
799
- };
800
- const renderLookupActions = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
801
- className: "ns-address-lookup__actions",
802
- children: [showMapAction && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
803
- type: "button",
804
- onClick: handleOpenMap,
805
- className: "ns-address-lookup__toggle ns-address-lookup__toggle--icon",
806
- title: fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.openInMaps,
807
- "aria-label": fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.openInMaps,
808
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LocationPinIcon.default, {
809
- className: "ns-address-lookup__icon"
810
- })
811
- }), !isAutocompleteMode && allowValidation && /*#__PURE__*/(0, _jsxRuntime.jsx)(_foundationUiComponents.NsButton, {
812
- type: "button",
813
- onClick: handleValidate,
814
- disabled: validationLoading || !String(formData[lookupField] || "").trim(),
815
- variant: "contained",
816
- color: "primary",
817
- size: "small",
818
- className: "ns-address-lookup__validate-button",
819
- children: validationLoading ? (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validatingAddress) || "Validating..." : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validateAddress) || "Validate Address"
820
- }), entryMode === "both" && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
821
- type: "button",
822
- onClick: handleModeSwitch,
823
- className: "ns-address-lookup__toggle",
824
- children: mode === "autocomplete" ? fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.switchToManualEntry : fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.switchToAutocomplete
825
- })]
826
- });
827
-
828
- // Reset verification when switching modes to prevent stale validation
829
- const handleModeSwitch = () => {
830
- setShowValidationSuggestions(false);
831
- setShowMapModal(false);
832
- setPendingMapOpen(false);
833
- setValidationTriggerSource(null);
834
- clearServiceErrors({
835
- custom: true
836
- });
837
- const nextMode = mode === 'autocomplete' ? 'manual' : 'autocomplete';
838
- setMode(nextMode);
839
- if (verificationStatus === 'autocomplete' && nextMode === 'manual') {
840
- setVerificationStatus('unverified');
841
- setFormData(prev => (0, _addressVerification.withAddressVerification)(prev, 'unverified'));
842
- }
843
- };
844
- const getLookupInputElement = () => typeof document !== 'undefined' ? document.getElementById(getFieldId(lookupField)) : null;
845
- const getVisibleSuggestionButtons = () => {
846
- var _componentRef$current2;
847
- return Array.from(((_componentRef$current2 = componentRef.current) === null || _componentRef$current2 === void 0 ? void 0 : _componentRef$current2.querySelectorAll(LOOKUP_LIST_BUTTON_SELECTOR)) || []);
848
- };
849
- const handleLookupInputKeyDown = event => {
850
- if (event.key !== "ArrowDown" && event.key !== "ArrowUp") {
851
- return;
852
- }
853
- const suggestionButtons = getVisibleSuggestionButtons();
854
- if (suggestionButtons.length === 0) {
855
- return;
856
- }
857
- event.preventDefault();
858
- const targetButton = event.key === "ArrowUp" ? suggestionButtons[suggestionButtons.length - 1] : suggestionButtons[0];
859
- targetButton === null || targetButton === void 0 || targetButton.focus();
860
- };
861
- const handleSuggestionButtonKeyDown = (event, index) => {
862
- const suggestionButtons = getVisibleSuggestionButtons();
863
- if (suggestionButtons.length === 0) {
864
- return;
865
- }
866
- if (event.key === "ArrowDown") {
867
- var _suggestionButtons;
868
- event.preventDefault();
869
- if (index === suggestionButtons.length - 1) {
870
- var _getLookupInputElemen2;
871
- (_getLookupInputElemen2 = getLookupInputElement()) === null || _getLookupInputElemen2 === void 0 || _getLookupInputElemen2.focus();
872
- return;
873
- }
874
- (_suggestionButtons = suggestionButtons[index + 1]) === null || _suggestionButtons === void 0 || _suggestionButtons.focus();
875
- return;
164
+ },
165
+ resolveInitialAutoApply: ({
166
+ validationSuggestions,
167
+ autoApplyStarted
168
+ }) => {
169
+ if (autoApplyStarted && validationSuggestions.length === 1 && isAcceptableInitialValidationResult(validationSuggestions[0])) {
170
+ return {
171
+ apply: validationSuggestions[0]
172
+ };
876
173
  }
877
- if (event.key === "ArrowUp") {
878
- var _suggestionButtons2;
879
- event.preventDefault();
880
- if (index === 0) {
881
- var _getLookupInputElemen3;
882
- (_getLookupInputElemen3 = getLookupInputElement()) === null || _getLookupInputElemen3 === void 0 || _getLookupInputElemen3.focus();
883
- return;
174
+ return {};
175
+ },
176
+ onLookupSuggestionsResolved: ({
177
+ suggestions,
178
+ selectedLookupTarget,
179
+ selectedAddress,
180
+ loading,
181
+ setSelectedAddress,
182
+ setSelectedLookupTarget,
183
+ setQuery,
184
+ setCustomError
185
+ }) => {
186
+ if (selectedLookupTarget) {
187
+ if (suggestions.length === 1 && suggestions[0].isDetailed) {
188
+ setSelectedAddress(suggestions[0]);
189
+ setSelectedLookupTarget(null);
190
+ setQuery('');
191
+ setCustomError(null);
192
+ } else if (suggestions.length === 0 && !loading) {
193
+ setCustomError('Unable to retrieve address details. Please try another address or enter manually.');
194
+ setSelectedLookupTarget(null);
195
+ setQuery('');
884
196
  }
885
- (_suggestionButtons2 = suggestionButtons[index - 1]) === null || _suggestionButtons2 === void 0 || _suggestionButtons2.focus();
886
- return;
887
- }
888
- if (event.key === "Escape") {
889
- var _getLookupInputElemen4;
890
- event.preventDefault();
891
- (_getLookupInputElemen4 = getLookupInputElement()) === null || _getLookupInputElemen4 === void 0 || _getLookupInputElemen4.focus();
892
- }
893
- };
894
- const renderLookupLists = isLookupField => {
895
- if (readOnlyView) {
896
- return null;
897
- }
898
- const shouldShowValidationResults = allowValidation && showValidationSuggestions && (!isAutocompleteMode || ["map", "initial"].includes(validationTriggerSource));
899
- const shouldShowNoResults = shouldShowValidationResults && !validationLoading && validationSuggestions.length === 0 && !validationServiceError && (validationTriggerSource !== "map" || mapValidationStartedRef.current);
900
- if (!isLookupField) {
901
- return null;
902
- }
903
- if (suggestions.length > 0 && !selectedAddress && isAutocompleteMode) {
904
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
905
- ref: suggestionsListRef,
906
- className: "ns-address-lookup__list ns-address-lookup__list--suggestions",
907
- children: suggestions.map((suggestion, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
908
- className: ["ns-address-lookup__list-item", index < suggestions.length - 1 ? "ns-address-lookup__list-item--divided" : ""].filter(Boolean).join(" "),
909
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
910
- type: "button",
911
- onClick: () => handleSelect(suggestion),
912
- onKeyDown: event => handleSuggestionButtonKeyDown(event, index),
913
- className: "ns-address-lookup__list-button",
914
- children: suggestion.displayText
915
- })
916
- }, getSuggestionKey(suggestion)))
917
- });
918
- }
919
- if (shouldShowValidationResults && validationSuggestions.length > 0) {
920
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
921
- className: "ns-address-lookup__list ns-address-lookup__list--validation-inline",
922
- children: validationSuggestions.map((suggestion, index) => {
923
- var _suggestion$validatio13;
924
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
925
- className: ["ns-address-lookup__list-item", ((_suggestion$validatio13 = suggestion.validationSummary) === null || _suggestion$validatio13 === void 0 ? void 0 : _suggestion$validatio13.code) === "not-verified" ? "ns-address-lookup__list-item--not-verified" : "", index < validationSuggestions.length - 1 ? "ns-address-lookup__list-item--divided" : ""].filter(Boolean).join(" "),
926
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
927
- type: "button",
928
- onClick: () => handleValidationSelect(suggestion),
929
- onKeyDown: event => handleSuggestionButtonKeyDown(event, index),
930
- className: "ns-address-lookup__list-button",
931
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
932
- className: "ns-address-lookup__list-title",
933
- children: getIntlValidationSummaryTitle(suggestion)
934
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
935
- className: "ns-address-lookup__list-subtitle",
936
- children: suggestion.displayText
937
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
938
- className: "ns-address-lookup__list-subtitle",
939
- children: getIntlValidationSummaryMessage(suggestion)
940
- })]
941
- })
942
- }, getValidationSuggestionKey(suggestion));
943
- })
944
- });
945
- }
946
- if (shouldShowNoResults) {
947
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
948
- className: "ns-address-lookup__message",
949
- children: fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.intlNoResults
950
- });
197
+ } else if (suggestions.length > 0 && !suggestions[0].isDetailed && !selectedAddress) {
198
+ setSelectedAddress(null);
199
+ setCustomError(null);
951
200
  }
952
- return null;
201
+ }
202
+ };
203
+ const SmartyIntlResults = props => {
204
+ var _c$fieldLabels4;
205
+ const {
206
+ countryCode,
207
+ suppressRequiredFieldsHint = false
208
+ } = props;
209
+ const adapter = {
210
+ ...intlAdapterBase,
211
+ countryCode
953
212
  };
954
- (0, _react.useEffect)(() => {
955
- if (['autocomplete', 'map', 'save'].includes(validationTriggerSource) && validationSuggestions.length === 1 && autoApplyValidationStartedRef.current) {
956
- handleValidationSelect(validationSuggestions[0]);
957
- }
958
- if (validationTriggerSource === 'save' && autoApplyValidationStartedRef.current && !validationLoading && validationSuggestions.length === 0 && !validationServiceError) {
959
- autoApplyValidationStartedRef.current = false;
960
- setShowValidationSuggestions(false);
961
- setValidationTriggerSource(null);
962
-
963
- // Zero-result save validation still needs a terminal status so save-pending clears.
964
- onSelect === null || onSelect === void 0 || onSelect({
965
- type: 'validation-request',
966
- address: formData,
967
- status: (0, _addressStatus.buildAddressStatus)({
968
- countryCode,
969
- addressForm: resolvedAddressForm,
970
- formData,
971
- verificationStatus,
972
- mode,
973
- requireValidation: allowValidation,
974
- validationAttempted: true
975
- })
976
- });
977
- }
978
- if (validationTriggerSource === "initial" && validationSuggestions.length === 1 && autoApplyValidationStartedRef.current && isAcceptableInitialValidationResult(validationSuggestions[0])) {
979
- handleValidationSelect(validationSuggestions[0]);
980
- }
981
- }, [validationLoading, validationSuggestions, validationTriggerSource]);
213
+ const c = (0, _useSmartyAddressController.default)({
214
+ props,
215
+ adapter
216
+ });
982
217
  const renderField = fieldConfig => {
983
- const isLookupField = fieldConfig.field === lookupField;
984
- const fieldId = getFieldId(fieldConfig.field);
985
- const labelId = `${fieldId}-label`;
986
- const errorId = `${fieldId}-error`;
987
- const fieldLabel = areLabelsLoading ? '' : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels[fieldConfig.field]) || fieldConfig.label;
988
- const fieldError = getFieldErrorMessage(fieldConfig.field);
989
- const isInvalid = hasVisibleFieldError(fieldConfig.field);
990
- const isRequired = fieldConfig.required || isFieldRequired(fieldConfig.field);
991
- const isValid = (0, _fieldValidation.getIsFieldValid)({
992
- showValidFields,
993
- fieldValue: formData[fieldConfig.field],
994
- hasError: isInvalid,
995
- isLookupField,
996
- verificationStatus
997
- });
998
- const isReadOnly = readOnlyView || !fieldConfig.editable && !isLookupField && isAutocompleteMode;
999
- const fieldWidth = fieldConfig.width === 'full' ? '100%' : fieldConfig.width === 'third' ? '33.333333%' : '50%';
1000
- const inputClassName = ["ns-address-lookup__input", isReadOnly ? "ns-address-lookup__input--readonly" : "", isInvalid ? "ns-address-lookup__input--invalid" : "", isLookupField && loading ? "ns-address-lookup__input--loading" : ""].filter(Boolean).join(" ");
1001
- const labelRowClassName = ["ns-address-lookup__label-row", isLookupField ? "" : "ns-address-lookup__label-row--field"].filter(Boolean).join(" ");
1002
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1003
- className: "ns-address-lookup__field",
1004
- style: {
1005
- width: fieldWidth
1006
- },
1007
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1008
- className: labelRowClassName,
1009
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
1010
- id: labelId,
1011
- htmlFor: fieldId,
1012
- className: "MuiFormLabel-root MuiFormLabel-colorPrimary css-1ef1ceb-MuiFormLabel-root",
1013
- children: [fieldLabel, isRequired && !areLabelsLoading && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
1014
- "aria-hidden": "true",
1015
- className: "MuiFormLabel-asterisk",
1016
- children: ' *'
1017
- })]
1018
- }), isLookupField && !readOnlyView && renderLookupActions()]
1019
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1020
- className: "ns-address-lookup__input-shell",
1021
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_foundationUiComponents.NsInputField, {
1022
- id: fieldId,
1023
- type: "text",
1024
- value: formData[fieldConfig.field] || '',
1025
- "aria-invalid": shouldShowFieldError(fieldConfig.field) ? 'true' : undefined,
1026
- fieldState: isInvalid ? 'error' : isValid ? 'success' : undefined,
1027
- required: isRequired,
1028
- onBlur: () => handleFieldBlur(fieldConfig.field),
1029
- onKeyDown: isLookupField && !readOnlyView ? handleLookupInputKeyDown : undefined,
1030
- onChange: e => {
1031
- const filtered = (0, _validators.filterAllowedCharacters)(e.target.value, fieldConfig.allowedCharacters);
1032
- if (readOnlyView) {
1033
- return;
1034
- }
1035
- if (isLookupField && isAutocompleteMode) {
1036
- handleInputChange({
1037
- ...e,
1038
- target: {
1039
- ...e.target,
1040
- value: filtered
1041
- }
1042
- });
1043
- } else {
1044
- handleEditableFieldChange(fieldConfig.field, filtered);
1045
- }
1046
- },
1047
- InputProps: {
1048
- readOnly: isReadOnly
1049
- },
1050
- inputProps: {
1051
- maxLength: fieldConfig.maxLength,
1052
- 'aria-labelledby': labelId,
1053
- 'aria-errormessage': fieldError ? errorId : undefined,
1054
- 'aria-invalid': isInvalid ? 'true' : undefined,
1055
- 'data-testid': getFieldTestId(fieldConfig.field)
1056
- },
1057
- className: inputClassName
1058
- }), loading && isAutocompleteMode && isLookupField && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1059
- className: "ns-address-lookup__spinner"
1060
- })]
1061
- }), fieldError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1062
- id: errorId,
1063
- className: "ns-address-lookup__error-text",
1064
- role: "alert",
1065
- children: fieldError
1066
- }), renderLookupLists(isLookupField)]
1067
- }, getFieldKey(fieldConfig));
218
+ var _c$fieldLabels;
219
+ const isLookupField = fieldConfig.field === c.lookupField;
220
+ const actions = isLookupField && !c.readOnlyView ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_LookupActions.default, {
221
+ fieldLabels: c.fieldLabels,
222
+ showMapAction: c.showMapAction,
223
+ onOpenMap: c.handleOpenMap,
224
+ isAutocompleteMode: c.isAutocompleteMode,
225
+ allowValidation: c.allowValidation,
226
+ onValidate: c.handleValidate,
227
+ validationDisabled: c.validationLoading || !String(c.formData[c.lookupField] || '').trim(),
228
+ validationLoading: c.validationLoading,
229
+ entryMode: c.entryMode,
230
+ isManualToggle: c.mode === 'autocomplete',
231
+ onModeSwitch: c.handleModeSwitch
232
+ }) : null;
233
+ const lookupLists = isLookupField ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_LookupResults.default, {
234
+ readOnlyView: c.readOnlyView,
235
+ allowValidation: c.allowValidation,
236
+ showValidationSuggestions: c.showValidationSuggestions,
237
+ isAutocompleteMode: c.isAutocompleteMode,
238
+ validationTriggerSource: c.validationTriggerSource,
239
+ validationResultsVisibleSources: VALIDATION_RESULTS_VISIBLE_SOURCES,
240
+ validationLoading: c.validationLoading,
241
+ validationServiceError: c.validationServiceError,
242
+ mapValidationStarted: c.mapValidationStartedRef.current,
243
+ suggestions: c.suggestions,
244
+ selectedAddress: c.selectedAddress,
245
+ suggestionsListRef: c.suggestionsListRef,
246
+ getLookupSuggestionKey: getLookupSuggestionKey,
247
+ onLookupSelect: c.handleSelect,
248
+ onSuggestionKeyDown: c.handleSuggestionButtonKeyDown,
249
+ validationSuggestions: c.validationSuggestions,
250
+ getValidationSuggestionKey: getValidationSuggestionKey,
251
+ getValidationSummaryTitle: suggestion => getValidationSummaryTitle(suggestion, c.fieldLabels),
252
+ getValidationSummaryMessage: suggestion => getValidationSummaryMessage(suggestion, c.fieldLabels),
253
+ notVerifiedCode: "not-verified",
254
+ onValidationSelect: c.handleValidationSelect,
255
+ noResultsLabel: (_c$fieldLabels = c.fieldLabels) === null || _c$fieldLabels === void 0 ? void 0 : _c$fieldLabels.intlNoResults
256
+ }) : null;
257
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AddressFieldRow.default, {
258
+ fieldConfig: fieldConfig,
259
+ lookupField: c.lookupField,
260
+ formData: c.formData,
261
+ fieldLabels: c.fieldLabels,
262
+ areLabelsLoading: c.areLabelsLoading,
263
+ readOnlyView: c.readOnlyView,
264
+ isAutocompleteMode: c.isAutocompleteMode,
265
+ loading: c.loading,
266
+ showValidFields: c.showValidFields,
267
+ verificationStatus: c.verificationStatus,
268
+ fieldValidation: c.fieldValidation,
269
+ onBlur: c.handleFieldBlur,
270
+ onLookupKeyDown: c.handleLookupInputKeyDown,
271
+ onChange: c.handleFieldInputChange,
272
+ actions: actions,
273
+ lookupLists: lookupLists
274
+ }, fieldConfig.field);
1068
275
  };
1069
276
  const renderAddressForm = () => {
1070
- const config = resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements;
1071
- const hasRequiredFields = requiredFields.length > 0;
277
+ var _c$resolvedAddressFor, _c$fieldLabels3;
278
+ const config = (_c$resolvedAddressFor = c.resolvedAddressForm) === null || _c$resolvedAddressFor === void 0 ? void 0 : _c$resolvedAddressFor.addressElements;
279
+ const hasRequiredFields = c.requiredFields.length > 0;
1072
280
  if (!(config !== null && config !== void 0 && config.length)) {
1073
- if (isFormLoading) {
281
+ if (c.isFormLoading) {
282
+ var _c$fieldLabels2;
1074
283
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1075
- children: fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.loadingAddressForm
284
+ children: (_c$fieldLabels2 = c.fieldLabels) === null || _c$fieldLabels2 === void 0 ? void 0 : _c$fieldLabels2.loadingAddressForm
1076
285
  });
1077
286
  }
1078
287
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
@@ -1080,53 +289,31 @@ const SmartyIntlResults = ({
1080
289
  });
1081
290
  }
1082
291
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1083
- children: [hasRequiredFields && !readOnlyView && !areLabelsLoading && !suppressRequiredFieldsHint && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
292
+ children: [hasRequiredFields && !c.readOnlyView && !c.areLabelsLoading && !suppressRequiredFieldsHint && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1084
293
  className: "ns-address-lookup__required-hint",
1085
- children: fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.requiredFieldsHint
294
+ children: (_c$fieldLabels3 = c.fieldLabels) === null || _c$fieldLabels3 === void 0 ? void 0 : _c$fieldLabels3.requiredFieldsHint
1086
295
  }), config.map(renderField)]
1087
296
  });
1088
297
  };
1089
298
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1090
- ref: componentRef,
299
+ ref: c.componentRef,
1091
300
  className: "ns-address-lookup__panel",
1092
- children: [lookupServiceError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
301
+ children: [c.lookupServiceError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1093
302
  className: "ns-address-lookup__message",
1094
- children: lookupErrorMessage
1095
- }), customError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
303
+ children: c.lookupErrorMessage
304
+ }), c.customError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1096
305
  className: "ns-address-lookup__message",
1097
- children: customError
1098
- }), allowValidation && validationServiceError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
306
+ children: c.customError
307
+ }), c.allowValidation && c.validationServiceError && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1099
308
  className: "ns-address-lookup__message",
1100
- children: validationErrorMessage
309
+ children: c.validationErrorMessage
1101
310
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1102
311
  className: "ns-address-lookup__form",
1103
312
  children: renderAddressForm()
1104
- }), showMapModal && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1105
- className: "ns-address-lookup__modal-backdrop",
1106
- onClick: () => setShowMapModal(false),
1107
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1108
- className: "ns-address-lookup__modal",
1109
- role: "dialog",
1110
- "aria-modal": "true",
1111
- "aria-label": fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.addressLocation,
1112
- onClick: event => event.stopPropagation(),
1113
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1114
- className: "ns-address-lookup__modal-header",
1115
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1116
- className: "ns-address-lookup__modal-title",
1117
- children: fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.addressLocation
1118
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
1119
- type: "button",
1120
- className: "ns-address-lookup__toggle",
1121
- "aria-label": "Close",
1122
- onClick: () => setShowMapModal(false),
1123
- children: "X"
1124
- })]
1125
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
1126
- ref: mapContainerRef,
1127
- className: "ns-address-lookup__map"
1128
- })]
1129
- })
313
+ }), c.showMapModal && /*#__PURE__*/(0, _jsxRuntime.jsx)(_AddressMapModal.default, {
314
+ label: (_c$fieldLabels4 = c.fieldLabels) === null || _c$fieldLabels4 === void 0 ? void 0 : _c$fieldLabels4.addressLocation,
315
+ mapContainerRef: c.mapContainerRef,
316
+ onClose: () => c.setShowMapModal(false)
1130
317
  })]
1131
318
  });
1132
319
  };