@quantaroute/checkout 1.7.1 → 1.7.2

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.
@@ -1,11 +1,17 @@
1
1
  import React, { useEffect, useRef, useState, useCallback, useId } from 'react';
2
2
  import maplibregl from 'maplibre-gl';
3
3
  import 'maplibre-gl/dist/maplibre-gl.css';
4
+ import type { MapMouseEvent, Map as MapLibreMap, Marker as MapLibreMarker } from 'maplibre-gl';
4
5
  import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '../core/digipin';
5
6
  import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
6
7
  import type { AutocompleteSuggestion } from '../core/api';
7
8
  import { useGeolocation } from '../hooks/useGeolocation';
8
9
  import type { MapPinSelectorProps } from '../core/types';
10
+ import {
11
+ DEFAULT_MAP_STYLE_URL,
12
+ waitForExternalMapRuntime,
13
+ type MapRuntime,
14
+ } from '../core/map-runtime';
9
15
 
10
16
  // ─── Constants ───────────────────────────────────────────────────────────────
11
17
 
@@ -15,13 +21,7 @@ const MIN_ZOOM = 6; // users cannot zoom out beyond a useful India-level v
15
21
  const OVERVIEW_ZOOM = 9;
16
22
  const STREET_ZOOM = 18;
17
23
 
18
- /**
19
- * Carto Positron – free vector basemap, no API key required.
20
- * Attribution: © OpenStreetMap contributors © CARTO
21
- * Terms: https://carto.com/legal/
22
- */
23
- const CARTO_STYLE_URL =
24
- 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
24
+ type MapLoadState = 'loading' | 'ready' | 'unavailable' | 'error';
25
25
 
26
26
  // ─── Pin dimensions ───────────────────────────────────────────────────────────
27
27
  // MUST match the SVG width/height exactly.
@@ -99,6 +99,149 @@ function createPinElement(brandColor: string = DEFAULT_BRAND): HTMLDivElement {
99
99
  return el;
100
100
  }
101
101
 
102
+ function collapseCompactAttribution(container: HTMLElement | null): void {
103
+ const attribEl = container?.querySelector(
104
+ '.maplibregl-ctrl-attrib.maplibregl-compact'
105
+ );
106
+ if (attribEl instanceof HTMLElement) {
107
+ attribEl.classList.remove('maplibregl-compact-show');
108
+ attribEl.setAttribute('open', '');
109
+ }
110
+ }
111
+
112
+ function initMapWithRuntime(
113
+ runtime: MapRuntime,
114
+ container: HTMLDivElement,
115
+ markerRef: React.MutableRefObject<MapLibreMarker | null>,
116
+ options: {
117
+ styleUrl: string;
118
+ initLat: number;
119
+ initLng: number;
120
+ initZoom: number;
121
+ brandColor: string;
122
+ indiaBoundaryUrl?: string;
123
+ refreshDigipin: (la: number, lo: number) => void;
124
+ onReady: () => void;
125
+ onError: (message: string) => void;
126
+ }
127
+ ): { map: MapLibreMap; cleanup: () => void } {
128
+ const {
129
+ styleUrl,
130
+ initLat,
131
+ initLng,
132
+ initZoom,
133
+ brandColor,
134
+ indiaBoundaryUrl,
135
+ refreshDigipin,
136
+ onReady,
137
+ onError,
138
+ } = options;
139
+
140
+ const boundaryPromise: Promise<unknown> = indiaBoundaryUrl
141
+ ? fetch(indiaBoundaryUrl)
142
+ .then((r) => (r.ok ? r.json() : null))
143
+ .catch(() => null)
144
+ : Promise.resolve(null);
145
+
146
+ const map = new runtime.Map({
147
+ container,
148
+ style: styleUrl,
149
+ center: [initLng, initLat],
150
+ zoom: initZoom,
151
+ minZoom: MIN_ZOOM,
152
+ attributionControl: false,
153
+ touchZoomRotate: true,
154
+ });
155
+
156
+ if (typeof runtime.AttributionControl === 'function') {
157
+ map.addControl(
158
+ new runtime.AttributionControl({
159
+ compact: true,
160
+ customAttribution:
161
+ '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors &nbsp;© <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>',
162
+ }),
163
+ 'bottom-right'
164
+ );
165
+ }
166
+
167
+ if (typeof runtime.NavigationControl === 'function') {
168
+ map.addControl(
169
+ new runtime.NavigationControl({ showCompass: false }),
170
+ 'top-right'
171
+ );
172
+ }
173
+
174
+ let marker: MapLibreMarker | null = null;
175
+
176
+ map.on('load', () => {
177
+ collapseCompactAttribution(container);
178
+ onReady();
179
+
180
+ boundaryPromise.then((geoJson) => {
181
+ if (!geoJson || !map.isStyleLoaded()) return;
182
+ try {
183
+ map.addSource('india-boundary', {
184
+ type: 'geojson',
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+ data: geoJson as any,
187
+ });
188
+ map.addLayer({
189
+ id: 'india-boundary-line',
190
+ type: 'line',
191
+ source: 'india-boundary',
192
+ paint: {
193
+ 'line-color': '#94a3b8',
194
+ 'line-width': 1.5,
195
+ 'line-opacity': 0.65,
196
+ },
197
+ });
198
+ } catch {
199
+ // Silent: duplicate source/layer on hot-reload is not an error
200
+ }
201
+ });
202
+
203
+ marker = new runtime.Marker({
204
+ element: createPinElement(brandColor),
205
+ draggable: true,
206
+ anchor: 'bottom',
207
+ })
208
+ .setLngLat([initLng, initLat])
209
+ .addTo(map);
210
+
211
+ markerRef.current = marker;
212
+
213
+ marker.on('drag', () => {
214
+ const pos = marker!.getLngLat();
215
+ refreshDigipin(pos.lat, pos.lng);
216
+ });
217
+
218
+ marker.on('dragend', () => {
219
+ const pos = marker!.getLngLat();
220
+ map.easeTo({ center: [pos.lng, pos.lat], duration: 250 });
221
+ });
222
+ });
223
+
224
+ map.on('error', () => {
225
+ onError('Map tiles could not load. Please try again.');
226
+ });
227
+
228
+ map.on('click', (e: MapMouseEvent) => {
229
+ const pos = e.lngLat;
230
+ marker?.setLngLat([pos.lng, pos.lat]);
231
+ refreshDigipin(pos.lat, pos.lng);
232
+ map.easeTo({ center: [pos.lng, pos.lat], duration: 200 });
233
+ });
234
+
235
+ return {
236
+ map,
237
+ cleanup: () => {
238
+ markerRef.current = null;
239
+ marker = null;
240
+ map.remove();
241
+ },
242
+ };
243
+ }
244
+
102
245
  // ─── Component ───────────────────────────────────────────────────────────────
