@quantaroute/checkout 1.4.1 → 1.4.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.
@@ -70,21 +70,21 @@ throw new Error(`API error ${t.status}: ${e||t.statusText}`)}const i=await t.jso
70
70
  if(!i.success)throw new Error(i.message??"Reverse geocoding failed")
71
71
  return i}function v(){const[e,r]=n.useState({loading:!1,error:null})
72
72
  return{...e,locate:n.useCallback(e=>{navigator.geolocation?(r({loading:!0,error:null}),navigator.geolocation.getCurrentPosition(({coords:n})=>{r({loading:!1,error:null}),e(n.latitude,n.longitude)},e=>{let n="Unable to get location."
73
- e.code===e.PERMISSION_DENIED?n="Location permission denied. Please enable it in browser settings.":e.code===e.POSITION_UNAVAILABLE?n="Location unavailable. Try again or place the pin manually.":e.code===e.TIMEOUT&&(n="Location request timed out. Try again."),r({loading:!1,error:n})},{enableHighAccuracy:!0,timeout:12e3,maximumAge:0})):r({loading:!1,error:"Geolocation is not supported by your browser."})},[]),clearError:n.useCallback(()=>{r(e=>({...e,error:null}))},[])}}function g(e,r){if(!s(e,r))return null
74
- try{return o(e,r)}catch{return null}}const _="#0ea5e9",q=({onLocationConfirm:e,defaultLat:t,defaultLng:i,mapHeight:o="380px",theme:s="light",indiaBoundaryUrl:d,enableSearch:c=!0,apiKey:u,apiBaseUrl:h,brandColor:p=_})=>{const m=n.useRef(null),b=n.useRef(null),q=n.useRef(null),w=t??13.00427,N=i??77.589291,k=void 0!==t&&void 0!==i,[C,x]=n.useState(w),[E,S]=n.useState(N),[L,P]=n.useState(()=>g(w,N)),[I,T]=n.useState(!1),[A,B]=n.useState(""),[M,$]=n.useState([]),[O,D]=n.useState(!1),[F,U]=n.useState(null),[j,R]=n.useState(!1),W=n.useRef(null),J=n.useRef(null),z=n.useId(),{loading:V,error:H,locate:K,clearError:G}=v(),Z=n.useCallback((e,r)=>{P(g(e,r))},[]),Y=n.useCallback((e,r)=>{var n
73
+ e.code===e.PERMISSION_DENIED?n="Location permission denied. Please enable it in browser settings.":e.code===e.POSITION_UNAVAILABLE?n="Location unavailable. Try again or place the pin manually.":e.code===e.TIMEOUT&&(n="Location request timed out. Try again."),r({loading:!1,error:n})},{enableHighAccuracy:!0,timeout:12e3,maximumAge:0})):r({loading:!1,error:"Geolocation is not supported by your browser."})},[]),clearError:n.useCallback(()=>{r(e=>({...e,error:null}))},[])}}function _(e,r){if(!s(e,r))return null
74
+ try{return o(e,r)}catch{return null}}const g="#0ea5e9",q=({onLocationConfirm:e,defaultLat:t,defaultLng:i,mapHeight:o="380px",theme:s="light",indiaBoundaryUrl:d,enableSearch:c=!0,apiKey:u,apiBaseUrl:h,brandColor:p=g})=>{const m=n.useRef(null),b=n.useRef(null),q=n.useRef(null),w=t??13.00427,N=i??77.589291,k=void 0!==t&&void 0!==i,[C,x]=n.useState(w),[E,S]=n.useState(N),[L,P]=n.useState(()=>_(w,N)),[T,I]=n.useState(!1),[A,B]=n.useState(""),[M,O]=n.useState([]),[$,D]=n.useState(!1),[F,U]=n.useState(null),[j,R]=n.useState(!1),W=n.useRef(null),J=n.useRef(null),z=n.useId(),{loading:V,error:H,locate:K,clearError:G}=v(),Z=n.useCallback((e,r)=>{P(_(e,r))},[]),Y=n.useCallback((e,r)=>{var n
75
75
  x(e),S(r),Z(e,r),b.current&&b.current.flyTo({center:[r,e],zoom:18,duration:900,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])},[Z]),Q=n.useCallback(e=>{const r=e.target.value
76
76
  B(r),U(null),W.current&&clearTimeout(W.current)
77
77
  const n=r.trim()
78
- if(!n)return $([]),R(!1),void D(!1)
78
+ if(!n)return O([]),R(!1),void D(!1)
79
79
  if(f(n))try{const e=l(n.toUpperCase()),r=parseFloat(e.latitude),a=parseFloat(e.longitude)
80
- Y(r,a),$([]),R(!1),B(n.toUpperCase())}catch{U("Invalid DigiPin code")}else{if(n.length<3)return $([]),void R(!1)
80
+ Y(r,a),O([]),R(!1),B(n.toUpperCase())}catch{U("Invalid DigiPin code")}else{if(n.length<3)return O([]),void R(!1)
81
81
  D(!0),W.current=setTimeout(async()=>{try{const e=u??"",r=await y(n,e,h,5,C,E)
82
- $(r),R(r.length>0)}catch(e){U(e instanceof Error?e.message:"Search failed"),$([]),R(!1)}finally{D(!1)}},400)}},[u,h,Y]),X=n.useCallback(e=>{var r
83
- Y(e.coordinates.latitude,e.coordinates.longitude),B(""),$([]),R(!1),null==(r=J.current)||r.blur()},[Y]),ee=n.useCallback(e=>{"Escape"===e.key&&($([]),R(!1),B(""))},[])
82
+ O(r),R(r.length>0)}catch(e){U(e instanceof Error?e.message:"Search failed"),O([]),R(!1)}finally{D(!1)}},400)}},[u,h,Y]),X=n.useCallback(e=>{var r
83
+ Y(e.coordinates.latitude,e.coordinates.longitude),B(""),O([]),R(!1),null==(r=J.current)||r.blur()},[Y]),ee=n.useCallback(e=>{"Escape"===e.key&&(O([]),R(!1),B(""))},[])
84
84
  n.useEffect(()=>{if(!m.current)return
85
85
  const e=d?fetch(d).then(e=>e.ok?e.json():null).catch(()=>null):Promise.resolve(null),r=k?18:9,n=new a.Map({container:m.current,style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",center:[N,w],zoom:r,minZoom:6,attributionControl:!1,touchZoomRotate:!0})
86
- return n.addControl(new a.AttributionControl({compact:!0,customAttribution:'© <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>'}),"bottom-right"),n.addControl(new a.NavigationControl({showCompass:!1}),"top-right"),n.on("load",()=>{T(!0),e.then(e=>{if(e&&n.isStyleLoaded())try{n.addSource("india-boundary",{type:"geojson",data:e}),n.addLayer({id:"india-boundary-line",type:"line",source:"india-boundary",paint:{"line-color":"#94a3b8","line-width":1.5,"line-opacity":.65}})}catch{}})
87
- const r=function(e=_){const r=document.createElement("div")
86
+ return n.addControl(new a.AttributionControl({compact:!0,customAttribution:'© <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>'}),"bottom-right"),n.addControl(new a.NavigationControl({showCompass:!1}),"top-right"),n.on("load",()=>{I(!0),e.then(e=>{if(e&&n.isStyleLoaded())try{n.addSource("india-boundary",{type:"geojson",data:e}),n.addLayer({id:"india-boundary-line",type:"line",source:"india-boundary",paint:{"line-color":"#94a3b8","line-width":1.5,"line-opacity":.65}})}catch{}})
87
+ const r=function(e=g){const r=document.createElement("div")
88
88
  return r.className="qr-pin",r.setAttribute("aria-label","Drag to adjust your location"),r.style.width="40px",r.style.height="52px",r.innerHTML=`\n <svg\n class="qr-pin__svg"\n width="40"\n height="52"\n viewBox="0 0 40 52"\n overflow="visible"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n aria-hidden="true"\n >\n <defs>\n \x3c!--\n The filter region must be generous enough to contain the shadow blur.\n stdDeviation=3 → ~9px blur radius; our region extends 50% on each side.\n overflow="visible" on the <svg> lets it paint outside the viewport.\n --\x3e\n <filter id="qr-pin-shadow" x="-60%" y="-40%" width="220%" height="220%">\n <feDropShadow dx="0" dy="3" stdDeviation="3.5"\n flood-color="#000" flood-opacity="0.28"/>\n </filter>\n </defs>\n\n \x3c!-- Teardrop body — tip is at (20, 52) = bottom-center of the SVG --\x3e\n <path\n d="M20 0C9.402 0 0 9.402 0 20C0 34 20 52 20 52S40 34 40 20C40 9.402 30.598 0 20 0Z"\n fill="${e}"\n filter="url(#qr-pin-shadow)"\n />\n \x3c!-- Dot inside the pin --\x3e\n <circle cx="20" cy="20" r="9" fill="white"/>\n <circle cx="20" cy="20" r="5" fill="${e}"/>\n </svg>\n\n \x3c!--\n Pulse ring — position: absolute inside .qr-pin (position: relative).\n bottom: -(height/2) → bottom: -10px centres the 20×20 circle\n exactly at y = PIN_H = 52px = the pin tip coordinate.\n --\x3e\n <div class="qr-pin__pulse" aria-hidden="true"></div>\n `,r}(p),t=new a.Marker({element:r,draggable:!0,anchor:"bottom"}).setLngLat([N,w]).addTo(n)
89
89
  t.on("drag",()=>{const e=t.getLngLat()
90
90
  x(e.lat),S(e.lng),Z(e.lat,e.lng)}),t.on("dragend",()=>{const e=t.getLngLat()
@@ -92,16 +92,17 @@ n.easeTo({center:[e.lng,e.lat],duration:250})}),q.current=t}),n.on("click",e=>{v
92
92
  const a=e.lngLat
93
93
  null==(r=q.current)||r.setLngLat([a.lng,a.lat]),x(a.lat),S(a.lng),Z(a.lat,a.lng),n.easeTo({center:[a.lng,a.lat],duration:200})}),b.current=n,()=>{n.remove(),b.current=null,q.current=null}},[])
94
94
  const re=n.useCallback(()=>{G(),K((e,r)=>{var n
95
- x(e),S(r),Z(e,r),b.current&&b.current.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])})},[K,G,Z]),ne=n.useCallback(()=>{L&&e(C,E,L)},[C,E,L,e]),ae=null!==L,te=ae&&I
96
- return r.jsxs("div",{className:"qr-map-wrapper",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("div",{className:"qr-step-badge",children:"1"}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Pin Your Location"}),r.jsx("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),c&&r.jsxs("div",{className:"qr-search-bar",role:"search",children:[r.jsxs("div",{className:"qr-search-bar__input-wrap",children:[r.jsxs("svg",{className:"qr-search-bar__icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("path",{d:"M21 21l-4.35-4.35"})]}),r.jsx("input",{ref:J,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:A,onChange:Q,onKeyDown:ee,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":j?z:void 0,"aria-expanded":j}),O&&r.jsx("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),A&&!O&&r.jsx("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{B(""),$([]),R(!1),U(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),F&&r.jsx("p",{className:"qr-search-bar__error",role:"alert",children:F}),j&&M.length>0&&r.jsx("ul",{id:z,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:M.map((e,n)=>r.jsxs("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:r=>{r.preventDefault(),X(e)},children:[r.jsxs("svg",{className:"qr-search-bar__suggestion-icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]}),r.jsxs("div",{className:"qr-search-bar__suggestion-text",children:[r.jsx("span",{className:"qr-search-bar__suggestion-name",children:e.displayName}),e.address&&e.address!==e.displayName&&r.jsx("span",{className:"qr-search-bar__suggestion-sub",children:e.address})]})]},n))}),r.jsxs("p",{className:"qr-search-bar__hint",children:[r.jsx("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),r.jsxs("div",{className:"qr-map-outer",style:{height:o},children:[r.jsx("div",{ref:m,className:"qr-map-canvas"}),L&&r.jsxs("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${L}`,children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:L})]}),!ae&&I&&r.jsx("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r.jsx("button",{className:"qr-locate-btn"+(V?" qr-locate-btn--loading":""),onClick:re,disabled:V,title:"Use my current location","aria-label":"Use my current location",type:"button",children:V?r.jsx("span",{className:"qr-spinner","aria-hidden":"true"}):r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"12",cy:"12",r:"7"}),r.jsx("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),H&&r.jsxs("div",{className:"qr-geo-error",role:"alert",children:[r.jsx("span",{children:H}),r.jsx("button",{type:"button",className:"qr-geo-error__dismiss",onClick:G,"aria-label":"Dismiss error",children:"×"})]})]}),I&&r.jsxs("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[r.jsxs("span",{children:[C.toFixed(5),"° N"]}),r.jsx("span",{className:"qr-coords-sep",children:"·"}),r.jsxs("span",{children:[E.toFixed(5),"° E"]})]}),r.jsxs("div",{className:"qr-map-actions",children:[r.jsxs("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:ne,disabled:!te,children:["Confirm Location",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!ae&&I&&r.jsx("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"})]})]})},w={flatNumber:"",floorNumber:"",buildingName:"",streetName:""}
95
+ x(e),S(r),Z(e,r),b.current&&b.current.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])})},[K,G,Z]),ne=n.useCallback(()=>{L&&e(C,E,L)},[C,E,L,e]),ae=null!==L,te=ae&&T
96
+ return r.jsxs("div",{className:"qr-map-wrapper",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("div",{className:"qr-step-badge",children:"1"}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Pin Your Location"}),r.jsx("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),c&&r.jsxs("div",{className:"qr-search-bar",role:"search",children:[r.jsxs("div",{className:"qr-search-bar__input-wrap",children:[r.jsxs("svg",{className:"qr-search-bar__icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("path",{d:"M21 21l-4.35-4.35"})]}),r.jsx("input",{ref:J,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:A,onChange:Q,onKeyDown:ee,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":j?z:void 0,"aria-expanded":j}),$&&r.jsx("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),A&&!$&&r.jsx("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{B(""),O([]),R(!1),U(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),F&&r.jsx("p",{className:"qr-search-bar__error",role:"alert",children:F}),j&&M.length>0&&r.jsx("ul",{id:z,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:M.map((e,n)=>r.jsxs("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:r=>{r.preventDefault(),X(e)},children:[r.jsxs("svg",{className:"qr-search-bar__suggestion-icon","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]}),r.jsxs("div",{className:"qr-search-bar__suggestion-text",children:[r.jsx("span",{className:"qr-search-bar__suggestion-name",children:e.displayName}),e.address&&e.address!==e.displayName&&r.jsx("span",{className:"qr-search-bar__suggestion-sub",children:e.address})]})]},n))}),r.jsxs("p",{className:"qr-search-bar__hint",children:[r.jsx("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),r.jsxs("div",{className:"qr-map-outer",style:{height:o},children:[r.jsx("div",{ref:m,className:"qr-map-canvas"}),L&&r.jsxs("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${L}`,children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:L})]}),!ae&&T&&r.jsx("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r.jsx("button",{className:"qr-locate-btn"+(V?" qr-locate-btn--loading":""),onClick:re,disabled:V,title:"Use my current location","aria-label":"Use my current location",type:"button",children:V?r.jsx("span",{className:"qr-spinner","aria-hidden":"true"}):r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"12",cy:"12",r:"7"}),r.jsx("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),H&&r.jsxs("div",{className:"qr-geo-error",role:"alert",children:[r.jsx("span",{children:H}),r.jsx("button",{type:"button",className:"qr-geo-error__dismiss",onClick:G,"aria-label":"Dismiss error",children:"×"})]})]}),T&&r.jsxs("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[r.jsxs("span",{children:[C.toFixed(5),"° N"]}),r.jsx("span",{className:"qr-coords-sep",children:"·"}),r.jsxs("span",{children:[E.toFixed(5),"° E"]})]}),r.jsxs("div",{className:"qr-map-actions",children:[r.jsxs("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:ne,disabled:!te,children:["Confirm Location",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!ae&&T&&r.jsx("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"})]})]})},w={flatNumber:"",floorNumber:"",buildingName:"",streetName:""}
97
97
  function N(e,r){switch(r.type){case"LOAD_START":return{status:"loading"}
98
98
  case"LOAD_SUCCESS":{const e=function(e){const r={}
99
99
  e.name?r.buildingName=e.name:e.building_name?r.buildingName=e.building_name:e.addr_housename&&(r.buildingName=e.addr_housename)
100
100
  const n=[]
101
101
  return e.road&&n.push(e.road),e.suburb&&n.push(e.suburb),n.length>0&&(r.streetName=n.join(", ")),r}(r.addressComponents)
102
- return{status:"ready",adminInfo:r.adminInfo,alternatives:r.alternatives||[],selectedLocality:r.adminInfo.locality,fields:{...w,...e},submitting:!1,pincodeHasDelivery:r.pincodeHasDelivery}}case"LOAD_ERROR":return{status:"error",message:r.message}
102
+ return{status:"ready",adminInfo:r.adminInfo,alternatives:r.alternatives||[],selectedLocality:r.adminInfo.locality,selectedLabel:"home",fields:{...w,...e},submitting:!1,pincodeHasDelivery:r.pincodeHasDelivery}}case"LOAD_ERROR":return{status:"error",message:r.message}
103
103
  case"SET_FIELD":return"ready"!==e.status?e:{...e,fields:{...e.fields,[r.key]:r.value}}
104
104
  case"SET_LOCALITY":return"ready"!==e.status?e:{...e,selectedLocality:r.locality}
105
+ case"SET_LABEL":return"ready"!==e.status?e:{...e,selectedLabel:r.label}
105
106
  case"SUBMIT_START":return"ready"!==e.status?e:{...e,submitting:!0}
106
107
  case"SUBMIT_END":return"ready"!==e.status?e:{...e,submitting:!1}
107
108
  default:return e}}const k=({digipin:e,lat:a,lng:t,apiKey:i,apiBaseUrl:o,onAddressComplete:l,onBack:s,onError:d})=>{const[c,u]=n.useReducer(N,{status:"loading"}),f=n.useCallback(async()=>{var r
@@ -115,10 +116,10 @@ u({type:"LOAD_SUCCESS",adminInfo:n.data.administrative_info,alternatives:n.data.
115
116
  u({type:"LOAD_ERROR",message:r}),null==d||d(e instanceof Error?e:new Error(r))}},[e,a,t,i,o,d])
116
117
  n.useEffect(()=>{f()},[f])
117
118
  const y=n.useCallback(r=>{if(r.preventDefault(),"ready"!==c.status)return
118
- const{adminInfo:n,selectedLocality:i,fields:o}=c,s=[o.flatNumber,o.floorNumber?`Floor ${o.floorNumber}`:"",o.buildingName,o.streetName,i,n.district,n.state,n.pincode].filter(Boolean),d={digipin:e,lat:a,lng:t,state:n.state,district:n.district,division:n.division,locality:i,pincode:n.pincode,delivery:n.delivery,country:n.country??"India",...o,formattedAddress:s.join(", ")}
119
+ const{adminInfo:n,selectedLocality:i,selectedLabel:o,fields:s}=c,d=[s.flatNumber,s.floorNumber?`Floor ${s.floorNumber}`:"",s.buildingName,s.streetName,i,n.district,n.state,n.pincode].filter(Boolean),h={digipin:e,lat:a,lng:t,state:n.state,district:n.district,division:n.division,locality:i,pincode:n.pincode,delivery:n.delivery,country:n.country??"India",...s,formattedAddress:d.join(", "),label:o}
119
120
  u({type:"SUBMIT_START"})
120
- try{l(d)}finally{u({type:"SUBMIT_END"})}},[c,e,a,t,l])
121
- return r.jsxs("div",{className:"qr-form-wrapper",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("button",{type:"button",className:"qr-back-btn",onClick:s,"aria-label":"Back to map",children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),r.jsx("div",{className:"qr-step-badge",children:"2"}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Add Address Details"}),r.jsx("span",{className:"qr-step-sub",children:"Flat number and building info"})]})]}),r.jsxs("div",{className:"qr-form-digipin-strip",children:[r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r.jsx("circle",{cx:"12",cy:"10",r:"3"})]}),r.jsx("span",{className:"qr-form-digipin-strip__label",children:"DigiPin"}),r.jsx("span",{className:"qr-form-digipin-strip__code",children:e})]}),"loading"===c.status&&r.jsxs("div",{className:"qr-loading-state","aria-busy":"true","aria-label":"Fetching address details",children:[r.jsx("div",{className:"qr-spinner qr-spinner--lg","aria-hidden":"true"}),r.jsx("p",{className:"qr-loading-state__text",children:"Fetching address details…"})]}),"error"===c.status&&r.jsxs("div",{className:"qr-error-state",role:"alert",children:[r.jsx("div",{className:"qr-error-state__icon","aria-hidden":"true",children:"⚠"}),r.jsx("p",{className:"qr-error-state__msg",children:c.message}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{f()},children:"Retry"})]}),"ready"===c.status&&r.jsxs("form",{onSubmit:y,className:"qr-form",noValidate:!0,children:[r.jsxs("fieldset",{className:"qr-fieldset",children:[r.jsxs("legend",{className:"qr-fieldset__legend",children:[r.jsx("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"📍"}),"Auto-detected from your pin"]}),r.jsxs("div",{className:"qr-auto-grid",children:[r.jsxs("div",{className:"qr-auto-row",children:[r.jsx("span",{className:"qr-auto-row__label",children:"State"}),r.jsx("span",{className:"qr-auto-row__value",children:c.adminInfo.state})]}),r.jsxs("div",{className:"qr-auto-row",children:[r.jsx("span",{className:"qr-auto-row__label",children:"District"}),r.jsx("span",{className:"qr-auto-row__value",children:c.adminInfo.district})]}),r.jsxs("div",{className:"qr-auto-row qr-auto-row--full",children:[r.jsx("span",{className:"qr-auto-row__label",children:"Locality"}),c.alternatives.length>0?r.jsxs("select",{className:"qr-auto-row__select",value:c.selectedLocality,onChange:e=>u({type:"SET_LOCALITY",locality:e.target.value}),"aria-label":"Select locality",children:[r.jsx("option",{value:c.adminInfo.locality,children:c.adminInfo.locality}),c.alternatives.map((e,n)=>r.jsx("option",{value:e.name,children:e.name},n))]}):r.jsx("span",{className:"qr-auto-row__value",children:c.selectedLocality})]}),r.jsxs("div",{className:"qr-auto-row",children:[r.jsx("span",{className:"qr-auto-row__label",children:"Pincode"}),r.jsx("span",{className:"qr-auto-row__value qr-auto-row__value--pin",children:c.adminInfo.pincode})]})]})]}),!c.pincodeHasDelivery&&r.jsxs("div",{className:"qr-pincode-banner qr-pincode-banner--warning",role:"status","aria-live":"polite",children:[r.jsx("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:"⚠"}),r.jsxs("div",{className:"qr-pincode-banner__text",children:[r.jsx("strong",{children:"Non-delivery area"}),r.jsx("span",{children:"This pincode has no India Post home-delivery office. Courier delivery may be limited — confirm with your seller before placing the order."})]})]}),r.jsxs("fieldset",{className:"qr-fieldset",children:[r.jsxs("legend",{className:"qr-fieldset__legend",children:[r.jsx("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"🏠"}),"Your details"]}),r.jsxs("div",{className:"qr-fields-grid",children:[r.jsxs("div",{className:"qr-field qr-field--full",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-flatNumber",children:["Flat / House Number",r.jsx("span",{className:"qr-required","aria-hidden":"true",children:"*"})]}),r.jsx("input",{id:"qr-flatNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 4B, Flat 201, House No. 12",value:c.fields.flatNumber,onChange:e=>u({type:"SET_FIELD",key:"flatNumber",value:e.target.value}),autoComplete:"address-line1",required:!0,"aria-required":"true"})]}),r.jsxs("div",{className:"qr-field",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-floorNumber",children:["Floor",r.jsx("span",{className:"qr-optional",children:"optional"})]}),r.jsx("input",{id:"qr-floorNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 3rd, Ground",value:c.fields.floorNumber,onChange:e=>u({type:"SET_FIELD",key:"floorNumber",value:e.target.value})})]}),r.jsxs("div",{className:"qr-field",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-buildingName",children:["Building / Society",r.jsx("span",{className:"qr-optional",children:"optional"})]}),r.jsx("input",{id:"qr-buildingName",type:"text",className:"qr-field__input",placeholder:"e.g. Sunshine Apts, DDA Colony",value:c.fields.buildingName,onChange:e=>u({type:"SET_FIELD",key:"buildingName",value:e.target.value}),autoComplete:"address-line2"})]}),r.jsxs("div",{className:"qr-field qr-field--full",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-streetName",children:["Street / Area",r.jsx("span",{className:"qr-optional",children:"optional"})]}),r.jsx("input",{id:"qr-streetName",type:"text",className:"qr-field__input",placeholder:"e.g. MG Road, Sector 12",value:c.fields.streetName,onChange:e=>u({type:"SET_FIELD",key:"streetName",value:e.target.value}),autoComplete:"address-level3"})]})]})]}),r.jsxs("div",{className:"qr-form-actions",children:[r.jsxs("button",{type:"button",className:"qr-btn qr-btn--ghost",onClick:s,children:[r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),"Adjust Pin"]}),r.jsx("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--grow",disabled:c.submitting||!c.fields.flatNumber.trim(),children:c.submitting?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Saving…"]}):r.jsxs(r.Fragment,{children:["Save Address",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M20 6L9 17l-5-5"})})]})})]})]})]})}
121
+ try{l(h)}finally{u({type:"SUBMIT_END"})}},[c,e,a,t,l])
122
+ return r.jsxs("div",{className:"qr-form-wrapper",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("button",{type:"button",className:"qr-back-btn",onClick:s,"aria-label":"Back to map",children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),r.jsx("div",{className:"qr-step-badge",children:"2"}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Add Address Details"}),r.jsx("span",{className:"qr-step-sub",children:"Flat number and building info"})]})]}),r.jsxs("div",{className:"qr-form-digipin-strip",children:[r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r.jsx("circle",{cx:"12",cy:"10",r:"3"})]}),r.jsx("span",{className:"qr-form-digipin-strip__label",children:"DigiPin"}),r.jsx("span",{className:"qr-form-digipin-strip__code",children:e})]}),"loading"===c.status&&r.jsxs("div",{className:"qr-loading-state","aria-busy":"true","aria-label":"Fetching address details",children:[r.jsx("div",{className:"qr-spinner qr-spinner--lg","aria-hidden":"true"}),r.jsx("p",{className:"qr-loading-state__text",children:"Fetching address details…"})]}),"error"===c.status&&r.jsxs("div",{className:"qr-error-state",role:"alert",children:[r.jsx("div",{className:"qr-error-state__icon","aria-hidden":"true",children:"⚠"}),r.jsx("p",{className:"qr-error-state__msg",children:c.message}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{f()},children:"Retry"})]}),"ready"===c.status&&r.jsxs("form",{onSubmit:y,className:"qr-form",noValidate:!0,children:[r.jsxs("fieldset",{className:"qr-fieldset",children:[r.jsxs("legend",{className:"qr-fieldset__legend",children:[r.jsx("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"📍"}),"Auto-detected from your pin"]}),r.jsxs("div",{className:"qr-auto-grid",children:[r.jsxs("div",{className:"qr-auto-row",children:[r.jsx("span",{className:"qr-auto-row__label",children:"State"}),r.jsx("span",{className:"qr-auto-row__value",children:c.adminInfo.state})]}),r.jsxs("div",{className:"qr-auto-row",children:[r.jsx("span",{className:"qr-auto-row__label",children:"District"}),r.jsx("span",{className:"qr-auto-row__value",children:c.adminInfo.district})]}),r.jsxs("div",{className:"qr-auto-row qr-auto-row--full",children:[r.jsx("span",{className:"qr-auto-row__label",children:"Locality"}),c.alternatives.length>0?r.jsxs("select",{className:"qr-auto-row__select",value:c.selectedLocality,onChange:e=>u({type:"SET_LOCALITY",locality:e.target.value}),"aria-label":"Select locality",children:[r.jsx("option",{value:c.adminInfo.locality,children:c.adminInfo.locality}),c.alternatives.map((e,n)=>r.jsx("option",{value:e.name,children:e.name},n))]}):r.jsx("span",{className:"qr-auto-row__value",children:c.selectedLocality})]}),r.jsxs("div",{className:"qr-auto-row",children:[r.jsx("span",{className:"qr-auto-row__label",children:"Pincode"}),r.jsx("span",{className:"qr-auto-row__value qr-auto-row__value--pin",children:c.adminInfo.pincode})]})]})]}),!c.pincodeHasDelivery&&r.jsxs("div",{className:"qr-pincode-banner qr-pincode-banner--warning",role:"status","aria-live":"polite",children:[r.jsx("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:"⚠"}),r.jsxs("div",{className:"qr-pincode-banner__text",children:[r.jsx("strong",{children:"Non-delivery area"}),r.jsx("span",{children:"This pincode has no India Post home-delivery office. Courier delivery may be limited — confirm with your seller before placing the order."})]})]}),r.jsxs("fieldset",{className:"qr-fieldset",children:[r.jsx("legend",{className:"qr-fieldset__legend",children:"Save as"}),r.jsx("div",{className:"qr-label-picker",role:"radiogroup","aria-label":"Address label",children:[{value:"home",title:"Home",icon:"🏠"},{value:"work",title:"Work",icon:"💼"},{value:"other",title:"Other",icon:"📍"}].map(({value:e,title:n,icon:a})=>r.jsxs("button",{type:"button",role:"radio","aria-checked":c.selectedLabel===e,className:"qr-label-picker__option"+(c.selectedLabel===e?" qr-label-picker__option--active":""),onClick:()=>u({type:"SET_LABEL",label:e}),children:[r.jsx("span",{className:"qr-label-picker__icon","aria-hidden":"true",children:a}),r.jsx("span",{children:n})]},e))})]}),r.jsxs("fieldset",{className:"qr-fieldset",children:[r.jsxs("legend",{className:"qr-fieldset__legend",children:[r.jsx("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"🏠"}),"Your details"]}),r.jsxs("div",{className:"qr-fields-grid",children:[r.jsxs("div",{className:"qr-field qr-field--full",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-flatNumber",children:["Flat / House Number",r.jsx("span",{className:"qr-required","aria-hidden":"true",children:"*"})]}),r.jsx("input",{id:"qr-flatNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 4B, Flat 201, House No. 12",value:c.fields.flatNumber,onChange:e=>u({type:"SET_FIELD",key:"flatNumber",value:e.target.value}),autoComplete:"address-line1",required:!0,"aria-required":"true"})]}),r.jsxs("div",{className:"qr-field",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-floorNumber",children:["Floor",r.jsx("span",{className:"qr-optional",children:"optional"})]}),r.jsx("input",{id:"qr-floorNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 3rd, Ground",value:c.fields.floorNumber,onChange:e=>u({type:"SET_FIELD",key:"floorNumber",value:e.target.value})})]}),r.jsxs("div",{className:"qr-field",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-buildingName",children:["Building / Society",r.jsx("span",{className:"qr-optional",children:"optional"})]}),r.jsx("input",{id:"qr-buildingName",type:"text",className:"qr-field__input",placeholder:"e.g. Sunshine Apts, DDA Colony",value:c.fields.buildingName,onChange:e=>u({type:"SET_FIELD",key:"buildingName",value:e.target.value}),autoComplete:"address-line2"})]}),r.jsxs("div",{className:"qr-field qr-field--full",children:[r.jsxs("label",{className:"qr-field__label",htmlFor:"qr-streetName",children:["Street / Area",r.jsx("span",{className:"qr-optional",children:"optional"})]}),r.jsx("input",{id:"qr-streetName",type:"text",className:"qr-field__input",placeholder:"e.g. MG Road, Sector 12",value:c.fields.streetName,onChange:e=>u({type:"SET_FIELD",key:"streetName",value:e.target.value}),autoComplete:"address-level3"})]})]})]}),r.jsxs("div",{className:"qr-form-actions",children:[r.jsxs("button",{type:"button",className:"qr-btn qr-btn--ghost",onClick:s,children:[r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),"Adjust Pin"]}),r.jsx("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--grow",disabled:c.submitting||!c.fields.flatNumber.trim(),children:c.submitting?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Saving…"]}):r.jsxs(r.Fragment,{children:["Save Address",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M20 6L9 17l-5-5"})})]})})]})]})]})}
122
123
  async function C(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"send",mobile:r,merchant_id:e.merchantId})}),a=await n.json().catch(()=>({}))