103
246
 
104
247
  const MapPinSelector: React.FC<MapPinSelectorProps> = ({
@@ -112,10 +255,12 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
112
255
  apiKey,
113
256
  apiBaseUrl,
114
257
  brandColor = DEFAULT_BRAND,
258
+ mapStyle = DEFAULT_MAP_STYLE_URL,
259
+ embedMode = 'bundled',
115
260
  }) => {
116
261
  const containerRef = useRef<HTMLDivElement>(null);
117
- const mapRef = useRef<maplibregl.Map | null>(null);
118
- const markerRef = useRef<maplibregl.Marker | null>(null);
262
+ const mapRef = useRef<MapLibreMap | null>(null);
263
+ const markerRef = useRef<MapLibreMarker | null>(null);
119
264
 
120
265
  const initLat = defaultLat ?? INDIA_CENTER.lat;
121
266
  const initLng = defaultLng ?? INDIA_CENTER.lng;
@@ -127,6 +272,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
127
272
  computeDigiPinSafe(initLat, initLng)
128
273
  );
129
274
  const [mapLoaded, setMapLoaded] = useState(false);
275
+ const [mapState, setMapState] = useState<MapLoadState>('loading');
276
+ const [mapError, setMapError] = useState<string | null>(null);
130
277
 
131
278
  // ── Search state ─────────────────────────────────────────────────────────
132
279
  const [searchQuery, setSearchQuery] = useState('');
@@ -141,17 +288,15 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
141
288
  const { loading: geoLoading, error: geoError, locate, clearError } = useGeolocation();
142
289
 
143
290
  const refreshDigipin = useCallback((la: number, lo: number) => {
291
+ setLat(la);
292
+ setLng(lo);
144
293
  setDigipin(computeDigiPinSafe(la, lo));
145
294
  }, []);
146
295
 
147
296
  // ── Fly map + move pin to a coord ────────────────────────────────────────
148
297
  const flyToCoord = useCallback((la: number, lo: number) => {
149
- setLat(la);
150
- setLng(lo);
151
298
  refreshDigipin(la, lo);
152
- if (mapRef.current) {
153
- mapRef.current.flyTo({ center: [lo, la], zoom: STREET_ZOOM, duration: 900, essential: true });
154
- }
299
+ mapRef.current?.flyTo({ center: [lo, la], zoom: STREET_ZOOM, duration: 900, essential: true });
155
300
  markerRef.current?.setLngLat([lo, la]);
156
301
  }, [refreshDigipin]);
157
302
 
@@ -165,7 +310,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
165
310
 
166
311
  const trimmed = value.trim();
167
312
 
168
- // Empty — close dropdown
169
313
  if (!trimmed) {
170
314
  setSuggestions([]);
171
315
  setDropdownOpen(false);
@@ -173,8 +317,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
173
317
  return;
174
318
  }
175
319
 
176
- // DigiPin input — resolve 100% offline, instant, zero API cost
177
- // Keep the text in the input so the user can see what resolved.
178
320
  if (looksLikeDigiPin(trimmed)) {
179
321
  try {
180
322
  const coords = getLatLngFromDigiPin(trimmed);
@@ -190,7 +332,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
190
332
  return;
191
333
  }
192
334
 
193
- // Partial DigiPin (compact/spaced/dashed) — wait for full code, skip autocomplete
194
335
  if (couldBeDigiPinInput(trimmed)) {
195
336
  setSuggestions([]);
196
337
  setDropdownOpen(false);
@@ -198,7 +339,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
198
339
  return;
199
340
  }
200
341
 
201
- // Address search — debounce 400 ms, need ≥ 3 chars
202
342
  if (trimmed.length < 3) {
203
343
  setSuggestions([]);
204
344
  setDropdownOpen(false);
@@ -209,7 +349,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
209
349
  debounceRef.current = setTimeout(async () => {
210
350
  try {
211
351
  const key = apiKey ?? '';
212
- // Forward current pin position so the API can bias/bound results nearby
213
352
  const results = await autocompleteAddress(trimmed, key, apiBaseUrl, 5, lat, lng);
214
353
  setSuggestions(results);
215
354
  setDropdownOpen(results.length > 0);
@@ -221,9 +360,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
221
360
  setSearchLoading(false);
222
361
  }
223
362
  }, 400);
224
- }, [apiKey, apiBaseUrl, flyToCoord]);
363
+ }, [apiKey, apiBaseUrl, flyToCoord, lat, lng]);
225
364
 
226
- // ── Pick a suggestion from the dropdown ──────────────────────────────────
227
365
  const handleSuggestionSelect = useCallback((s: AutocompleteSuggestion) => {
228
366
  flyToCoord(s.coordinates.latitude, s.coordinates.longitude);
229
367
  setSearchQuery('');
@@ -240,159 +378,96 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
240
378
  }
241
379
  }, []);
242
380
 