123
124
  if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")}async function x(e,r,n,a){const t=await fetch(`${e.functionBaseUrl}/checkout-otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify",mobile:r,otp:n,merchant_id:e.merchantId,...a})}),i=await t.json().catch(()=>({}))
124
125
  if(!t.ok||!i.success)throw new Error(i.error??"Invalid or expired OTP.")
@@ -127,8 +128,8 @@ if(!n.ok||!a.success)throw new Error(a.error??"Failed to load saved addresses.")
127
128
  return a.data??[]}async function L(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"create",address:n})}),t=await a.json().catch(()=>({}))
128
129
  if(!a.ok||!t.success)throw new Error(t.error??"Failed to save address.")
129
130
  return t.data}async function P(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"delete",address_id:n})}),t=await a.json().catch(()=>({}))
130
- if(!a.ok||!t.success)throw new Error(t.error??"Failed to delete address.")}async function I(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"set_default",address_id:n})}),t=await a.json().catch(()=>({}))
131
- if(!a.ok||!t.success)throw new Error(t.error??"Failed to set default address.")}async function T(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"address_completed",data:n})}),t=await a.json().catch(()=>({}))
131
+ if(!a.ok||!t.success)throw new Error(t.error??"Failed to delete address.")}async function T(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"set_default",address_id:n})}),t=await a.json().catch(()=>({}))
132
+ if(!a.ok||!t.success)throw new Error(t.error??"Failed to set default address.")}async function I(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"address_completed",data:n})}),t=await a.json().catch(()=>({}))
132
133
  !a.ok||t.success}async function A(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-email-otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"send",email:r,merchant_id:e.merchantId})}),a=await n.json().catch(()=>({}))
133
134
  if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")
134
135
  return{reused:Boolean(a.reused)}}async function B(e,r,n,a){const t=await fetch(`${e.functionBaseUrl}/checkout-email-otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify",email:r,code:n,merchant_id:e.merchantId,...a})}),i=await t.json().catch(()=>({}))
@@ -137,8 +138,8 @@ return i}async function M(e,r,n,a){const t={action:"cod_eligibility",pincode:n}
137
138
  void 0!==a&&(t.cart_total_paise=a)
138
139
  const i=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify(t)}),o=await i.json().catch(()=>({}))
139
140
  if(!i.ok||!o.success)throw new Error(o.error??"Failed to check COD eligibility.")
140
- return o.data}async function $(e,r,n){try{const a={"Content-Type":"application/json"}
141
- n&&(a["x-session-token"]=n),await fetch(`${e.functionBaseUrl}/checkout-funnel-events`,{method:"POST",headers:a,body:JSON.stringify({merchant_id:e.merchantId,...r})})}catch{}}async function O(e,r,n){try{await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"abandon",last_step:n})})}catch{}}async function D(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-offers`,{method:"GET",headers:E(r)}),a=await n.json().catch(()=>({}))
141
+ return o.data}async function O(e,r,n){try{const a={"Content-Type":"application/json"}
142
+ n&&(a["x-session-token"]=n),await fetch(`${e.functionBaseUrl}/checkout-funnel-events`,{method:"POST",headers:a,body:JSON.stringify({merchant_id:e.merchantId,...r})})}catch{}}async function $(e,r,n){try{await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:E(r),body:JSON.stringify({action:"abandon",last_step:n})})}catch{}}async function D(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-offers`,{method:"GET",headers:E(r)}),a=await n.json().catch(()=>({}))
142
143
  return n.ok&&a.success?a.data??null:null}async function F(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:E(r),body:JSON.stringify({action:"create_order",amount_paise:n})}),t=await a.json().catch(()=>({}))
143
144
  if(!a.ok||!t.success)throw new Error(t.error??"Failed to create payment order.")
144
145
  return t.data}async function U(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:E(r),body:JSON.stringify({action:"verify",...n})}),t=await a.json().catch(()=>({}))
@@ -151,23 +152,23 @@ d(!0),u(null)
151
152
  try{await C({functionBaseUrl:t,merchantId:i},`+91${o}`),e(`+91${o}`)}catch(e){u(e instanceof Error?e.message:"Failed to send OTP. Please try again.")}finally{d(!1)}},[o,t,i,e])
152
153
  return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("path",{d:"M16 14h4l2 5-2.5 1.5a11 11 0 005 5L26 23l5 2v4c0 1.1-.9 2-2 2A18 18 0 0114 16c0-1.1.9-2 2-2z",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r.jsx("p",{className:"qr-auth-step__sub",children:"Enter your mobile to load saved addresses"}),r.jsxs("form",{onSubmit:m,noValidate:!0,children:[r.jsxs("div",{className:"qr-phone-field"+(c?" qr-phone-field--error":""),children:[r.jsx("span",{className:"qr-phone-field__prefix","aria-hidden":"true",children:"+91"}),r.jsx("input",{ref:h,type:"tel",inputMode:"numeric",className:"qr-phone-field__input",placeholder:"98765 43210",value:o,onChange:p,maxLength:10,autoComplete:"tel-national","aria-label":"Mobile number","aria-describedby":c?"qr-phone-error":void 0,"aria-invalid":!!c,disabled:s})]}),c&&r.jsx("p",{id:"qr-phone-error",className:"qr-auth-step__error",role:"alert",children:c}),r.jsx("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:s||10!==o.length,children:s?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):r.jsxs(r.Fragment,{children:["Send OTP",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r.jsx("button",{type:"button",className:"qr-auth-step__skip",onClick:a,disabled:s,children:"Skip, enter address manually"})]})}
153
154
  function W(e){const r=e.replace(/\D/g,"")
154
- return r.length<4?e:`+91 ${r.slice(2,7)} **${r.slice(-3)}`}const J=({mobile:e,onVerified:a,onBack:t,functionBaseUrl:i,merchantId:o,sessionContext:l})=>{const[s,d]=n.useState(Array(6).fill("")),[c,u]=n.useState(!1),[h,p]=n.useState(null),[m,f]=n.useState(30),[y,b]=n.useState(!1),v=n.useRef([]),g=n.useRef(null)
155
- n.useEffect(()=>(g.current=setInterval(()=>{f(e=>e<=1?(clearInterval(g.current),0):e-1)},1e3),()=>{g.current&&clearInterval(g.current)}),[])
156
- const _=e=>{var r
155
+ return r.length<4?e:`+91 ${r.slice(2,7)} **${r.slice(-3)}`}const J=({mobile:e,onVerified:a,onBack:t,functionBaseUrl:i,merchantId:o,sessionContext:l})=>{const[s,d]=n.useState(Array(6).fill("")),[c,u]=n.useState(!1),[h,p]=n.useState(null),[m,f]=n.useState(30),[y,b]=n.useState(!1),v=n.useRef([]),_=n.useRef(null)
156
+ n.useEffect(()=>(_.current=setInterval(()=>{f(e=>e<=1?(clearInterval(_.current),0):e-1)},1e3),()=>{_.current&&clearInterval(_.current)}),[])
157
+ const g=e=>{var r
157
158
  null==(r=v.current[e])||r.focus()},q=n.useCallback((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
158
159
  p(null),d(r=>{const a=[...r]
159
- return a[e]=n,a}),n&&e<5&&_(e+1)},[]),w=n.useCallback((e,r)=>{"Backspace"===r.key?s[e]?d(r=>{const n=[...r]
160
+ return a[e]=n,a}),n&&e<5&&g(e+1)},[]),w=n.useCallback((e,r)=>{"Backspace"===r.key?s[e]?d(r=>{const n=[...r]
160
161
  return n[e]="",n}):e>0&&(d(r=>{const n=[...r]
161
- return n[e-1]="",n}),_(e-1)):"ArrowLeft"===r.key&&e>0?_(e-1):"ArrowRight"===r.key&&e<5&&_(e+1)},[s]),N=n.useCallback(e=>{e.preventDefault()
162
+ return n[e-1]="",n}),g(e-1)):"ArrowLeft"===r.key&&e>0?g(e-1):"ArrowRight"===r.key&&e<5&&g(e+1)},[s]),N=n.useCallback(e=>{e.preventDefault()
162
163
  const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6)
163
164
  if(!r)return
164
165
  const n=Array(6).fill("")
165
- r.split("").forEach((e,r)=>{n[r]=e}),d(n),p(null),_(Math.min(r.length,5))},[]),k=s.join(""),E=6===k.length&&!s.includes(""),S=n.useCallback(async()=>{if(E){u(!0),p(null)
166
+ r.split("").forEach((e,r)=>{n[r]=e}),d(n),p(null),g(Math.min(r.length,5))},[]),k=s.join(""),E=6===k.length&&!s.includes(""),S=n.useCallback(async()=>{if(E){u(!0),p(null)
166
167
  try{const r=await x({functionBaseUrl:i,merchantId:o},e,k,l)
167
- a(r.session_token,r.buyer_id,r.session_id)}catch(e){p(e instanceof Error?e.message:"Verification failed. Please try again."),d(Array(6).fill("")),_(0)}finally{u(!1)}}},[E,k,e,i,o,a,l])
168
+ a(r.session_token,r.buyer_id,r.session_id)}catch(e){p(e instanceof Error?e.message:"Verification failed. Please try again."),d(Array(6).fill("")),g(0)}finally{u(!1)}}},[E,k,e,i,o,a,l])
168
169
  n.useEffect(()=>{E&&!c&&S()},[E])
169
170
  const L=n.useCallback(async()=>{if(!(m>0||y)){b(!0),p(null),d(Array(6).fill(""))
170
- try{await C({functionBaseUrl:i,merchantId:o},e),f(30),g.current=setInterval(()=>{f(e=>e<=1?(clearInterval(g.current),0):e-1)},1e3),_(0)}catch(e){p(e instanceof Error?e.message:"Failed to resend OTP.")}finally{b(!1)}}},[m,y,i,o,e])
171
+ try{await C({functionBaseUrl:i,merchantId:o},e),f(30),_.current=setInterval(()=>{f(e=>e<=1?(clearInterval(_.current),0):e-1)},1e3),g(0)}catch(e){p(e instanceof Error?e.message:"Failed to resend OTP.")}finally{b(!1)}}},[m,y,i,o,e])
171
172
  return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:t,disabled:c,children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"13",y:"16",width:"22",height:"16",rx:"2",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M13 22h22",stroke:"var(--qr-primary)",strokeWidth:"1.8"}),r.jsx("circle",{cx:"18",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r.jsx("circle",{cx:"24",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r.jsx("circle",{cx:"30",cy:"29",r:"1.5",fill:"var(--qr-primary)"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Enter OTP"}),r.jsxs("p",{className:"qr-auth-step__sub",children:["Sent to ",r.jsx("strong",{children:W(e)})]}),r.jsx("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter one-time password",children:s.map((e,n)=>r.jsx("input",{ref:e=>{v.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${h?" qr-otp-box--error":""}`,value:e,onChange:e=>q(n,e.target.value),onKeyDown:e=>w(n,e),onPaste:N,onFocus:e=>e.target.select(),"aria-label":`OTP digit ${n+1}`,disabled:c,autoComplete:0===n?"one-time-code":"off"},n))}),h&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:h}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:S,disabled:!E||c,children:c?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify OTP"}),r.jsx("p",{className:"qr-auth-step__resend",children:m>0?r.jsxs("span",{children:["Resend OTP in ",m,"s"]}):r.jsx("button",{type:"button",className:"qr-link-btn",onClick:L,disabled:y,children:y?"Sending…":"Resend OTP"})})]})},z=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M3 9.5L12 3l9 6.5V20a1 1 0 01-1 1H4a1 1 0 01-1-1V9.5z"}),r.jsx("path",{d:"M9 21V12h6v9"})]}),V=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),r.jsx("path",{d:"M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2"})]}),H=()=>r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]})