243
- // ── Map initialization (runs once) ────────────────────────────────────────
381
+ // ── Map initialization ────────────────────────────────────────────────────
244
382
  useEffect(() => {
245
383
  if (!containerRef.current) return;
246
384
 
247
- // ── Fetch India boundary GeoJSON eagerly, in parallel with map style load ──
248
- // Starting the fetch here (before map fires 'load') means by the time the
249
- // map is ready the data is likely already parsed → zero perceived delay.
250
- // Silent failure: the boundary is a legal safeguard, not critical UI.
251
- const boundaryPromise: Promise<unknown> = indiaBoundaryUrl
252
- ? fetch(indiaBoundaryUrl)
253
- .then((r) => (r.ok ? r.json() : null))
254
- .catch(() => null)
255
- : Promise.resolve(null);
385
+ let cancelled = false;
386
+ let cancelWait: (() => void) | null = null;
387
+ let mapCleanup: (() => void) | null = null;
256
388
 
257
389
  const initZoom = hasDefault ? STREET_ZOOM : OVERVIEW_ZOOM;
390
+ const container = containerRef.current;
258
391
 
259
- const map = new maplibregl.Map({
260
- container: containerRef.current,
261
- style: CARTO_STYLE_URL,
262
- center: [initLng, initLat],
263
- zoom: initZoom,
264
- minZoom: MIN_ZOOM, // lock: cannot zoom out past level 7
265
- attributionControl: false,
266
- // Smooth touch gestures on mobile (tap center for zoom)
267
- touchZoomRotate: true,
268
- });
392
+ const mountMap = (runtime: MapRuntime) => {
393
+ if (cancelled || !containerRef.current) return;
269
394
 
270
- // Attribution (required by Carto & OSM terms)
271
- map.addControl(
272
- new maplibregl.AttributionControl({
273
- compact: true,
274
- customAttribution:
275
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors &nbsp;© <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>',
276
- }),
277
- 'bottom-right'
278
- );
279
-
280
- // Zoom +/− (hidden on small screens via CSS)
281
- map.addControl(
282
- new maplibregl.NavigationControl({ showCompass: false }),
283
- 'top-right'
284
- );
285
-
286
- map.on('load', () => {
287
- setMapLoaded(true);
395
+ try {
396
+ const { map, cleanup } = initMapWithRuntime(runtime, container, markerRef, {
397
+ styleUrl: mapStyle,
398
+ initLat,
399
+ initLng,
400
+ initZoom,
401
+ brandColor,
402
+ indiaBoundaryUrl,
403
+ refreshDigipin,
404
+ onReady: () => {
405
+ if (cancelled) return;
406
+ setMapLoaded(true);
407
+ setMapState('ready');
408
+ setMapError(null);
409
+ },
410
+ onError: (message) => {
411
+ if (cancelled) return;
412
+ setMapState((state) => (state === 'ready' ? state : 'error'));
413
+ setMapError(message);
414
+ },
415
+ });
288
416
 
289
- // MapLibre compact attribution starts expanded; collapse to icon-only.
290
- const attribEl = containerRef.current?.querySelector(
291
- '.maplibregl-ctrl-attrib.maplibregl-compact'
292
- );
293
- if (attribEl instanceof HTMLElement) {
294
- attribEl.classList.remove('maplibregl-compact-show');
295
- attribEl.setAttribute('open', '');
417
+ mapRef.current = map;
418
+ mapCleanup = cleanup;
419
+ } catch (err) {
420
+ setMapState('error');
421
+ setMapError(err instanceof Error ? err.message : 'Map failed to initialize.');
296
422
  }
423
+ };
297
424
 
298
- // ── India boundary overlay (legal compliance) ────────────────────────
299
- // Resolves instantly if the fetch finished before map loaded (typical),
300
- // or waits the remaining milliseconds if still in-flight.
301
- boundaryPromise.then((geoJson) => {
302
- if (!geoJson || !map.isStyleLoaded()) return;
303
- try {
304
- map.addSource('india-boundary', {
305
- type: 'geojson',
306
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
307
- data: geoJson as any,
308
- });
309
- map.addLayer({
310
- id: 'india-boundary-line',
311
- type: 'line',
312
- source: 'india-boundary',
313
- paint: {
314
- 'line-color': '#94a3b8', // slate-400 — subtle grey
315
- 'line-width': 1.5,
316
- 'line-opacity': 0.65,
317
- },
318
- });
319
- } catch {
320
- // Silent: duplicate source/layer on hot-reload is not an error
321
- }
322
- });
323
-
324
- // Create draggable pin marker.
325
- // anchor='bottom' → MapLibre aligns element's bottom-center with the coord.
326
- // Our SVG tip is at (20, 52) = exactly the bottom-center of the 40×52 element.
327
- // No offset needed — any offset shifts the tip away from the coordinate.
328
- const pinEl = createPinElement(brandColor);
329
- const marker = new maplibregl.Marker({
330
- element: pinEl,
331
- draggable: true,
332
- anchor: 'bottom',
333
- })
334
- .setLngLat([initLng, initLat])
335
- .addTo(map);
336
-
337
- // Live DigiPin update while dragging
338
- marker.on('drag', () => {
339
- const pos = marker.getLngLat();
340
- setLat(pos.lat);
341
- setLng(pos.lng);
342
- refreshDigipin(pos.lat, pos.lng);
343
- });
344
-
345
- // Re-center map after drag ends
346
- marker.on('dragend', () => {
347
- const pos = marker.getLngLat();
348
- map.easeTo({ center: [pos.lng, pos.lat], duration: 250 });
349
- });
350
-
351
- markerRef.current = marker;
352
- // DigiPin is already computed in useState() init; no need to recompute here.
353
- });
354
-
355
- // Tap/click map to reposition pin
356
- map.on('click', (e) => {
357
- const pos = e.lngLat;
358
- markerRef.current?.setLngLat([pos.lng, pos.lat]);
359
- setLat(pos.lat);
360
- setLng(pos.lng);
361
- refreshDigipin(pos.lat, pos.lng);
362
- map.easeTo({ center: [pos.lng, pos.lat], duration: 200 });
363
- });
425
+ const handleUnavailable = () => {
426
+ if (cancelled) return;
427
+ setMapState('unavailable');
428
+ setMapError('Map could not load. Check your connection and try again.');
429
+ };
364
430
 
365
- mapRef.current = map;
431
+ if (embedMode === 'external') {
432
+ cancelWait = waitForExternalMapRuntime(mountMap, handleUnavailable);
433
+ } else {
434
+ mountMap(maplibregl as MapRuntime);
435
+ }
366
436
 
367
437
  return () => {
368
- map.remove();
369
- mapRef.current = null;
438
+ cancelled = true;
439
+ cancelWait?.();
440
+ if (debounceRef.current) clearTimeout(debounceRef.current);
370
441
  markerRef.current = null;
442
+ mapRef.current = null;
443
+ mapCleanup?.();
371
444
  };
372
- // eslint-disable-next-line react-hooks/exhaustive-deps
373
- }, []); // intentionally empty – runs once on mount
445
+ }, [
446
+ brandColor,
447
+ embedMode,
448
+ hasDefault,
449
+ indiaBoundaryUrl,
450
+ initLat,
451
+ initLng,
452
+ mapStyle,
453
+ refreshDigipin,
454
+ ]);
374
455
 