172
173
  function K({label:e}){return"home"===e?r.jsx(z,{}):"work"===e?r.jsx(V,{}):r.jsx(H,{})}function G({address:e,onUse:n,onDelete:a,onSetDefault:t,deleting:i}){const o=[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean),l=[e.flat_number,e.building_name,e.street_name].filter(Boolean).join(", "),s=[e.locality,e.district].filter(Boolean).join(", "),d=[e.state,e.pincode].filter(Boolean).join(" – "),c=o.length>0?void 0:e.locality||e.district||e.state
173
174
  return r.jsxs("div",{className:"qr-addr-card"+(e.is_default?" qr-addr-card--default":""),children:[r.jsxs("div",{className:"qr-addr-card__header",children:[r.jsx("div",{className:"qr-addr-card__label-icon",children:r.jsx(K,{label:e.label})}),r.jsx("span",{className:"qr-addr-card__label",children:e.label.charAt(0).toUpperCase()+e.label.slice(1)}),e.is_default&&r.jsx("span",{className:"qr-addr-card__default-badge",children:"Default"}),r.jsxs("div",{className:"qr-addr-card__actions",children:[!e.is_default&&r.jsx("button",{type:"button",className:"qr-icon-btn",title:"Set as default",onClick:t,"aria-label":"Set as default address",children:r.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}),r.jsx("button",{type:"button",className:"qr-icon-btn qr-icon-btn--danger",title:"Delete address",onClick:a,disabled:i,"aria-label":"Delete address",children:i?r.jsx("span",{className:"qr-spinner qr-spinner--xs","aria-hidden":"true"}):r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("polyline",{points:"3 6 5 6 21 6"}),r.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),r.jsx("path",{d:"M10 11v6M14 11v6"}),r.jsx("path",{d:"M9 6V4a1 1 0 011-1h4a1 1 0 011 1v2"})]})})]})]}),r.jsxs("div",{className:"qr-addr-card__body",children:[c?r.jsx("p",{className:"qr-addr-card__line",children:c}):r.jsxs(r.Fragment,{children:[l&&r.jsx("p",{className:"qr-addr-card__line",children:l}),s&&r.jsx("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:s}),d&&r.jsx("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:d})]}),r.jsxs("div",{className:"qr-addr-card__meta",children:[r.jsxs("span",{className:"qr-digipin-badge qr-digipin-badge--inline qr-digipin-badge--sm",children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:e.digipin})]}),e.saved_at_brand&&r.jsxs("span",{className:"qr-addr-card__brand-chip",title:`First saved at ${e.saved_at_brand}`,children:[r.jsx("svg",{viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M1 1h4.5l5.5 5.5-4.5 4.5L1 5.5V1zm2 1.5a.75.75 0 100 1.5.75.75 0 000-1.5z"})}),e.saved_at_brand]})]})]}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full qr-btn--sm",onClick:n,children:"Deliver here"})]})}const Z=({sessionToken:e,functionBaseUrl:a,merchantId:t,onSelectAddress:i,onAddNew:o})=>{const[l,s]=n.useState([]),[d,c]=n.useState(!0),[u,h]=n.useState(null),[p,m]=n.useState(null),f={functionBaseUrl:a,merchantId:t},y=n.useCallback(async()=>{c(!0),h(null)
@@ -177,7 +178,7 @@ s(r)}catch(e){h(e instanceof Error?e.message:"Failed to load addresses.")}finall
177
178
  n.useEffect(()=>{y()},[y])
178
179
  const b=n.useCallback(async r=>{m(r)
179
180
  try{await P(f,e,r),s(e=>{const n=e.filter(e=>e.id!==r)
180
- return 0===n.length&&o(),n})}catch(e){h(e instanceof Error?e.message:"Failed to delete address.")}finally{m(null)}},[e,o]),v=n.useCallback(async r=>{try{await I(f,e,r),s(e=>e.map(e=>({...e,is_default:e.id===r})))}catch(e){h(e instanceof Error?e.message:"Failed to set default.")}},[e])
181
+ return 0===n.length&&o(),n})}catch(e){h(e instanceof Error?e.message:"Failed to delete address.")}finally{m(null)}},[e,o]),v=n.useCallback(async r=>{try{await T(f,e,r),s(e=>e.map(e=>({...e,is_default:e.id===r})))}catch(e){h(e instanceof Error?e.message:"Failed to set default.")}},[e])
181
182
  return d?r.jsx("div",{className:"qr-saved-step",children:r.jsx("div",{className:"qr-saved-step__loading","aria-live":"polite",children:r.jsx("span",{className:"qr-spinner","aria-label":"Loading addresses"})})}):u&&0===l.length?r.jsxs("div",{className:"qr-saved-step",children:[r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:u}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:y,children:"Retry"}),r.jsx("button",{type:"button",className:"qr-auth-step__skip",onClick:o,children:"Enter address manually"})]}):r.jsxs("div",{className:"qr-saved-step",children:[r.jsxs("div",{className:"qr-step-header",children:[r.jsx("div",{className:"qr-step-badge qr-step-badge--saved",children:r.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M12 2C8.134 2 5 5.134 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.866-3.134-7-7-7z"}),r.jsx("circle",{cx:"12",cy:"9",r:"2.5"})]})}),r.jsxs("div",{className:"qr-step-text",children:[r.jsx("span",{className:"qr-step-title",children:"Saved Addresses"}),r.jsx("span",{className:"qr-step-sub",children:"Pick one or add a new location"})]})]}),u&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:u}),r.jsx("div",{className:"qr-saved-step__list",children:l.map(e=>r.jsx(G,{address:e,onUse:()=>i(e),onDelete:()=>b(e.id),onSetDefault:()=>v(e.id),deleting:p===e.id},e.id))}),r.jsxs("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:o,children:[r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M12 5v14M5 12h14"})}),"Add new address"]})]})},Y=({checkoutConfig:e,sessionToken:a,pincode:t,cartTotalPaise:i,theme:o="light",onCodAllowedChange:l})=>{const[s,d]=n.useState("loading"),[c,u]=n.useState(!1),[h,p]=n.useState()
182
183
  n.useEffect(()=>{let r=!1
183
184
  return d("loading"),(async()=>{try{const n=await M(e,a,t,i)
@@ -208,10 +209,10 @@ try{const{reused:r}=await A({functionBaseUrl:t,merchantId:i},o)
208
209
  e(o.toLowerCase(),{reused:r})}catch(e){u(e instanceof Error?e.message:"Failed to send code. Please try again.")}finally{d(!1)}},[o,t,i,e])
209
210
  return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r.jsx("p",{className:"qr-auth-step__sub",children:"Enter your email to load saved addresses"}),r.jsxs("form",{onSubmit:m,noValidate:!0,children:[r.jsx("div",{className:"qr-email-field"+(c?" qr-email-field--error":""),children:r.jsx("input",{ref:h,type:"email",inputMode:"email",className:"qr-email-field__input",placeholder:"you@example.com",value:o,onChange:p,autoComplete:"email","aria-label":"Email address","aria-describedby":c?"qr-email-error":void 0,"aria-invalid":!!c,disabled:s})}),c&&r.jsx("p",{id:"qr-email-error",className:"qr-auth-step__error",role:"alert",children:c}),r.jsx("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:s||o.length<5,children:s?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):r.jsxs(r.Fragment,{children:["Send Code",r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r.jsx("button",{type:"button",className:"qr-auth-step__skip",onClick:a,disabled:s,children:"Skip, enter address manually"})]})}
210
211
  function ne(e){const[r,n]=e.split("@")
211
- return!n||r.length<=1?e:`${r[0]}***@${n}`}const ae=({email:e,codeReused:a=!1,onVerified:t,onBack:i,functionBaseUrl:o,merchantId:l,sessionContext:s})=>{const[d,c]=n.useState(Array(6).fill("")),[u,h]=n.useState(!1),[p,m]=n.useState(null),[f,y]=n.useState(60),[b,v]=n.useState(!1),g=n.useRef([]),_=n.useRef(null)
212
- n.useEffect(()=>(_.current=setInterval(()=>{y(e=>e<=1?(clearInterval(_.current),0):e-1)},1e3),()=>{_.current&&clearInterval(_.current)}),[])
212
+ return!n||r.length<=1?e:`${r[0]}***@${n}`}const ae=({email:e,codeReused:a=!1,onVerified:t,onBack:i,functionBaseUrl:o,merchantId:l,sessionContext:s})=>{const[d,c]=n.useState(Array(6).fill("")),[u,h]=n.useState(!1),[p,m]=n.useState(null),[f,y]=n.useState(60),[b,v]=n.useState(!1),_=n.useRef([]),g=n.useRef(null)
213
+ n.useEffect(()=>(g.current=setInterval(()=>{y(e=>e<=1?(clearInterval(g.current),0):e-1)},1e3),()=>{g.current&&clearInterval(g.current)}),[])
213
214
  const q=e=>{var r
214
- return null==(r=g.current[e])?void 0:r.focus()},w=n.useCallback((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
215
+ return null==(r=_.current[e])?void 0:r.focus()},w=n.useCallback((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
215
216
  m(null),c(r=>{const a=[...r]
216
217
  return a[e]=n,a}),n&&e<5&&q(e+1)},[]),N=n.useCallback((e,r)=>{"Backspace"===r.key?d[e]?c(r=>{const n=[...r]
217
218
  return n[e]="",n}):e>0&&(c(r=>{const n=[...r]
@@ -224,37 +225,37 @@ try{const r=await B({functionBaseUrl:o,merchantId:l},e,C,s)
224
225
  t(r.session_token,r.buyer_id,r.session_id)}catch(e){m(e instanceof Error?e.message:"Verification failed. Please try again."),c(Array(6).fill("")),q(0)}finally{h(!1)}}},[x,C,e,o,l,t,s])
225
226
  n.useEffect(()=>{x&&!u&&E()},[x])
226
227
  const S=n.useCallback(async()=>{if(!(f>0||b)){v(!0),m(null),c(Array(6).fill(""))
227
- try{await A({functionBaseUrl:o,merchantId:l},e),y(60),_.current=setInterval(()=>{y(e=>e<=1?(clearInterval(_.current),0):e-1)},1e3),q(0)}catch(e){m(e instanceof Error?e.message:"Failed to resend code.")}finally{v(!1)}}},[f,b,o,l,e])
228
- return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:i,disabled:u,children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Check your email"}),r.jsx("p",{className:"qr-auth-step__sub",children:a?r.jsx(r.Fragment,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):r.jsxs(r.Fragment,{children:["6-digit code sent to ",r.jsx("strong",{children:ne(e)})]})}),r.jsx("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter verification code",children:d.map((e,n)=>r.jsx("input",{ref:e=>{g.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${p?" qr-otp-box--error":""}`,value:e,onChange:e=>w(n,e.target.value),onKeyDown:e=>N(n,e),onPaste:k,onFocus:e=>e.target.select(),"aria-label":`Code digit ${n+1}`,disabled:u,autoComplete:0===n?"one-time-code":"off"},n))}),p&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:p}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:E,disabled:!x||u,children:u?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify Code"}),r.jsx("p",{className:"qr-auth-step__resend",children:f>0?r.jsxs("span",{children:["Resend code in ",f,"s"]}):r.jsx("button",{type:"button",className:"qr-link-btn",onClick:S,disabled:b,children:b?"Sending…":"Resend Code"})})]})}
228
+ try{await A({functionBaseUrl:o,merchantId:l},e),y(60),g.current=setInterval(()=>{y(e=>e<=1?(clearInterval(g.current),0):e-1)},1e3),q(0)}catch(e){m(e instanceof Error?e.message:"Failed to resend code.")}finally{v(!1)}}},[f,b,o,l,e])
229
+ return r.jsxs("div",{className:"qr-auth-step",children:[r.jsx("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:i,disabled:u,children:r.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r.jsx("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r.jsx("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r.jsx("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-auth-step__title",children:"Check your email"}),r.jsx("p",{className:"qr-auth-step__sub",children:a?r.jsx(r.Fragment,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):r.jsxs(r.Fragment,{children:["6-digit code sent to ",r.jsx("strong",{children:ne(e)})]})}),r.jsx("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter verification code",children:d.map((e,n)=>r.jsx("input",{ref:e=>{_.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${p?" qr-otp-box--error":""}`,value:e,onChange:e=>w(n,e.target.value),onKeyDown:e=>N(n,e),onPaste:k,onFocus:e=>e.target.select(),"aria-label":`Code digit ${n+1}`,disabled:u,autoComplete:0===n?"one-time-code":"off"},n))}),p&&r.jsx("p",{className:"qr-auth-step__error",role:"alert",children:p}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:E,disabled:!x||u,children:u?r.jsx("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify Code"}),r.jsx("p",{className:"qr-auth-step__resend",children:f>0?r.jsxs("span",{children:["Resend code in ",f,"s"]}):r.jsx("button",{type:"button",className:"qr-link-btn",onClick:S,disabled:b,children:b?"Sending…":"Resend Code"})})]})}
229
230
  function te(e){if("undefined"!=typeof window){const e=window.innerWidth
230
231
  return e<768?"mobile":e<1024?"tablet":"desktop"}const r=(e??"").toLowerCase()
231
232
  return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function ie(){const e=function(){if("undefined"!=typeof navigator&&navigator.userAgent)return navigator.userAgent.slice(0,512)}()
232
233
  return{deviceType:te(e),platform:"web",userAgent:e}}const oe=["utm_source","utm_medium","utm_campaign"]
233
234
  function le(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
234
235
  for(const e of oe){const a=r.searchParams.get(e)
235
- a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}const se=({address:e,onEditAddress:n})=>r.jsxs("div",{className:"qr-success",children:[r.jsx("div",{className:"qr-success__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 52 52",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"26",cy:"26",r:"26",fill:"var(--qr-success, #10b981)",opacity:"0.12"}),r.jsx("circle",{cx:"26",cy:"26",r:"20",fill:"var(--qr-success, #10b981)"}),r.jsx("path",{d:"M15 26l8 8 14-16",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-success__title",children:"Address Saved!"}),r.jsx("p",{className:"qr-success__address",children:e.formattedAddress}),r.jsx("div",{className:"qr-success__meta",children:r.jsxs("span",{className:"qr-digipin-badge qr-digipin-badge--inline",children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:e.digipin})]})}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--sm",onClick:n,children:"Change Address"})]}),de=({apiKey:e,apiBaseUrl:a="https://api.quantaroute.com",onComplete:t,onError:i,defaultLat:o,defaultLng:l,theme:s="light",className:d="",style:c,mapHeight:u="380px",title:h="Add Delivery Address",indiaBoundaryUrl:p,enableSearch:m=!0,enablePhoneAuth:f=!1,merchantId:y="",supabaseFunctionBaseUrl:b="",brandColor:v,logoUrl:g,headerBanner:_,onCheckoutEvent:w,enableCod:N=!1,codCartTotalPaise:C,codSessionToken:x="",enableEmailAuth:E=!1,variant:S,utmParams:P,enablePayment:I=!1,paymentAmountPaise:A,onPaymentComplete:B,enablePrepaidNudge:M=!1,prepaidNudgeCopy:F,prepaidNudgeCtaUrl:U})=>{const j=f?"phone":E?"email":"none",W="phone"===j?"phone":"email"===j?"email":"map",z=Boolean(I&&A&&b),[V,H]=n.useState(W),[K,G]=n.useState(null),[X,ne]=n.useState(null),[te,oe]=n.useState(null),[de,ce]=n.useState(""),[ue,he]=n.useState(!1),[pe,me]=n.useState(!1),[fe,ye]=n.useState(null),[be,ve]=n.useState(null),ge=n.useRef(V),_e=n.useMemo(()=>P??le(),[P]),qe=n.useMemo(()=>ie(),[]),we=n.useMemo(()=>({utm_source:_e.utm_source,utm_medium:_e.utm_medium,utm_campaign:_e.utm_campaign,device_type:qe.deviceType,platform:qe.platform,user_agent:qe.userAgent,experiment_variant:S}),[_e,qe,S]),Ne={functionBaseUrl:b,merchantId:y},ke=(null==te?void 0:te.sessionToken)||x
236
- n.useEffect(()=>{ge.current=V},[V])
236
+ a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}const se=({address:e,onEditAddress:n})=>r.jsxs("div",{className:"qr-success",children:[r.jsx("div",{className:"qr-success__icon","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 52 52",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("circle",{cx:"26",cy:"26",r:"26",fill:"var(--qr-success, #10b981)",opacity:"0.12"}),r.jsx("circle",{cx:"26",cy:"26",r:"20",fill:"var(--qr-success, #10b981)"}),r.jsx("path",{d:"M15 26l8 8 14-16",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("h3",{className:"qr-success__title",children:"Address Saved!"}),r.jsx("p",{className:"qr-success__address",children:e.formattedAddress}),r.jsx("div",{className:"qr-success__meta",children:r.jsxs("span",{className:"qr-digipin-badge qr-digipin-badge--inline",children:[r.jsx("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r.jsx("span",{className:"qr-digipin-badge__code",children:e.digipin})]})}),r.jsx("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--sm",onClick:n,children:"Change Address"})]}),de=({apiKey:e,apiBaseUrl:a="https://api.quantaroute.com",onComplete:t,onError:i,defaultLat:o,defaultLng:l,theme:s="light",className:d="",style:c,mapHeight:u="380px",title:h="Add Delivery Address",indiaBoundaryUrl:p,enableSearch:m=!0,enablePhoneAuth:f=!1,merchantId:y="",supabaseFunctionBaseUrl:b="",brandColor:v,logoUrl:_,headerBanner:g,onCheckoutEvent:w,enableCod:N=!1,codCartTotalPaise:C,codSessionToken:x="",enableEmailAuth:E=!1,variant:S,utmParams:P,enablePayment:T=!1,paymentAmountPaise:A,onPaymentComplete:B,enablePrepaidNudge:M=!1,prepaidNudgeCopy:F,prepaidNudgeCtaUrl:U})=>{const j=f?"phone":E?"email":"none",W="phone"===j?"phone":"email"===j?"email":"map",z=Boolean(T&&A&&b),[V,H]=n.useState(W),[K,G]=n.useState(null),[X,ne]=n.useState(null),[te,oe]=n.useState(null),[de,ce]=n.useState(""),[ue,he]=n.useState(!1),[pe,me]=n.useState(!1),[fe,ye]=n.useState(null),[be,ve]=n.useState(null),_e=n.useRef(V),ge=n.useMemo(()=>P??le(),[P]),qe=n.useMemo(()=>ie(),[]),we=n.useMemo(()=>({utm_source:ge.utm_source,utm_medium:ge.utm_medium,utm_campaign:ge.utm_campaign,device_type:qe.deviceType,platform:qe.platform,user_agent:qe.userAgent,experiment_variant:S}),[ge,qe,S]),Ne={functionBaseUrl:b,merchantId:y},ke=(null==te?void 0:te.sessionToken)||x
237
+ n.useEffect(()=>{_e.current=V},[V])
237
238
  const Ce=n.useCallback(e=>{const r={...e,sessionId:e.sessionId??(null==te?void 0:te.sessionId),buyerId:e.buyerId??(null==te?void 0:te.buyerId),authChannel:e.authChannel??("phone"===j?"phone":"email"===j?"email":"none"),deviceType:e.deviceType??qe.deviceType,platform:e.platform??qe.platform,userAgent:e.userAgent??qe.userAgent,experimentVariant:e.experimentVariant??S,timestamp:(new Date).toISOString()}
238
- if(w)try{w(r)}catch{}y&&b&&$(Ne,{event_type:r.type,step:r.step,buyer_id:r.buyerId,auth_channel:r.authChannel,device_type:r.deviceType,platform:r.platform,user_agent:r.userAgent,payment_method:r.paymentMethod,experiment_variant:r.experimentVariant},null==te?void 0:te.sessionToken).catch(()=>{})},[te,j,qe,S,w,y,b,Ne])
239
+ if(w)try{w(r)}catch{}y&&b&&O(Ne,{event_type:r.type,step:r.step,buyer_id:r.buyerId,auth_channel:r.authChannel,device_type:r.deviceType,platform:r.platform,user_agent:r.userAgent,payment_method:r.paymentMethod,experiment_variant:r.experimentVariant},null==te?void 0:te.sessionToken).catch(()=>{})},[te,j,qe,S,w,y,b,Ne])
239
240
  n.useEffect(()=>{if(!y||!b)return
240
- const e=()=>{"done"!==ge.current&&(null==te?void 0:te.sessionToken)&&(O(Ne,te.sessionToken,ge.current).catch(()=>{}),Ce({type:"session_abandoned",step:ge.current}))}
241
+ const e=()=>{"done"!==_e.current&&(null==te?void 0:te.sessionToken)&&($(Ne,te.sessionToken,_e.current).catch(()=>{}),Ce({type:"session_abandoned",step:_e.current}))}
241
242
  return window.addEventListener("pagehide",e),()=>window.removeEventListener("pagehide",e)},[null==te?void 0:te.sessionToken,y,b,Ne,Ce]),n.useEffect(()=>{(null==te?void 0:te.sessionToken)&&y&&b&&D(Ne,te.sessionToken).then(ye).catch(()=>ye(null))},[null==te?void 0:te.sessionToken,y,b,Ne])
242
243
  const xe=n.useMemo(()=>function(e,r){const n=null==r?void 0:r.trim()
243
244
  if(!n)return e
244
245
  const a={"--qr-primary":n,"--qr-primary-dark":n,"--qr-border-focus":n,"--qr-primary-light":`color-mix(in srgb, ${n} 18%, white)`}
245
- return e?{...e,...a}:a}(c,v),[c,v]),Ee=()=>{Ce({type:"auth_skipped",step:"map"}),H("map")},Se=async e=>{if(ne(e),Ce({type:"address_completed",step:z?"payment":"done",digipin:e.digipin,buyerId:null==te?void 0:te.buyerId}),null==te?void 0:te.sessionToken){T(Ne,te.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
246
- try{await L(Ne,te.sessionToken,{digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,locality:e.locality,pincode:e.pincode,delivery_status:e.delivery,flat_number:e.flatNumber,floor_number:e.floorNumber,building_name:e.buildingName,street_name:e.streetName,full_address_json:e,label:"home",is_default:!0})}catch{}}z&&ke?H("payment"):(H("done"),t(e))}
246
+ return e?{...e,...a}:a}(c,v),[c,v]),Ee=()=>{Ce({type:"auth_skipped",step:"map"}),H("map")},Se=async e=>{if(ne(e),Ce({type:"address_completed",step:z?"payment":"done",digipin:e.digipin,buyerId:null==te?void 0:te.buyerId}),null==te?void 0:te.sessionToken){I(Ne,te.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
247
+ try{await L(Ne,te.sessionToken,{digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,locality:e.locality,pincode:e.pincode,delivery_status:e.delivery,flat_number:e.flatNumber,floor_number:e.floorNumber,building_name:e.buildingName,street_name:e.streetName,full_address_json:e,label:e.label??"home",is_default:!0})}catch{}}z&&ke?H("payment"):(H("done"),t(e))}
247
248
  n.useEffect(()=>{const e={phone:"phone_step_viewed",email:"email_step_viewed",saved:"saved_addresses_viewed",map:"map_step_viewed",form:"form_step_viewed",payment:"payment_step_viewed"}[V]
248
249
  e&&Ce({type:e,step:V,buyerId:null==te?void 0:te.buyerId})},[V]),n.useEffect(()=>{E&&"email"===j&&(y&&b||null==i||i(new Error("enableEmailAuth requires merchantId and supabaseFunctionBaseUrl on CheckoutWidget.")))},[E,j,y,b,i])
249
250
  const Le=function(e,r,n){if("none"===r){if(n){const r=["map","form","payment","done"].indexOf(e)
250
251
  return-1===r?0:r}return"map"===e?0:"form"===e?1:2}const a=("email"===r?n?["email","email-otp","saved","map","form","payment","done"]:["email","email-otp","saved","map","form","done"]:n?["phone","otp","saved","map","form","payment","done"]:["phone","otp","saved","map","form","done"]).indexOf(e)
251
252
  return-1===a?0:a}(V,j,z),Pe=function(e,r){return"none"===e?r?3:2:r?6:5}(j,z)
252
- return r.jsxs("div",{className:`qr-checkout qr-checkout--${s} ${d}`,style:xe,"data-testid":"quantaroute-checkout",children:["done"!==V&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"qr-header",children:[r.jsxs("div",{className:"qr-header__brand",children:[g?r.jsx("img",{src:g,alt:"",className:"qr-header__logo-img",width:28,height:28,decoding:"async"}):r.jsxs("svg",{className:"qr-header__logo","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r.jsx("circle",{cx:"12",cy:"10",r:"3"})]}),r.jsx("span",{className:"qr-header__title",children:h})]}),(()=>{const e=Array.from({length:Pe+1},(e,r)=>r)
253
- return r.jsx("div",{className:"qr-progress",role:"progressbar","aria-valuenow":Le+1,"aria-valuemin":1,"aria-valuemax":Pe+1,"aria-label":`Step ${Le+1} of ${Pe+1}`,children:e.map(e=>r.jsxs(n.Fragment,{children:[r.jsx("div",{className:"qr-progress__dot"+(Le>=e?" qr-progress__dot--active":"")}),e<Pe&&r.jsx("div",{className:"qr-progress__line"+(Le>e?" qr-progress__line--active":"")})]},e))})})()]}),_?r.jsx("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:_}):null,fe?r.jsxs("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[fe.banner_copy,fe.banner_cta_url?r.jsxs(r.Fragment,{children:[" ",r.jsx("a",{href:fe.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===V&&E&&r.jsx(re,{onOtpSent:(e,r)=>{ce(e),he(Boolean(null==r?void 0:r.reused)),Ce({type:"email_otp_sent",step:"email-otp",mobile:e}),H("email-otp")},onSkip:Ee,functionBaseUrl:b,merchantId:y}),"email-otp"===V&&E&&de&&r.jsx(ae,{email:de,codeReused:ue,onVerified:(e,r,n)=>{oe({mobile:de,sessionToken:e,sessionId:n??"",buyerId:r}),Ce({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),H("saved")},onBack:()=>H("email"),functionBaseUrl:b,merchantId:y,sessionContext:we}),"phone"===V&&f&&r.jsx(R,{onOtpSent:e=>{oe(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Ce({type:"otp_sent",step:"otp",mobile:e}),H("otp")},onSkip:Ee,functionBaseUrl:b,merchantId:y}),"otp"===V&&te&&r.jsx(J,{mobile:te.mobile,onVerified:(e,r,n)=>{oe({mobile:(null==te?void 0:te.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Ce({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),H("saved")},onBack:()=>H("phone"),functionBaseUrl:b,merchantId:y,sessionContext:we}),"saved"===V&&(null==te?void 0:te.sessionToken)&&r.jsx(Z,{sessionToken:te.sessionToken,functionBaseUrl:b,merchantId:y,onSelectAddress:e=>{Ce({type:"saved_address_selected",step:z?"payment":"done",buyerId:null==te?void 0:te.buyerId,digipin:e.digipin}),(null==te?void 0:te.sessionToken)&&T(Ne,te.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
254
- const r={digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,division:"",locality:e.locality,pincode:e.pincode,delivery:e.delivery_status,country:"India",flatNumber:e.flat_number,floorNumber:e.floor_number,buildingName:e.building_name,streetName:e.street_name,formattedAddress:[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean).join(", ")}
253
+ return r.jsxs("div",{className:`qr-checkout qr-checkout--${s} ${d}`,style:xe,"data-testid":"quantaroute-checkout",children:["done"!==V&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"qr-header",children:[r.jsxs("div",{className:"qr-header__brand",children:[_?r.jsx("img",{src:_,alt:"",className:"qr-header__logo-img",width:28,height:28,decoding:"async"}):r.jsxs("svg",{className:"qr-header__logo","aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r.jsx("circle",{cx:"12",cy:"10",r:"3"})]}),r.jsx("span",{className:"qr-header__title",children:h})]}),(()=>{const e=Array.from({length:Pe+1},(e,r)=>r)
254
+ return r.jsx("div",{className:"qr-progress",role:"progressbar","aria-valuenow":Le+1,"aria-valuemin":1,"aria-valuemax":Pe+1,"aria-label":`Step ${Le+1} of ${Pe+1}`,children:e.map(e=>r.jsxs(n.Fragment,{children:[r.jsx("div",{className:"qr-progress__dot"+(Le>=e?" qr-progress__dot--active":"")}),e<Pe&&r.jsx("div",{className:"qr-progress__line"+(Le>e?" qr-progress__line--active":"")})]},e))})})()]}),g?r.jsx("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:g}):null,fe?r.jsxs("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[fe.banner_copy,fe.banner_cta_url?r.jsxs(r.Fragment,{children:[" ",r.jsx("a",{href:fe.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===V&&E&&r.jsx(re,{onOtpSent:(e,r)=>{ce(e),he(Boolean(null==r?void 0:r.reused)),Ce({type:"email_otp_sent",step:"email-otp",mobile:e}),H("email-otp")},onSkip:Ee,functionBaseUrl:b,merchantId:y}),"email-otp"===V&&E&&de&&r.jsx(ae,{email:de,codeReused:ue,onVerified:(e,r,n)=>{oe({mobile:de,sessionToken:e,sessionId:n??"",buyerId:r}),Ce({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),H("saved")},onBack:()=>H("email"),functionBaseUrl:b,merchantId:y,sessionContext:we}),"phone"===V&&f&&r.jsx(R,{onOtpSent:e=>{oe(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Ce({type:"otp_sent",step:"otp",mobile:e}),H("otp")},onSkip:Ee,functionBaseUrl:b,merchantId:y}),"otp"===V&&te&&r.jsx(J,{mobile:te.mobile,onVerified:(e,r,n)=>{oe({mobile:(null==te?void 0:te.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Ce({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),H("saved")},onBack:()=>H("phone"),functionBaseUrl:b,merchantId:y,sessionContext:we}),"saved"===V&&(null==te?void 0:te.sessionToken)&&r.jsx(Z,{sessionToken:te.sessionToken,functionBaseUrl:b,merchantId:y,onSelectAddress:e=>{Ce({type:"saved_address_selected",step:z?"payment":"done",buyerId:null==te?void 0:te.buyerId,digipin:e.digipin}),(null==te?void 0:te.sessionToken)&&I(Ne,te.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
255
+ const r={digipin:e.digipin,lat:e.lat,lng:e.lng,state:e.state,district:e.district,division:"",locality:e.locality,pincode:e.pincode,delivery:e.delivery_status,country:"India",flatNumber:e.flat_number,floorNumber:e.floor_number,buildingName:e.building_name,streetName:e.street_name,formattedAddress:[e.flat_number,e.building_name,e.street_name,e.locality,e.district,e.state,e.pincode].filter(Boolean).join(", "),label:"work"===e.label||"other"===e.label?e.label:"home"}
255
256
  Se(r)},onAddNew:()=>H("map")}),"map"===V&&r.jsx(q,{onLocationConfirm:(e,r,n)=>{G({lat:e,lng:r,digipin:n}),Ce({type:"location_confirmed",step:"form",digipin:n,buyerId:null==te?void 0:te.buyerId}),H("form")},defaultLat:o,defaultLng:l,mapHeight:u,theme:s,indiaBoundaryUrl:p,enableSearch:m,apiKey:e,apiBaseUrl:a,brandColor:v}),"form"===V&&K&&r.jsx(k,{digipin:K.digipin,lat:K.lat,lng:K.lng,apiKey:e,apiBaseUrl:a,onAddressComplete:async e=>{await Se(e)},onBack:()=>{"form"===V?H("map"):"map"===V&&(null==te?void 0:te.sessionToken)?H("saved"):"email-otp"===V&&H("email")},onError:i,theme:s}),"payment"===V&&z&&ke&&A&&r.jsx(ee,{checkoutConfig:Ne,sessionToken:ke,sessionId:null==te?void 0:te.sessionId,amountPaise:A,enableCod:N,codAllowed:pe,theme:s,onComplete:e=>{ve(e),Ce({type:"payment_method_selected",step:"done",paymentMethod:e}),H("done"),X&&t(X),null==B||B({paymentMethod:e,sessionId:null==te?void 0:te.sessionId})},onBack:()=>H("form"),onEvent:(e,r)=>Ce({type:e,step:"payment",paymentMethod:r,buyerId:null==te?void 0:te.buyerId})}),"done"===V&&X&&r.jsxs(r.Fragment,{children:[r.jsx(se,{address:X,onEditAddress:()=>{Ce({type:"widget_reset",step:W}),H(W),G(null),ne(null)}}),be?r.jsxs("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",style:{textAlign:"center",margin:"8px 16px"},children:["Paid via ","cod"===be?"Cash on Delivery":"online payment"]}):null,N&&y&&b&&ke?r.jsxs(r.Fragment,{children:[r.jsx(Y,{checkoutConfig:Ne,sessionToken:ke,pincode:X.pincode,cartTotalPaise:C??A,theme:s,onCodAllowedChange:me}),M&&pe?r.jsx(Q,{copy:F??"Save more when you pay online — faster delivery & exclusive offers.",ctaUrl:U,theme:s}):null]}):null]}),r.jsxs("div",{className:"qr-footer",children:[r.jsx("span",{children:"Powered by"}),r.jsx("a",{href:"https://quantaroute.com",target:"_blank",rel:"noopener noreferrer",className:"qr-footer__link",children:"QuantaRoute"}),r.jsx("span",{className:"qr-footer__flag","aria-label":"Made in India",children:"🇮🇳"})]})]})}
256
257
  e.AddressForm=k,e.CheckoutWidget=de,e.CodAvailabilityBanner=Y,e.DIGIPIN_BOUNDS=i,e.EmailOtpStep=ae,e.EmailStep=re,e.MapPinSelector=q,e.OtpStep=J,e.PaymentStep=ee,e.PhoneStep=R,e.PrepaidNudge=Q,e.SavedAddressStep=Z,e.autocompleteAddress=y,e.captureUtmFromUrl=le,e.checkCodEligibility=M,e.createAddress=L,e.createPaymentOrder=F,e.default=de,e.deleteAddress=P,e.detectDeviceType=te,e.detectPlatform=function(){return"web"},e.fetchPrepaidNudgeConfig=async function(e,r){const n=await fetch(`${e}/checkout-admin?action=cod_config`,{headers:{"x-api-key":r}}),a=await n.json().catch(()=>({}))
257
258
  return n.ok&&a.success?{prepaid_nudge_copy:a.data.prepaid_nudge_copy,prepaid_nudge_cta_url:a.data.prepaid_nudge_cta_url}:null},e.fetchSessionOffer=D,e.getDigiPin=o,e.getLatLngFromDigiPin=l,e.getWebDeviceContext=ie,e.hasUtmParams=function(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)},e.isValidDigiPin=function(e){if(!e||"string"!=typeof e)return!1
258
259
  if(!/^[A-Z0-9]{3}-[A-Z0-9]{3}-[A-Z0-9]{4}$/i.test(e.trim()))return!1
259
- try{return l(e.trim().toUpperCase()),!0}catch{return!1}},e.isWithinIndia=s,e.listAddresses=S,e.logFunnelEvent=$,e.looksLikeDigiPin=f,e.lookupLocation=h,e.notifyAddressCompleted=T,e.notifySessionAbandoned=O,e.pincodeHasDeliveryOffice=m,e.recordCodPayment=j,e.reverseGeocode=b,e.sendEmailOtp=A,e.sendOtp=C,e.setDefaultAddress=I,e.useDigiPin=function(e,r){return n.useMemo(()=>{if(!s(e,r))return null
260
+ try{return l(e.trim().toUpperCase()),!0}catch{return!1}},e.isWithinIndia=s,e.listAddresses=S,e.logFunnelEvent=O,e.looksLikeDigiPin=f,e.lookupLocation=h,e.notifyAddressCompleted=I,e.notifySessionAbandoned=$,e.pincodeHasDeliveryOffice=m,e.recordCodPayment=j,e.reverseGeocode=b,e.sendEmailOtp=A,e.sendOtp=C,e.setDefaultAddress=T,e.useDigiPin=function(e,r){return n.useMemo(()=>{if(!s(e,r))return null
260
261
  try{return o(e,r)}catch{return null}},[e,r])},e.useGeolocation=v,e.validatePincode=p,e.verifyEmailOtp=B,e.verifyOtp=x,e.verifyPayment=U,Object.defineProperties(e,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})