375
456
  // ── Geolocation handler ───────────────────────────────────────────────────
376
457
  const handleLocateMe = useCallback(() => {
377
458
  clearError();
378
459
  locate((userLat, userLng) => {
379
- setLat(userLat);
380
- setLng(userLng);
381
460
  refreshDigipin(userLat, userLng);
382
-
383
- if (mapRef.current) {
384
- mapRef.current.flyTo({
385
- center: [userLng, userLat],
386
- zoom: STREET_ZOOM,
387
- duration: 1400,
388
- essential: true,
389
- });
390
- }
461
+ mapRef.current?.flyTo({
462
+ center: [userLng, userLat],
463
+ zoom: STREET_ZOOM,
464
+ duration: 1400,
465
+ essential: true,
466
+ });
391
467
  markerRef.current?.setLngLat([userLng, userLat]);
392
468
  });
393
469
  }, [locate, clearError, refreshDigipin]);
394
470
 
395
- // ── Confirm handler ───────────────────────────────────────────────────────
396
471
  const handleConfirm = useCallback(() => {
397
472
  if (digipin) {
398
473
  onLocationConfirm(lat, lng, digipin);
@@ -400,11 +475,11 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
400
475
  }, [lat, lng, digipin, onLocationConfirm]);
401
476
 
402
477
  const isInIndia = digipin !== null;
403
- const canConfirm = isInIndia && mapLoaded;
478
+ const canConfirm = isInIndia && mapLoaded && mapState === 'ready';
479
+ const showMapStatus = mapState !== 'ready';
404
480
 
405
481
  return (
406
482
  <div className="qr-map-wrapper">
407
- {/* ── Step header ── */}
408
483
  <div className="qr-step-header">
409
484
  <div className="qr-step-badge">1</div>
410
485
  <div className="qr-step-text">
@@ -415,11 +490,9 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
415
490
  </div>
416
491
  </div>
417
492
 
418
- {/* ── Search bar ── */}
419
493
  {enableSearch && (
420
494
  <div className="qr-search-bar" role="search">
421
495
  <div className="qr-search-bar__input-wrap">
422
- {/* Search icon */}
423
496
  <svg
424
497
  className="qr-search-bar__icon"
425
498
  aria-hidden="true"
@@ -452,12 +525,10 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
452
525
  aria-expanded={dropdownOpen}
453
526
  />
454
527
 
455
- {/* Inline loading spinner */}
456
528
  {searchLoading && (
457
529
  <span className="qr-search-bar__spinner qr-spinner qr-spinner--sm" aria-hidden="true" />
458
530
  )}
459
531
 
460
- {/* Clear button */}
461
532
  {searchQuery && !searchLoading && (
462
533
  <button
463
534
  type="button"
@@ -471,12 +542,10 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
471
542
  )}
472
543
  </div>
473
544
 
474
- {/* Inline error */}
475
545
  {searchError && (
476
546
  <p className="qr-search-bar__error" role="alert">{searchError}</p>
477
547
  )}
478
548
 
479
- {/* Suggestions dropdown */}
480
549
  {dropdownOpen && suggestions.length > 0 && (
481
550
  <ul
482
551
  id={listboxId}
@@ -491,7 +560,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
491
560
  role="option"
492
561
  aria-selected="false"
493
562
  onMouseDown={(e) => {
494
- e.preventDefault(); // keep input focus until after click
563
+ e.preventDefault();
495
564
  handleSuggestionSelect(s);
496
565
  }}
497
566
  >
@@ -519,7 +588,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
519
588
  </ul>
520
589
  )}
521
590
 
522
- {/* DigiPin hint chip */}
523
591
  <p className="qr-search-bar__hint">
524
592
  <span className="qr-search-bar__hint-chip">DigiPin</span>
525
593
  Type your DigiPin code for instant offline lookup — no API call
@@ -527,12 +595,22 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
527
595
  </div>
528
596
  )}
529
597
 
530
- {/* ── Map area ── */}
531
598
  <div className="qr-map-outer" style={{ height: mapHeight }}>
532
- {/* MapLibre GL container */}
533
599
  <div ref={containerRef} className="qr-map-canvas" />
534
600
 
535
- {/* DigiPin overlay badge – shown once inside India */}
601
+ {showMapStatus && (
602
+ <div className="qr-map-notice" role={mapState === 'loading' ? 'status' : 'alert'}>
603
+ {mapState === 'loading' ? (
604
+ <>
605
+ <span className="qr-spinner qr-spinner--sm" aria-hidden="true" />
606
+ <span>Loading map…</span>
607
+ </>
608
+ ) : (
609
+ mapError ?? 'Map is unavailable. Please try again.'
610
+ )}
611
+ </div>
612
+ )}
613
+
536
614
  {digipin && (
537
615
  <div className="qr-digipin-badge" aria-live="polite" aria-label={`DigiPin: ${digipin}`}>
538
616
  <span className="qr-digipin-badge__label">DigiPin</span>
@@ -540,18 +618,16 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
540
618
  </div>
541
619
  )}
542
620
 
543
- {/* Out-of-India notice */}
544
621
  {!isInIndia && mapLoaded && (
545
622
  <div className="qr-map-notice" role="status">
546
623
  Move map to India to get a DigiPin
547
624
  </div>
548
625
  )}
549
626
 
550
- {/* Locate-me button */}
551
627
  <button
552
628
  className={`qr-locate-btn${geoLoading ? ' qr-locate-btn--loading' : ''}`}
553
629
  onClick={handleLocateMe}
554
- disabled={geoLoading}
630
+ disabled={geoLoading || mapState !== 'ready'}
555
631
  title="Use my current location"
556
632
  aria-label="Use my current location"
557
633
  type="button"
@@ -564,23 +640,17 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
564
640
  viewBox="0 0 24 24"
565
641
  fill="none"
566
642
  stroke="currentColor"
567
- strokeWidth="2"
643
+ strokeWidth="2"
568
644
  strokeLinecap="round"
569
645
  strokeLinejoin="round"
570
646
  >
571
- {/* 1. Inner solid dot */}
572
647
  <circle cx="12" cy="12" r="3" fill="currentColor" stroke="none" />
573
-
574
- {/* 2. Outer ring */}
575
648
  <circle cx="12" cy="12" r="7" />
576
-
577
- {/* 3. Crosshair bumps attached to the ring */}
578
649
  <path d="M12 2v3M12 19v3M2 12h3M19 12h3" />
579
650
  </svg>
580
651
  )}
581
652
  </button>
582
653
 
583
- {/* Geo error toast */}
584
654
  {geoError && (
585
655
  <div className="qr-geo-error" role="alert">
586
656
  <span>{geoError}</span>
@@ -596,7 +666,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
596
666
  )}
597
667
  </div>
598
668
 
599
- {/* ── Coordinates strip ── */}
600
669
  {mapLoaded && (
601
670
  <div className="qr-coords-strip" aria-label="Current pin coordinates">
602
671
  <span>{lat.toFixed(5)}° N</span>
@@ -605,7 +674,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
605
674
  </div>
606
675
  )}
607
676
 
608
- {/* ── Confirm action bar ── */}
609
677
  <div className="qr-map-actions">
610
678
  <button
611
679
  type="button"
@@ -629,6 +697,13 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
629
697
  {!isInIndia && mapLoaded && (
630
698
  <p className="qr-map-hint">Move the pin to a location in India to continue</p>
631
699
  )}
700
+ {mapState !== 'ready' && (
701
+ <p className="qr-map-hint">
702
+ {mapState === 'loading'
703
+ ? 'Loading the map before location confirmation.'
704
+ : 'Map is unavailable, so location confirmation is paused.'}
705
+ </p>
706
+ )}
632
707
  </div>
633
708
  </div>
634
709
  );