@quantaroute/checkout 1.4.2 → 1.4.3

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.
@@ -21,101 +21,103 @@
21
21
  import{jsxs as e,jsx as r,Fragment as n}from"react/jsx-runtime"
22
22
  import a,{useState as t,useCallback as i,useRef as o,useId as l,useEffect as s,useReducer as d,useMemo as c}from"react"
23
23
  import u from"maplibre-gl"
24
- const h=[["F","C","9","8"],["J","3","2","7"],["K","4","5","6"],["L","M","P","T"]],p={minLat:2.5,maxLat:38.5,minLon:63.5,maxLon:99.5}
25
- function m(e,r){if(e<p.minLat||e>p.maxLat)throw new Error(`Latitude ${e} out of range. Must be between ${p.minLat} and ${p.maxLat}`)
24
+ const h=[["F","C","9","8"],["J","3","2","7"],["K","4","5","6"],["L","M","P","T"]],p={minLat:2.5,maxLat:38.5,minLon:63.5,maxLon:99.5},m=new RegExp("^[FC98J327K456LMPT]{10}$","i")
25
+ function f(e){return e.trim().toUpperCase().replace(/[\s\-_.]/g,"")}function y(e){const r=f(e)
26
+ return 10!==r.length?e.trim().toUpperCase():`${r.slice(0,3)}-${r.slice(3,6)}-${r.slice(6)}`}function b(e){const r=f(e)
27
+ return 10===r.length&&m.test(r)}function v(e,r){if(e<p.minLat||e>p.maxLat)throw new Error(`Latitude ${e} out of range. Must be between ${p.minLat} and ${p.maxLat}`)
26
28
  if(r<p.minLon||r>p.maxLon)throw new Error(`Longitude ${r} out of range. Must be between ${p.minLon} and ${p.maxLon}`)
27
29
  let n=p.minLat,a=p.maxLat,t=p.minLon,i=p.maxLon,o=""
28
30
  for(let l=1;l<=10;l++){const s=(a-n)/4,d=(i-t)/4
29
31
  let c=3-Math.floor((e-n)/s),u=Math.floor((r-t)/d)
30
- c=Math.max(0,Math.min(c,3)),u=Math.max(0,Math.min(u,3)),o+=h[c][u],3!==l&&6!==l||(o+="-"),a=n+s*(4-c),n+=s*(3-c),t+=d*u,i=t+d}return o}function f(e){const r=e.replace(/-/g,"")
31
- if(10!==r.length)throw new Error("Invalid DIGIPIN: must be 10 characters (excluding dashes)")
32
+ c=Math.max(0,Math.min(c,3)),u=Math.max(0,Math.min(u,3)),o+=h[c][u],3!==l&&6!==l||(o+="-"),a=n+s*(4-c),n+=s*(3-c),t+=d*u,i=t+d}return o}function _(e){const r=f(e)
33
+ if(10!==r.length)throw new Error("Invalid DIGIPIN: must be 10 characters (excluding separators)")
32
34
  let n=p.minLat,a=p.maxLat,t=p.minLon,i=p.maxLon
33
35
  for(let e=0;e<10;e++){const o=r[e]
34
36
  let l=!1,s=-1,d=-1
35
37
  for(let e=0;e<4;e++){for(let r=0;r<4;r++)if(h[e][r]===o){s=e,d=r,l=!0
36
38
  break}if(l)break}if(!l)throw new Error(`Invalid character in DIGIPIN: '${o}'`)
37
39
  const c=(a-n)/4,u=(i-t)/4,p=t+u*(d+1)
38
- n=a-c*(s+1),a-=c*s,t+=u*d,i=p}return{latitude:((n+a)/2).toFixed(6),longitude:((t+i)/2).toFixed(6)}}function y(e){if(!e||"string"!=typeof e)return!1
39
- if(!/^[A-Z0-9]{3}-[A-Z0-9]{3}-[A-Z0-9]{4}$/i.test(e.trim()))return!1
40
- try{return f(e.trim().toUpperCase()),!0}catch{return!1}}function b(e,r){return e>=p.minLat&&e<=p.maxLat&&r>=p.minLon&&r<=p.maxLon}const v="https://api.quantaroute.com",_=/^[FC98J327K456LMPT]{3}-[FC98J327K456LMPT]{3}-[FC98J327K456LMPT]{4}$/i
41
- function g(e){if("undefined"!=typeof AbortSignal&&"function"==typeof AbortSignal.timeout)return AbortSignal.timeout(e)
40
+ n=a-c*(s+1),a-=c*s,t+=u*d,i=p}return{latitude:((n+a)/2).toFixed(6),longitude:((t+i)/2).toFixed(6)}}function g(e){if(!e||"string"!=typeof e)return!1
41
+ if(!b(e))return!1
42
+ try{return _(e),!0}catch{return!1}}function q(e,r){return e>=p.minLat&&e<=p.maxLat&&r>=p.minLon&&r<=p.maxLon}const w="https://api.quantaroute.com"
43
+ function N(e){if("undefined"!=typeof AbortSignal&&"function"==typeof AbortSignal.timeout)return AbortSignal.timeout(e)
42
44
  const r=new AbortController
43
- return setTimeout(()=>r.abort(),e),r.signal}async function q(e,r,n,a=v){const t=`${a.replace(/\/$/,"")}/v1/location/lookup`
45
+ return setTimeout(()=>r.abort(),e),r.signal}async function k(e,r,n,a=w){const t=`${a.replace(/\/$/,"")}/v1/location/lookup`
44
46
  let i
45
- try{i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":n},body:JSON.stringify({latitude:e,longitude:r}),signal:g(15e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Request timed out. Check your internet connection.")
47
+ try{i=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":n},body:JSON.stringify({latitude:e,longitude:r}),signal:N(15e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Request timed out. Check your internet connection.")
46
48
  throw new Error(`Network error: ${e instanceof Error?e.message:String(e)}`)}if(!i.ok){let e=""
47
49
  try{e=await i.text()}catch{}if(401===i.status||403===i.status)throw new Error("Invalid API key. Check your QuantaRoute API key.")
48
50
  if(429===i.status)throw new Error("Rate limit exceeded. Upgrade your plan or try again later.")
49
51
  throw new Error(`API error ${i.status}: ${e||i.statusText}`)}const o=await i.json()
50
52
  if(!o.success)throw new Error(o.message??"Location lookup failed")
51
- return o}async function w(e,r,n=v){const a=e.replace(/\D/g,"").slice(0,6)
53
+ return o}async function C(e,r,n=w){const a=e.replace(/\D/g,"").slice(0,6)
52
54
  if(!/^[1-9][0-9]{5}$/.test(a))throw new Error("Pincode must be a 6-digit number starting with 1–9.")
53
55
  const t=`${n.replace(/\/$/,"")}/v1/pincode/validate/${a}`
54
56
  let i
55
- try{i=await fetch(t,{method:"GET",headers:{"x-api-key":r},signal:g(12e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Pincode validation timed out.")
57
+ try{i=await fetch(t,{method:"GET",headers:{"x-api-key":r},signal:N(12e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Pincode validation timed out.")
56
58
  throw new Error(`Network error: ${e instanceof Error?e.message:String(e)}`)}if(!i.ok){if(401===i.status||403===i.status)throw new Error("Invalid API key.")
57
59
  if(429===i.status)throw new Error("Rate limit exceeded.")
58
60
  let e=""
59
61
  try{e=await i.text()}catch{}throw new Error(`Pincode validation failed (${i.status}): ${e||i.statusText}`)}const o=await i.json()
60
62
  if(!o.success||!o.data)throw new Error(o.message??"Pincode validation failed.")
61
- return o.data}function N(e){return e.some(e=>"delivery"===(e.delivery??"").trim().toLowerCase())}function k(e){return _.test(e.trim().toUpperCase())}async function C(e,r,n=v,a=5,t,i){let o,l=`${n.replace(/\/$/,"")}/v1/digipin/autocomplete?q=${encodeURIComponent(e.trim())}&limit=${Math.min(a,10)}`
63
+ return o.data}function x(e){return e.some(e=>"delivery"===(e.delivery??"").trim().toLowerCase())}function E(e){return b(e)}async function S(e,r,n=w,a=5,t,i){let o,l=`${n.replace(/\/$/,"")}/v1/digipin/autocomplete?q=${encodeURIComponent(e.trim())}&limit=${Math.min(a,10)}`
62
64
  "number"==typeof t&&"number"==typeof i&&(l+=`&lat=${t.toFixed(6)}&lng=${i.toFixed(6)}`)
63
- try{o=await fetch(l,{method:"GET",headers:{"x-api-key":r},signal:g(8e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Autocomplete request timed out.")
65
+ try{o=await fetch(l,{method:"GET",headers:{"x-api-key":r},signal:N(8e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Autocomplete request timed out.")
64
66
  throw new Error(`Network error: ${e instanceof Error?e.message:String(e)}`)}if(!o.ok){if(401===o.status||403===o.status)throw new Error("Invalid API key.")
65
67
  if(429===o.status)throw new Error("Rate limit exceeded.")
66
68
  return[]}const s=await o.json()
67
- return s.success?s.data??[]:[]}async function x(e,r,n=v){const a=`${n.replace(/\/$/,"")}/v1/digipin/reverse`
69
+ return s.success?s.data??[]:[]}async function L(e,r,n=w){const a=`${n.replace(/\/$/,"")}/v1/digipin/reverse`
68
70
  let t
69
- try{t=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify({digipin:e}),signal:g(15e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Request timed out. Check your internet connection.")
71
+ try{t=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify({digipin:e}),signal:N(15e3)})}catch(e){if(e instanceof Error&&("TimeoutError"===e.name||"AbortError"===e.name))throw new Error("Request timed out. Check your internet connection.")
70
72
  throw new Error(`Network error: ${e instanceof Error?e.message:String(e)}`)}if(!t.ok){let e=""
71
73
  try{e=await t.text()}catch{}if(401===t.status||403===t.status)throw new Error("Invalid API key. Check your QuantaRoute API key.")
72
74
  if(429===t.status)throw new Error("Rate limit exceeded. Upgrade your plan or try again later.")
73
75
  throw new Error(`API error ${t.status}: ${e||t.statusText}`)}const i=await t.json()
74
76
  if(!i.success)throw new Error(i.message??"Reverse geocoding failed")
75
- return i}function E(){const[e,r]=t({loading:!1,error:null})
77
+ return i}function I(){const[e,r]=t({loading:!1,error:null})
76
78
  return{...e,locate:i(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."
77
- 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:i(()=>{r(e=>({...e,error:null}))},[])}}function S(e,r){if(!b(e,r))return null
78
- try{return m(e,r)}catch{return null}}const L="#0ea5e9",I=({onLocationConfirm:n,defaultLat:a,defaultLng:d,mapHeight:c="380px",theme:h="light",indiaBoundaryUrl:p,enableSearch:m=!0,apiKey:y,apiBaseUrl:b,brandColor:v=L})=>{const _=o(null),g=o(null),q=o(null),w=a??13.00427,N=d??77.589291,x=void 0!==a&&void 0!==d,[I,P]=t(w),[T,A]=t(N),[B,D]=t(()=>S(w,N)),[M,O]=t(!1),[$,U]=t(""),[F,R]=t([]),[j,W]=t(!1),[J,z]=t(null),[V,H]=t(!1),K=o(null),G=o(null),Z=l(),{loading:Y,error:Q,locate:X,clearError:ee}=E(),re=i((e,r)=>{D(S(e,r))},[]),ne=i((e,r)=>{var n
79
- P(e),A(r),re(e,r),g.current&&g.current.flyTo({center:[r,e],zoom:18,duration:900,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])},[re]),ae=i(e=>{const r=e.target.value
80
- U(r),z(null),K.current&&clearTimeout(K.current)
79
+ 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:i(()=>{r(e=>({...e,error:null}))},[])}}function P(e,r){if(!q(e,r))return null
80
+ try{return v(e,r)}catch{return null}}const T="#0ea5e9",A=({onLocationConfirm:n,defaultLat:a,defaultLng:d,mapHeight:c="380px",theme:h="light",indiaBoundaryUrl:p,enableSearch:m=!0,apiKey:f,apiBaseUrl:b,brandColor:v=T})=>{const g=o(null),q=o(null),w=o(null),N=a??13.00427,k=d??77.589291,C=void 0!==a&&void 0!==d,[x,L]=t(N),[A,B]=t(k),[$,D]=t(()=>P(N,k)),[O,M]=t(!1),[U,F]=t(""),[R,j]=t([]),[W,z]=t(!1),[J,V]=t(null),[H,G]=t(!1),K=o(null),Y=o(null),Q=l(),{loading:Z,error:X,locate:ee,clearError:re}=I(),ne=i((e,r)=>{D(P(e,r))},[]),ae=i((e,r)=>{var n
81
+ L(e),B(r),ne(e,r),q.current&&q.current.flyTo({center:[r,e],zoom:18,duration:900,essential:!0}),null==(n=w.current)||n.setLngLat([r,e])},[ne]),te=i(e=>{const r=e.target.value
82
+ F(r),V(null),K.current&&clearTimeout(K.current)
81
83
  const n=r.trim()
82
- if(!n)return R([]),H(!1),void W(!1)
83
- if(k(n))try{const e=f(n.toUpperCase()),r=parseFloat(e.latitude),a=parseFloat(e.longitude)
84
- ne(r,a),R([]),H(!1),U(n.toUpperCase())}catch{z("Invalid DigiPin code")}else{if(n.length<3)return R([]),void H(!1)
85
- W(!0),K.current=setTimeout(async()=>{try{const e=y??"",r=await C(n,e,b,5,I,T)
86
- R(r),H(r.length>0)}catch(e){z(e instanceof Error?e.message:"Search failed"),R([]),H(!1)}finally{W(!1)}},400)}},[y,b,ne]),te=i(e=>{var r
87
- ne(e.coordinates.latitude,e.coordinates.longitude),U(""),R([]),H(!1),null==(r=G.current)||r.blur()},[ne]),ie=i(e=>{"Escape"===e.key&&(R([]),H(!1),U(""))},[])
88
- s(()=>{if(!_.current)return
89
- const e=p?fetch(p).then(e=>e.ok?e.json():null).catch(()=>null):Promise.resolve(null),r=x?18:9,n=new u.Map({container:_.current,style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",center:[N,w],zoom:r,minZoom:6,attributionControl:!1,touchZoomRotate:!0})
90
- return n.addControl(new u.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 u.NavigationControl({showCompass:!1}),"top-right"),n.on("load",()=>{O(!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{}})
91
- const r=function(e=L){const r=document.createElement("div")
92
- 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}(v),a=new u.Marker({element:r,draggable:!0,anchor:"bottom"}).setLngLat([N,w]).addTo(n)
84
+ if(!n)return j([]),G(!1),void z(!1)
85
+ if(E(n))try{const e=_(n),r=parseFloat(e.latitude),a=parseFloat(e.longitude)
86
+ ae(r,a),j([]),G(!1),F(y(n))}catch{V("Invalid DigiPin code")}else{if(n.length<3)return j([]),void G(!1)
87
+ z(!0),K.current=setTimeout(async()=>{try{const e=f??"",r=await S(n,e,b,5,x,A)
88
+ j(r),G(r.length>0)}catch(e){V(e instanceof Error?e.message:"Search failed"),j([]),G(!1)}finally{z(!1)}},400)}},[f,b,ae]),ie=i(e=>{var r
89
+ ae(e.coordinates.latitude,e.coordinates.longitude),F(""),j([]),G(!1),null==(r=Y.current)||r.blur()},[ae]),oe=i(e=>{"Escape"===e.key&&(j([]),G(!1),F(""))},[])
90
+ s(()=>{if(!g.current)return
91
+ const e=p?fetch(p).then(e=>e.ok?e.json():null).catch(()=>null):Promise.resolve(null),r=C?18:9,n=new u.Map({container:g.current,style:"https://basemaps.cartocdn.com/gl/positron-gl-style/style.json",center:[k,N],zoom:r,minZoom:6,attributionControl:!1,touchZoomRotate:!0})
92
+ return n.addControl(new u.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 u.NavigationControl({showCompass:!1}),"top-right"),n.on("load",()=>{M(!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{}})
93
+ const r=function(e=T){const r=document.createElement("div")
94
+ 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}(v),a=new u.Marker({element:r,draggable:!0,anchor:"bottom"}).setLngLat([k,N]).addTo(n)
93
95
  a.on("drag",()=>{const e=a.getLngLat()
94
- P(e.lat),A(e.lng),re(e.lat,e.lng)}),a.on("dragend",()=>{const e=a.getLngLat()
95
- n.easeTo({center:[e.lng,e.lat],duration:250})}),q.current=a}),n.on("click",e=>{var r
96
+ L(e.lat),B(e.lng),ne(e.lat,e.lng)}),a.on("dragend",()=>{const e=a.getLngLat()
97
+ n.easeTo({center:[e.lng,e.lat],duration:250})}),w.current=a}),n.on("click",e=>{var r
96
98
  const a=e.lngLat
97
- null==(r=q.current)||r.setLngLat([a.lng,a.lat]),P(a.lat),A(a.lng),re(a.lat,a.lng),n.easeTo({center:[a.lng,a.lat],duration:200})}),g.current=n,()=>{n.remove(),g.current=null,q.current=null}},[])
98
- const oe=i(()=>{ee(),X((e,r)=>{var n
99
- P(e),A(r),re(e,r),g.current&&g.current.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(n=q.current)||n.setLngLat([r,e])})},[X,ee,re]),le=i(()=>{B&&n(I,T,B)},[I,T,B,n]),se=null!==B,de=se&&M
100
- return e("div",{className:"qr-map-wrapper",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge",children:"1"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Pin Your Location"}),r("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),m&&e("div",{className:"qr-search-bar",role:"search",children:[e("div",{className:"qr-search-bar__input-wrap",children:[e("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("circle",{cx:"11",cy:"11",r:"8"}),r("path",{d:"M21 21l-4.35-4.35"})]}),r("input",{ref:G,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:$,onChange:ae,onKeyDown:ie,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":V?Z:void 0,"aria-expanded":V}),j&&r("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),$&&!j&&r("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{U(""),R([]),H(!1),z(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),J&&r("p",{className:"qr-search-bar__error",role:"alert",children:J}),V&&F.length>0&&r("ul",{id:Z,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:F.map((n,a)=>e("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:e=>{e.preventDefault(),te(n)},children:[e("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("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("circle",{cx:"12",cy:"9",r:"2.5"})]}),e("div",{className:"qr-search-bar__suggestion-text",children:[r("span",{className:"qr-search-bar__suggestion-name",children:n.displayName}),n.address&&n.address!==n.displayName&&r("span",{className:"qr-search-bar__suggestion-sub",children:n.address})]})]},a))}),e("p",{className:"qr-search-bar__hint",children:[r("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),e("div",{className:"qr-map-outer",style:{height:c},children:[r("div",{ref:_,className:"qr-map-canvas"}),B&&e("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${B}`,children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:B})]}),!se&&M&&r("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r("button",{className:"qr-locate-btn"+(Y?" qr-locate-btn--loading":""),onClick:oe,disabled:Y,title:"Use my current location","aria-label":"Use my current location",type:"button",children:Y?r("span",{className:"qr-spinner","aria-hidden":"true"}):e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"7"}),r("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),Q&&e("div",{className:"qr-geo-error",role:"alert",children:[r("span",{children:Q}),r("button",{type:"button",className:"qr-geo-error__dismiss",onClick:ee,"aria-label":"Dismiss error",children:"×"})]})]}),M&&e("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[e("span",{children:[I.toFixed(5),"° N"]}),r("span",{className:"qr-coords-sep",children:"·"}),e("span",{children:[T.toFixed(5),"° E"]})]}),e("div",{className:"qr-map-actions",children:[e("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:le,disabled:!de,children:["Confirm Location",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!se&&M&&r("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"})]})]})},P={flatNumber:"",floorNumber:"",buildingName:"",streetName:""}
101
- function T(e,r){switch(r.type){case"LOAD_START":return{status:"loading"}
99
+ null==(r=w.current)||r.setLngLat([a.lng,a.lat]),L(a.lat),B(a.lng),ne(a.lat,a.lng),n.easeTo({center:[a.lng,a.lat],duration:200})}),q.current=n,()=>{n.remove(),q.current=null,w.current=null}},[])
100
+ const le=i(()=>{re(),ee((e,r)=>{var n
101
+ L(e),B(r),ne(e,r),q.current&&q.current.flyTo({center:[r,e],zoom:18,duration:1400,essential:!0}),null==(n=w.current)||n.setLngLat([r,e])})},[ee,re,ne]),se=i(()=>{$&&n(x,A,$)},[x,A,$,n]),de=null!==$,ce=de&&O
102
+ return e("div",{className:"qr-map-wrapper",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge",children:"1"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Pin Your Location"}),r("span",{className:"qr-step-sub",children:"Tap the map or drag the pin to your exact home / office"})]})]}),m&&e("div",{className:"qr-search-bar",role:"search",children:[e("div",{className:"qr-search-bar__input-wrap",children:[e("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("circle",{cx:"11",cy:"11",r:"8"}),r("path",{d:"M21 21l-4.35-4.35"})]}),r("input",{ref:Y,type:"search",className:"qr-search-bar__input",placeholder:"Search address, 'pharmacy near me', or DigiPin…",value:U,onChange:te,onKeyDown:oe,autoComplete:"off",autoCorrect:"off",autoCapitalize:"characters",spellCheck:!1,"aria-label":"Search address or DigiPin","aria-autocomplete":"list","aria-controls":H?Q:void 0,"aria-expanded":H}),W&&r("span",{className:"qr-search-bar__spinner qr-spinner qr-spinner--sm","aria-hidden":"true"}),U&&!W&&r("button",{type:"button",className:"qr-search-bar__clear",onClick:()=>{F(""),j([]),G(!1),V(null)},"aria-label":"Clear search",tabIndex:-1,children:"×"})]}),J&&r("p",{className:"qr-search-bar__error",role:"alert",children:J}),H&&R.length>0&&r("ul",{id:Q,className:"qr-search-bar__dropdown",role:"listbox","aria-label":"Address suggestions",children:R.map((n,a)=>e("li",{className:"qr-search-bar__suggestion",role:"option","aria-selected":"false",onMouseDown:e=>{e.preventDefault(),ie(n)},children:[e("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("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("circle",{cx:"12",cy:"9",r:"2.5"})]}),e("div",{className:"qr-search-bar__suggestion-text",children:[r("span",{className:"qr-search-bar__suggestion-name",children:n.displayName}),n.address&&n.address!==n.displayName&&r("span",{className:"qr-search-bar__suggestion-sub",children:n.address})]})]},a))}),e("p",{className:"qr-search-bar__hint",children:[r("span",{className:"qr-search-bar__hint-chip",children:"DigiPin"}),"Type your DigiPin code for instant offline lookup — no API call"]})]}),e("div",{className:"qr-map-outer",style:{height:c},children:[r("div",{ref:g,className:"qr-map-canvas"}),$&&e("div",{className:"qr-digipin-badge","aria-live":"polite","aria-label":`DigiPin: ${$}`,children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:$})]}),!de&&O&&r("div",{className:"qr-map-notice",role:"status",children:"Move map to India to get a DigiPin"}),r("button",{className:"qr-locate-btn"+(Z?" qr-locate-btn--loading":""),onClick:le,disabled:Z,title:"Use my current location","aria-label":"Use my current location",type:"button",children:Z?r("span",{className:"qr-spinner","aria-hidden":"true"}):e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"7"}),r("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]})}),X&&e("div",{className:"qr-geo-error",role:"alert",children:[r("span",{children:X}),r("button",{type:"button",className:"qr-geo-error__dismiss",onClick:re,"aria-label":"Dismiss error",children:"×"})]})]}),O&&e("div",{className:"qr-coords-strip","aria-label":"Current pin coordinates",children:[e("span",{children:[x.toFixed(5),"° N"]}),r("span",{className:"qr-coords-sep",children:"·"}),e("span",{children:[A.toFixed(5),"° E"]})]}),e("div",{className:"qr-map-actions",children:[e("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:se,disabled:!ce,children:["Confirm Location",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]}),!de&&O&&r("p",{className:"qr-map-hint",children:"Move the pin to a location in India to continue"})]})]})},B={flatNumber:"",floorNumber:"",buildingName:"",streetName:""}
103
+ function $(e,r){switch(r.type){case"LOAD_START":return{status:"loading"}
102
104
  case"LOAD_SUCCESS":{const e=function(e){const r={}
103
105
  e.name?r.buildingName=e.name:e.building_name?r.buildingName=e.building_name:e.addr_housename&&(r.buildingName=e.addr_housename)
104
106
  const n=[]
105
107
  return e.road&&n.push(e.road),e.suburb&&n.push(e.suburb),n.length>0&&(r.streetName=n.join(", ")),r}(r.addressComponents)
106
- return{status:"ready",adminInfo:r.adminInfo,alternatives:r.alternatives||[],selectedLocality:r.adminInfo.locality,selectedLabel:"home",fields:{...P,...e},submitting:!1,pincodeHasDelivery:r.pincodeHasDelivery}}case"LOAD_ERROR":return{status:"error",message:r.message}
108
+ return{status:"ready",adminInfo:r.adminInfo,alternatives:r.alternatives||[],selectedLocality:r.adminInfo.locality,selectedLabel:"home",fields:{...B,...e},submitting:!1,pincodeHasDelivery:r.pincodeHasDelivery}}case"LOAD_ERROR":return{status:"error",message:r.message}
107
109
  case"SET_FIELD":return"ready"!==e.status?e:{...e,fields:{...e.fields,[r.key]:r.value}}
108
110
  case"SET_LOCALITY":return"ready"!==e.status?e:{...e,selectedLocality:r.locality}
109
111
  case"SET_LABEL":return"ready"!==e.status?e:{...e,selectedLabel:r.label}
110
112
  case"SUBMIT_START":return"ready"!==e.status?e:{...e,submitting:!0}
111
113
  case"SUBMIT_END":return"ready"!==e.status?e:{...e,submitting:!1}
112
- default:return e}}const A=({digipin:a,lat:t,lng:o,apiKey:l,apiBaseUrl:c,onAddressComplete:u,onBack:h,onError:p})=>{const[m,f]=d(T,{status:"loading"}),y=i(async()=>{var e
114
+ default:return e}}const D=({digipin:a,lat:t,lng:o,apiKey:l,apiBaseUrl:c,onAddressComplete:u,onBack:h,onError:p})=>{const[m,f]=d($,{status:"loading"}),y=i(async()=>{var e
113
115
  f({type:"LOAD_START"})
114
- try{const[r,n]=await Promise.all([q(t,o,l,c),x(a,l,c)]),i=(null==(e=r.data.administrative_info.pincode)?void 0:e.replace(/\D/g,"").slice(0,6))??""
116
+ try{const[r,n]=await Promise.all([k(t,o,l,c),L(a,l,c)]),i=(null==(e=r.data.administrative_info.pincode)?void 0:e.replace(/\D/g,"").slice(0,6))??""
115
117
  if(6!==i.length)return f({type:"LOAD_ERROR",message:"Could not determine a valid 6-digit pincode for this location. Please adjust the map pin."}),void(null==p||p(new Error("Missing or invalid pincode")))
116
- const s=await w(i,l,c)
118
+ const s=await C(i,l,c)
117
119
  if(!s.isValid)return f({type:"LOAD_ERROR",message:"This location resolves to a pincode that is not in the India Post database. Please move the map pin to a valid address."}),void(null==p||p(new Error("Invalid pincode for location")))
118
- const d=N(s.offices)
120
+ const d=x(s.offices)
119
121
  f({type:"LOAD_SUCCESS",adminInfo:r.data.administrative_info,alternatives:r.data.alternatives||[],addressComponents:n.data.addressComponents,pincodeHasDelivery:d})}catch(e){const r=e instanceof Error?e.message:"Failed to fetch address data."
120
122
  f({type:"LOAD_ERROR",message:r}),null==p||p(e instanceof Error?e:new Error(r))}},[a,t,o,l,c,p])
121
123
  s(()=>{y()},[y])
@@ -124,40 +126,40 @@ const{adminInfo:r,selectedLocality:n,selectedLabel:i,fields:l}=m,s=[l.flatNumber
124
126
  f({type:"SUBMIT_START"})
125
127
  try{u(d)}finally{f({type:"SUBMIT_END"})}},[m,a,t,o,u])
126
128
  return e("div",{className:"qr-form-wrapper",children:[e("div",{className:"qr-step-header",children:[r("button",{type:"button",className:"qr-back-btn",onClick:h,"aria-label":"Back to map",children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),r("div",{className:"qr-step-badge",children:"2"}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Add Address Details"}),r("span",{className:"qr-step-sub",children:"Flat number and building info"})]})]}),e("div",{className:"qr-form-digipin-strip",children:[e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r("circle",{cx:"12",cy:"10",r:"3"})]}),r("span",{className:"qr-form-digipin-strip__label",children:"DigiPin"}),r("span",{className:"qr-form-digipin-strip__code",children:a})]}),"loading"===m.status&&e("div",{className:"qr-loading-state","aria-busy":"true","aria-label":"Fetching address details",children:[r("div",{className:"qr-spinner qr-spinner--lg","aria-hidden":"true"}),r("p",{className:"qr-loading-state__text",children:"Fetching address details…"})]}),"error"===m.status&&e("div",{className:"qr-error-state",role:"alert",children:[r("div",{className:"qr-error-state__icon","aria-hidden":"true",children:"⚠"}),r("p",{className:"qr-error-state__msg",children:m.message}),r("button",{type:"button",className:"qr-btn qr-btn--secondary qr-btn--sm",onClick:()=>{y()},children:"Retry"})]}),"ready"===m.status&&e("form",{onSubmit:b,className:"qr-form",noValidate:!0,children:[e("fieldset",{className:"qr-fieldset",children:[e("legend",{className:"qr-fieldset__legend",children:[r("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"📍"}),"Auto-detected from your pin"]}),e("div",{className:"qr-auto-grid",children:[e("div",{className:"qr-auto-row",children:[r("span",{className:"qr-auto-row__label",children:"State"}),r("span",{className:"qr-auto-row__value",children:m.adminInfo.state})]}),e("div",{className:"qr-auto-row",children:[r("span",{className:"qr-auto-row__label",children:"District"}),r("span",{className:"qr-auto-row__value",children:m.adminInfo.district})]}),e("div",{className:"qr-auto-row qr-auto-row--full",children:[r("span",{className:"qr-auto-row__label",children:"Locality"}),m.alternatives.length>0?e("select",{className:"qr-auto-row__select",value:m.selectedLocality,onChange:e=>f({type:"SET_LOCALITY",locality:e.target.value}),"aria-label":"Select locality",children:[r("option",{value:m.adminInfo.locality,children:m.adminInfo.locality}),m.alternatives.map((e,n)=>r("option",{value:e.name,children:e.name},n))]}):r("span",{className:"qr-auto-row__value",children:m.selectedLocality})]}),e("div",{className:"qr-auto-row",children:[r("span",{className:"qr-auto-row__label",children:"Pincode"}),r("span",{className:"qr-auto-row__value qr-auto-row__value--pin",children:m.adminInfo.pincode})]})]})]}),!m.pincodeHasDelivery&&e("div",{className:"qr-pincode-banner qr-pincode-banner--warning",role:"status","aria-live":"polite",children:[r("span",{className:"qr-pincode-banner__icon","aria-hidden":"true",children:"⚠"}),e("div",{className:"qr-pincode-banner__text",children:[r("strong",{children:"Non-delivery area"}),r("span",{children:"This pincode has no India Post home-delivery office. Courier delivery may be limited — confirm with your seller before placing the order."})]})]}),e("fieldset",{className:"qr-fieldset",children:[r("legend",{className:"qr-fieldset__legend",children:"Save as"}),r("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:n,title:a,icon:t})=>e("button",{type:"button",role:"radio","aria-checked":m.selectedLabel===n,className:"qr-label-picker__option"+(m.selectedLabel===n?" qr-label-picker__option--active":""),onClick:()=>f({type:"SET_LABEL",label:n}),children:[r("span",{className:"qr-label-picker__icon","aria-hidden":"true",children:t}),r("span",{children:a})]},n))})]}),e("fieldset",{className:"qr-fieldset",children:[e("legend",{className:"qr-fieldset__legend",children:[r("span",{className:"qr-fieldset__icon","aria-hidden":"true",children:"🏠"}),"Your details"]}),e("div",{className:"qr-fields-grid",children:[e("div",{className:"qr-field qr-field--full",children:[e("label",{className:"qr-field__label",htmlFor:"qr-flatNumber",children:["Flat / House Number",r("span",{className:"qr-required","aria-hidden":"true",children:"*"})]}),r("input",{id:"qr-flatNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 4B, Flat 201, House No. 12",value:m.fields.flatNumber,onChange:e=>f({type:"SET_FIELD",key:"flatNumber",value:e.target.value}),autoComplete:"address-line1",required:!0,"aria-required":"true"})]}),e("div",{className:"qr-field",children:[e("label",{className:"qr-field__label",htmlFor:"qr-floorNumber",children:["Floor",r("span",{className:"qr-optional",children:"optional"})]}),r("input",{id:"qr-floorNumber",type:"text",className:"qr-field__input",placeholder:"e.g. 3rd, Ground",value:m.fields.floorNumber,onChange:e=>f({type:"SET_FIELD",key:"floorNumber",value:e.target.value})})]}),e("div",{className:"qr-field",children:[e("label",{className:"qr-field__label",htmlFor:"qr-buildingName",children:["Building / Society",r("span",{className:"qr-optional",children:"optional"})]}),r("input",{id:"qr-buildingName",type:"text",className:"qr-field__input",placeholder:"e.g. Sunshine Apts, DDA Colony",value:m.fields.buildingName,onChange:e=>f({type:"SET_FIELD",key:"buildingName",value:e.target.value}),autoComplete:"address-line2"})]}),e("div",{className:"qr-field qr-field--full",children:[e("label",{className:"qr-field__label",htmlFor:"qr-streetName",children:["Street / Area",r("span",{className:"qr-optional",children:"optional"})]}),r("input",{id:"qr-streetName",type:"text",className:"qr-field__input",placeholder:"e.g. MG Road, Sector 12",value:m.fields.streetName,onChange:e=>f({type:"SET_FIELD",key:"streetName",value:e.target.value}),autoComplete:"address-level3"})]})]})]}),e("div",{className:"qr-form-actions",children:[e("button",{type:"button",className:"qr-btn qr-btn--ghost",onClick:h,children:[r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),"Adjust Pin"]}),r("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--grow",disabled:m.submitting||!m.fields.flatNumber.trim(),children:m.submitting?e(n,{children:[r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}),"Saving…"]}):e(n,{children:["Save Address",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M20 6L9 17l-5-5"})})]})})]})]})]})}
127
- async function B(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(()=>({}))
128
- if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")}async function D(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(()=>({}))
129
+ async function O(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(()=>({}))
130
+ if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")}async function M(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(()=>({}))
129
131
  if(!t.ok||!i.success)throw new Error(i.error??"Invalid or expired OTP.")
130
- return i}function M(e){return{"Content-Type":"application/json","x-session-token":e}}async function O(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"list"})}),a=await n.json().catch(()=>({}))
132
+ return i}function U(e){return{"Content-Type":"application/json","x-session-token":e}}async function F(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify({action:"list"})}),a=await n.json().catch(()=>({}))
131
133
  if(!n.ok||!a.success)throw new Error(a.error??"Failed to load saved addresses.")
132
- return a.data??[]}async function $(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"create",address:n})}),t=await a.json().catch(()=>({}))
134
+ return a.data??[]}async function R(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify({action:"create",address:n})}),t=await a.json().catch(()=>({}))
133
135
  if(!a.ok||!t.success)throw new Error(t.error??"Failed to save address.")
134
- return t.data}async function U(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"delete",address_id:n})}),t=await a.json().catch(()=>({}))
135
- if(!a.ok||!t.success)throw new Error(t.error??"Failed to delete address.")}async function F(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"set_default",address_id:n})}),t=await a.json().catch(()=>({}))
136
- if(!a.ok||!t.success)throw new Error(t.error??"Failed to set default address.")}async function R(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"address_completed",data:n})}),t=await a.json().catch(()=>({}))
137
- !a.ok||t.success}async function j(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(()=>({}))
136
+ return t.data}async function j(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify({action:"delete",address_id:n})}),t=await a.json().catch(()=>({}))
137
+ if(!a.ok||!t.success)throw new Error(t.error??"Failed to delete address.")}async function W(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify({action:"set_default",address_id:n})}),t=await a.json().catch(()=>({}))
138
+ if(!a.ok||!t.success)throw new Error(t.error??"Failed to set default address.")}async function z(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify({action:"address_completed",data:n})}),t=await a.json().catch(()=>({}))
139
+ !a.ok||t.success}async function J(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(()=>({}))
138
140
  if(!n.ok||!a.success)throw new Error(a.error??"Failed to send OTP. Please try again.")
139
- return{reused:Boolean(a.reused)}}async function W(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(()=>({}))
141
+ return{reused:Boolean(a.reused)}}async function V(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(()=>({}))
140
142
  if(!t.ok||!i.success)throw new Error(i.error??"Invalid or expired code.")
141
- return i}async function J(e,r,n,a){const t={action:"cod_eligibility",pincode:n}
143
+ return i}async function H(e,r,n,a){const t={action:"cod_eligibility",pincode:n}
142
144
  void 0!==a&&(t.cart_total_paise=a)
143
- const i=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify(t)}),o=await i.json().catch(()=>({}))
145
+ const i=await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify(t)}),o=await i.json().catch(()=>({}))
144
146
  if(!i.ok||!o.success)throw new Error(o.error??"Failed to check COD eligibility.")
145
- return o.data}async function z(e,r,n){try{const a={"Content-Type":"application/json"}
146
- 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 V(e,r,n){try{await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:M(r),body:JSON.stringify({action:"abandon",last_step:n})})}catch{}}async function H(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-offers`,{method:"GET",headers:M(r)}),a=await n.json().catch(()=>({}))
147
- return n.ok&&a.success?a.data??null:null}async function K(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:M(r),body:JSON.stringify({action:"create_order",amount_paise:n})}),t=await a.json().catch(()=>({}))
147
+ return o.data}async function G(e,r,n){try{const a={"Content-Type":"application/json"}
148
+ 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 K(e,r,n){try{await fetch(`${e.functionBaseUrl}/checkout-addresses`,{method:"POST",headers:U(r),body:JSON.stringify({action:"abandon",last_step:n})})}catch{}}async function Y(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-offers`,{method:"GET",headers:U(r)}),a=await n.json().catch(()=>({}))
149
+ return n.ok&&a.success?a.data??null:null}async function Q(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:U(r),body:JSON.stringify({action:"create_order",amount_paise:n})}),t=await a.json().catch(()=>({}))
148
150
  if(!a.ok||!t.success)throw new Error(t.error??"Failed to create payment order.")
149
- return t.data}async function G(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:M(r),body:JSON.stringify({action:"verify",...n})}),t=await a.json().catch(()=>({}))
151
+ return t.data}async function Z(e,r,n){const a=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:U(r),body:JSON.stringify({action:"verify",...n})}),t=await a.json().catch(()=>({}))
150
152
  if(!a.ok||!t.success)throw new Error(t.error??"Payment verification failed.")
151
- return{payment_method:t.payment_method}}async function Z(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:M(r),body:JSON.stringify({action:"record_cod"})}),a=await n.json().catch(()=>({}))
153
+ return{payment_method:t.payment_method}}async function X(e,r){const n=await fetch(`${e.functionBaseUrl}/checkout-payment`,{method:"POST",headers:U(r),body:JSON.stringify({action:"record_cod"})}),a=await n.json().catch(()=>({}))
152
154
  if(!n.ok||!a.success)throw new Error(a.error??"Failed to record COD selection.")
153
- return{payment_method:a.payment_method}}async function Y(e,r){const n=await fetch(`${e}/checkout-admin?action=cod_config`,{headers:{"x-api-key":r}}),a=await n.json().catch(()=>({}))
154
- return n.ok&&a.success?{prepaid_nudge_copy:a.data.prepaid_nudge_copy,prepaid_nudge_cta_url:a.data.prepaid_nudge_cta_url}:null}const Q=({onOtpSent:a,onSkip:l,functionBaseUrl:s,merchantId:d})=>{const[c,u]=t(""),[h,p]=t(!1),[m,f]=t(null),y=o(null),b=i(e=>{u(e.target.value.replace(/\D/g,"").slice(0,10)),f(null)},[]),v=i(async e=>{var r
155
+ return{payment_method:a.payment_method}}async function ee(e,r){const n=await fetch(`${e}/checkout-admin?action=cod_config`,{headers:{"x-api-key":r}}),a=await n.json().catch(()=>({}))
156
+ return n.ok&&a.success?{prepaid_nudge_copy:a.data.prepaid_nudge_copy,prepaid_nudge_cta_url:a.data.prepaid_nudge_cta_url}:null}const re=({onOtpSent:a,onSkip:l,functionBaseUrl:s,merchantId:d})=>{const[c,u]=t(""),[h,p]=t(!1),[m,f]=t(null),y=o(null),b=i(e=>{u(e.target.value.replace(/\D/g,"").slice(0,10)),f(null)},[]),v=i(async e=>{var r
155
157
  if(e.preventDefault(),10!==c.length)return f("Enter a valid 10-digit mobile number."),void(null==(r=y.current)||r.focus())
156
158
  p(!0),f(null)
157
- try{await B({functionBaseUrl:s,merchantId:d},`+91${c}`),a(`+91${c}`)}catch(e){f(e instanceof Error?e.message:"Failed to send OTP. Please try again.")}finally{p(!1)}},[c,s,d,a])
159
+ try{await O({functionBaseUrl:s,merchantId:d},`+91${c}`),a(`+91${c}`)}catch(e){f(e instanceof Error?e.message:"Failed to send OTP. Please try again.")}finally{p(!1)}},[c,s,d,a])
158
160
  return e("div",{className:"qr-auth-step",children:[r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("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("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r("p",{className:"qr-auth-step__sub",children:"Enter your mobile to load saved addresses"}),e("form",{onSubmit:v,noValidate:!0,children:[e("div",{className:"qr-phone-field"+(m?" qr-phone-field--error":""),children:[r("span",{className:"qr-phone-field__prefix","aria-hidden":"true",children:"+91"}),r("input",{ref:y,type:"tel",inputMode:"numeric",className:"qr-phone-field__input",placeholder:"98765 43210",value:c,onChange:b,maxLength:10,autoComplete:"tel-national","aria-label":"Mobile number","aria-describedby":m?"qr-phone-error":void 0,"aria-invalid":!!m,disabled:h})]}),m&&r("p",{id:"qr-phone-error",className:"qr-auth-step__error",role:"alert",children:m}),r("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:h||10!==c.length,children:h?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):e(n,{children:["Send OTP",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:l,disabled:h,children:"Skip, enter address manually"})]})}
159
- function X(e){const r=e.replace(/\D/g,"")
160
- return r.length<4?e:`+91 ${r.slice(2,7)} **${r.slice(-3)}`}const ee=({mobile:n,onVerified:a,onBack:l,functionBaseUrl:d,merchantId:c,sessionContext:u})=>{const[h,p]=t(Array(6).fill("")),[m,f]=t(!1),[y,b]=t(null),[v,_]=t(30),[g,q]=t(!1),w=o([]),N=o(null)
161
+ function ne(e){const r=e.replace(/\D/g,"")
162
+ return r.length<4?e:`+91 ${r.slice(2,7)} **${r.slice(-3)}`}const ae=({mobile:n,onVerified:a,onBack:l,functionBaseUrl:d,merchantId:c,sessionContext:u})=>{const[h,p]=t(Array(6).fill("")),[m,f]=t(!1),[y,b]=t(null),[v,_]=t(30),[g,q]=t(!1),w=o([]),N=o(null)
161
163
  s(()=>(N.current=setInterval(()=>{_(e=>e<=1?(clearInterval(N.current),0):e-1)},1e3),()=>{N.current&&clearInterval(N.current)}),[])
162
164
  const k=e=>{var r
163
165
  null==(r=w.current[e])||r.focus()},C=i((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
@@ -169,49 +171,49 @@ const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6)
169
171
  if(!r)return
170
172
  const n=Array(6).fill("")
171
173
  r.split("").forEach((e,r)=>{n[r]=e}),p(n),b(null),k(Math.min(r.length,5))},[]),S=h.join(""),L=6===S.length&&!h.includes(""),I=i(async()=>{if(L){f(!0),b(null)
172
- try{const e=await D({functionBaseUrl:d,merchantId:c},n,S,u)
174
+ try{const e=await M({functionBaseUrl:d,merchantId:c},n,S,u)
173
175
  a(e.session_token,e.buyer_id,e.session_id)}catch(e){b(e instanceof Error?e.message:"Verification failed. Please try again."),p(Array(6).fill("")),k(0)}finally{f(!1)}}},[L,S,n,d,c,a,u])
174
176
  s(()=>{L&&!m&&I()},[L])
175
177
  const P=i(async()=>{if(!(v>0||g)){q(!0),b(null),p(Array(6).fill(""))
176
- try{await B({functionBaseUrl:d,merchantId:c},n),_(30),N.current=setInterval(()=>{_(e=>e<=1?(clearInterval(N.current),0):e-1)},1e3),k(0)}catch(e){b(e instanceof Error?e.message:"Failed to resend OTP.")}finally{q(!1)}}},[v,g,d,c,n])
177
- return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:l,disabled:m,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"13",y:"16",width:"22",height:"16",rx:"2",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M13 22h22",stroke:"var(--qr-primary)",strokeWidth:"1.8"}),r("circle",{cx:"18",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"24",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"30",cy:"29",r:"1.5",fill:"var(--qr-primary)"})]})}),r("h3",{className:"qr-auth-step__title",children:"Enter OTP"}),e("p",{className:"qr-auth-step__sub",children:["Sent to ",r("strong",{children:X(n)})]}),r("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter one-time password",children:h.map((e,n)=>r("input",{ref:e=>{w.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${y?" qr-otp-box--error":""}`,value:e,onChange:e=>C(n,e.target.value),onKeyDown:e=>x(n,e),onPaste:E,onFocus:e=>e.target.select(),"aria-label":`OTP digit ${n+1}`,disabled:m,autoComplete:0===n?"one-time-code":"off"},n))}),y&&r("p",{className:"qr-auth-step__error",role:"alert",children:y}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:I,disabled:!L||m,children:m?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify OTP"}),r("p",{className:"qr-auth-step__resend",children:v>0?e("span",{children:["Resend OTP in ",v,"s"]}):r("button",{type:"button",className:"qr-link-btn",onClick:P,disabled:g,children:g?"Sending…":"Resend OTP"})})]})},re=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M3 9.5L12 3l9 6.5V20a1 1 0 01-1 1H4a1 1 0 01-1-1V9.5z"}),r("path",{d:"M9 21V12h6v9"})]}),ne=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),r("path",{d:"M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2"})]}),ae=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("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("circle",{cx:"12",cy:"9",r:"2.5"})]})
178
- function te({label:e}){return r("home"===e?re:"work"===e?ne:ae,{})}function ie({address:a,onUse:t,onDelete:i,onSetDefault:o,deleting:l}){const s=[a.flat_number,a.building_name,a.street_name,a.locality,a.district,a.state,a.pincode].filter(Boolean),d=[a.flat_number,a.building_name,a.street_name].filter(Boolean).join(", "),c=[a.locality,a.district].filter(Boolean).join(", "),u=[a.state,a.pincode].filter(Boolean).join(" – "),h=s.length>0?void 0:a.locality||a.district||a.state
179
- return e("div",{className:"qr-addr-card"+(a.is_default?" qr-addr-card--default":""),children:[e("div",{className:"qr-addr-card__header",children:[r("div",{className:"qr-addr-card__label-icon",children:r(te,{label:a.label})}),r("span",{className:"qr-addr-card__label",children:a.label.charAt(0).toUpperCase()+a.label.slice(1)}),a.is_default&&r("span",{className:"qr-addr-card__default-badge",children:"Default"}),e("div",{className:"qr-addr-card__actions",children:[!a.is_default&&r("button",{type:"button",className:"qr-icon-btn",title:"Set as default",onClick:o,"aria-label":"Set as default address",children:r("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:r("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("button",{type:"button",className:"qr-icon-btn qr-icon-btn--danger",title:"Delete address",onClick:i,disabled:l,"aria-label":"Delete address",children:l?r("span",{className:"qr-spinner qr-spinner--xs","aria-hidden":"true"}):e("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("polyline",{points:"3 6 5 6 21 6"}),r("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),r("path",{d:"M10 11v6M14 11v6"}),r("path",{d:"M9 6V4a1 1 0 011-1h4a1 1 0 011 1v2"})]})})]})]}),e("div",{className:"qr-addr-card__body",children:[h?r("p",{className:"qr-addr-card__line",children:h}):e(n,{children:[d&&r("p",{className:"qr-addr-card__line",children:d}),c&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:c}),u&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:u})]}),e("div",{className:"qr-addr-card__meta",children:[e("span",{className:"qr-digipin-badge qr-digipin-badge--inline qr-digipin-badge--sm",children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:a.digipin})]}),a.saved_at_brand&&e("span",{className:"qr-addr-card__brand-chip",title:`First saved at ${a.saved_at_brand}`,children:[r("svg",{viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:r("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"})}),a.saved_at_brand]})]})]}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full qr-btn--sm",onClick:t,children:"Deliver here"})]})}const oe=({sessionToken:n,functionBaseUrl:a,merchantId:o,onSelectAddress:l,onAddNew:d})=>{const[c,u]=t([]),[h,p]=t(!0),[m,f]=t(null),[y,b]=t(null),v={functionBaseUrl:a,merchantId:o},_=i(async()=>{p(!0),f(null)
180
- try{const e=await O(v,n)
178
+ try{await O({functionBaseUrl:d,merchantId:c},n),_(30),N.current=setInterval(()=>{_(e=>e<=1?(clearInterval(N.current),0):e-1)},1e3),k(0)}catch(e){b(e instanceof Error?e.message:"Failed to resend OTP.")}finally{q(!1)}}},[v,g,d,c,n])
179
+ return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:l,disabled:m,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"13",y:"16",width:"22",height:"16",rx:"2",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M13 22h22",stroke:"var(--qr-primary)",strokeWidth:"1.8"}),r("circle",{cx:"18",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"24",cy:"29",r:"1.5",fill:"var(--qr-primary)"}),r("circle",{cx:"30",cy:"29",r:"1.5",fill:"var(--qr-primary)"})]})}),r("h3",{className:"qr-auth-step__title",children:"Enter OTP"}),e("p",{className:"qr-auth-step__sub",children:["Sent to ",r("strong",{children:ne(n)})]}),r("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter one-time password",children:h.map((e,n)=>r("input",{ref:e=>{w.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${y?" qr-otp-box--error":""}`,value:e,onChange:e=>C(n,e.target.value),onKeyDown:e=>x(n,e),onPaste:E,onFocus:e=>e.target.select(),"aria-label":`OTP digit ${n+1}`,disabled:m,autoComplete:0===n?"one-time-code":"off"},n))}),y&&r("p",{className:"qr-auth-step__error",role:"alert",children:y}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:I,disabled:!L||m,children:m?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify OTP"}),r("p",{className:"qr-auth-step__resend",children:v>0?e("span",{children:["Resend OTP in ",v,"s"]}):r("button",{type:"button",className:"qr-link-btn",onClick:P,disabled:g,children:g?"Sending…":"Resend OTP"})})]})},te=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("path",{d:"M3 9.5L12 3l9 6.5V20a1 1 0 01-1 1H4a1 1 0 01-1-1V9.5z"}),r("path",{d:"M9 21V12h6v9"})]}),ie=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("rect",{x:"2",y:"7",width:"20",height:"14",rx:"2"}),r("path",{d:"M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2"})]}),oe=()=>e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("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("circle",{cx:"12",cy:"9",r:"2.5"})]})
180
+ function le({label:e}){return r("home"===e?te:"work"===e?ie:oe,{})}function se({address:a,onUse:t,onDelete:i,onSetDefault:o,deleting:l}){const s=[a.flat_number,a.building_name,a.street_name,a.locality,a.district,a.state,a.pincode].filter(Boolean),d=[a.flat_number,a.building_name,a.street_name].filter(Boolean).join(", "),c=[a.locality,a.district].filter(Boolean).join(", "),u=[a.state,a.pincode].filter(Boolean).join(" – "),h=s.length>0?void 0:a.locality||a.district||a.state
181
+ return e("div",{className:"qr-addr-card"+(a.is_default?" qr-addr-card--default":""),children:[e("div",{className:"qr-addr-card__header",children:[r("div",{className:"qr-addr-card__label-icon",children:r(le,{label:a.label})}),r("span",{className:"qr-addr-card__label",children:a.label.charAt(0).toUpperCase()+a.label.slice(1)}),a.is_default&&r("span",{className:"qr-addr-card__default-badge",children:"Default"}),e("div",{className:"qr-addr-card__actions",children:[!a.is_default&&r("button",{type:"button",className:"qr-icon-btn",title:"Set as default",onClick:o,"aria-label":"Set as default address",children:r("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:r("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("button",{type:"button",className:"qr-icon-btn qr-icon-btn--danger",title:"Delete address",onClick:i,disabled:l,"aria-label":"Delete address",children:l?r("span",{className:"qr-spinner qr-spinner--xs","aria-hidden":"true"}):e("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[r("polyline",{points:"3 6 5 6 21 6"}),r("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),r("path",{d:"M10 11v6M14 11v6"}),r("path",{d:"M9 6V4a1 1 0 011-1h4a1 1 0 011 1v2"})]})})]})]}),e("div",{className:"qr-addr-card__body",children:[h?r("p",{className:"qr-addr-card__line",children:h}):e(n,{children:[d&&r("p",{className:"qr-addr-card__line",children:d}),c&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:c}),u&&r("p",{className:"qr-addr-card__line qr-addr-card__line--muted",children:u})]}),e("div",{className:"qr-addr-card__meta",children:[e("span",{className:"qr-digipin-badge qr-digipin-badge--inline qr-digipin-badge--sm",children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:a.digipin})]}),a.saved_at_brand&&e("span",{className:"qr-addr-card__brand-chip",title:`First saved at ${a.saved_at_brand}`,children:[r("svg",{viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:r("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"})}),a.saved_at_brand]})]})]}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full qr-btn--sm",onClick:t,children:"Deliver here"})]})}const de=({sessionToken:n,functionBaseUrl:a,merchantId:o,onSelectAddress:l,onAddNew:d})=>{const[c,u]=t([]),[h,p]=t(!0),[m,f]=t(null),[y,b]=t(null),v={functionBaseUrl:a,merchantId:o},_=i(async()=>{p(!0),f(null)
182
+ try{const e=await F(v,n)
181
183
  if(0===e.length)return void d()
182
184
  u(e)}catch(e){f(e instanceof Error?e.message:"Failed to load addresses.")}finally{p(!1)}},[n])
183
185
  s(()=>{_()},[_])
184
186
  const g=i(async e=>{b(e)
185
- try{await U(v,n,e),u(r=>{const n=r.filter(r=>r.id!==e)
186
- return 0===n.length&&d(),n})}catch(e){f(e instanceof Error?e.message:"Failed to delete address.")}finally{b(null)}},[n,d]),q=i(async e=>{try{await F(v,n,e),u(r=>r.map(r=>({...r,is_default:r.id===e})))}catch(e){f(e instanceof Error?e.message:"Failed to set default.")}},[n])
187
- return h?r("div",{className:"qr-saved-step",children:r("div",{className:"qr-saved-step__loading","aria-live":"polite",children:r("span",{className:"qr-spinner","aria-label":"Loading addresses"})})}):m&&0===c.length?e("div",{className:"qr-saved-step",children:[r("p",{className:"qr-auth-step__error",role:"alert",children:m}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:_,children:"Retry"}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:d,children:"Enter address manually"})]}):e("div",{className:"qr-saved-step",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge qr-step-badge--saved",children:e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("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("circle",{cx:"12",cy:"9",r:"2.5"})]})}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Saved Addresses"}),r("span",{className:"qr-step-sub",children:"Pick one or add a new location"})]})]}),m&&r("p",{className:"qr-auth-step__error",role:"alert",children:m}),r("div",{className:"qr-saved-step__list",children:c.map(e=>r(ie,{address:e,onUse:()=>l(e),onDelete:()=>g(e.id),onSetDefault:()=>q(e.id),deleting:y===e.id},e.id))}),e("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:d,children:[r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M12 5v14M5 12h14"})}),"Add new address"]})]})},le=({checkoutConfig:n,sessionToken:a,pincode:i,cartTotalPaise:o,theme:l="light",onCodAllowedChange:d})=>{const[c,u]=t("loading"),[h,p]=t(!1),[m,f]=t()
187
+ try{await j(v,n,e),u(r=>{const n=r.filter(r=>r.id!==e)
188
+ return 0===n.length&&d(),n})}catch(e){f(e instanceof Error?e.message:"Failed to delete address.")}finally{b(null)}},[n,d]),q=i(async e=>{try{await W(v,n,e),u(r=>r.map(r=>({...r,is_default:r.id===e})))}catch(e){f(e instanceof Error?e.message:"Failed to set default.")}},[n])
189
+ return h?r("div",{className:"qr-saved-step",children:r("div",{className:"qr-saved-step__loading","aria-live":"polite",children:r("span",{className:"qr-spinner","aria-label":"Loading addresses"})})}):m&&0===c.length?e("div",{className:"qr-saved-step",children:[r("p",{className:"qr-auth-step__error",role:"alert",children:m}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:_,children:"Retry"}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:d,children:"Enter address manually"})]}):e("div",{className:"qr-saved-step",children:[e("div",{className:"qr-step-header",children:[r("div",{className:"qr-step-badge qr-step-badge--saved",children:e("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r("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("circle",{cx:"12",cy:"9",r:"2.5"})]})}),e("div",{className:"qr-step-text",children:[r("span",{className:"qr-step-title",children:"Saved Addresses"}),r("span",{className:"qr-step-sub",children:"Pick one or add a new location"})]})]}),m&&r("p",{className:"qr-auth-step__error",role:"alert",children:m}),r("div",{className:"qr-saved-step__list",children:c.map(e=>r(se,{address:e,onUse:()=>l(e),onDelete:()=>g(e.id),onSetDefault:()=>q(e.id),deleting:y===e.id},e.id))}),e("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:d,children:[r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M12 5v14M5 12h14"})}),"Add new address"]})]})},ce=({checkoutConfig:n,sessionToken:a,pincode:i,cartTotalPaise:o,theme:l="light",onCodAllowedChange:d})=>{const[c,u]=t("loading"),[h,p]=t(!1),[m,f]=t()
188
190
  return s(()=>{let e=!1
189
- return u("loading"),(async()=>{try{const r=await J(n,a,i,o)
191
+ return u("loading"),(async()=>{try{const r=await H(n,a,i,o)
190
192
  if(e)return
191
193
  p(r.cod_allowed),null==d||d(r.cod_allowed),f(r.cod_allowed?void 0:r.reason?function(e){switch(e){case"cod_disabled":return"Cash on Delivery is not enabled for this store."
192
194
  case"pincode_blocked":return"COD is not available for this pincode."
193
195
  case"cart_value_exceeded":return"COD is not available for this order value."
194
196
  case"invalid_pincode":return"Enter a valid pincode to check COD."
195
- default:return"COD is not available."}}(r.reason):void 0),u("ready")}catch{e||(u("error"),p(!1),f("Could not verify COD. Try again."))}})(),()=>{e=!0}},[n,a,i,o]),e("div",{className:"qr-cod-banner"+("dark"===l?" qr-cod-banner--dark":""),role:"status","aria-live":"polite",children:[r("div",{className:"qr-cod-banner__title",children:"Cash on Delivery"}),"loading"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:"Checking availability…"}),"error"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--warn",children:m}),"ready"===c&&h&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",children:"Available for this address."}),"ready"===c&&!h&&m&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:m})]})},se=({copy:n,ctaUrl:a,theme:t="light"})=>e("div",{className:"qr-prepaid-nudge"+("dark"===t?" qr-prepaid-nudge--dark":""),role:"complementary","aria-label":"Prepaid offer",children:[r("p",{className:"qr-prepaid-nudge__copy",children:n}),a?r("a",{href:a,className:"qr-btn qr-btn--primary qr-btn--sm qr-prepaid-nudge__cta",target:"_blank",rel:"noopener noreferrer",children:"Pay online instead"}):null]}),de="https://checkout.razorpay.com/v1/checkout.js",ce=({checkoutConfig:n,sessionToken:a,sessionId:i,amountPaise:o,enableCod:l=!1,codAllowed:d=!1,theme:c="light",onComplete:u,onBack:h,onEvent:p})=>{const[m,f]=t(!1),[y,b]=t(null),v="dark"===c
197
+ default:return"COD is not available."}}(r.reason):void 0),u("ready")}catch{e||(u("error"),p(!1),f("Could not verify COD. Try again."))}})(),()=>{e=!0}},[n,a,i,o]),e("div",{className:"qr-cod-banner"+("dark"===l?" qr-cod-banner--dark":""),role:"status","aria-live":"polite",children:[r("div",{className:"qr-cod-banner__title",children:"Cash on Delivery"}),"loading"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:"Checking availability…"}),"error"===c&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--warn",children:m}),"ready"===c&&h&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",children:"Available for this address."}),"ready"===c&&!h&&m&&r("p",{className:"qr-cod-banner__text qr-cod-banner__text--muted",children:m})]})},ue=({copy:n,ctaUrl:a,theme:t="light"})=>e("div",{className:"qr-prepaid-nudge"+("dark"===t?" qr-prepaid-nudge--dark":""),role:"complementary","aria-label":"Prepaid offer",children:[r("p",{className:"qr-prepaid-nudge__copy",children:n}),a?r("a",{href:a,className:"qr-btn qr-btn--primary qr-btn--sm qr-prepaid-nudge__cta",target:"_blank",rel:"noopener noreferrer",children:"Pay online instead"}):null]}),he="https://checkout.razorpay.com/v1/checkout.js",pe=({checkoutConfig:n,sessionToken:a,sessionId:i,amountPaise:o,enableCod:l=!1,codAllowed:d=!1,theme:c="light",onComplete:u,onBack:h,onEvent:p})=>{const[m,f]=t(!1),[y,b]=t(null),v="dark"===c
196
198
  s(()=>{null==p||p("payment_step_viewed")},[p])
197
199
  const _=`₹${(o/100).toLocaleString("en-IN")}`
198
200
  return e("div",{className:"qr-payment-step"+(v?" qr-payment-step--dark":""),children:[h?r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:h,disabled:m,children:"← Back"}):null,r("h3",{className:"qr-auth-step__title",children:"Choose payment"}),e("p",{className:"qr-auth-step__sub",children:["Order total: ",r("strong",{children:_})]}),y?r("p",{className:"qr-auth-step__error",role:"alert",children:y}):null,r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:async()=>{f(!0),b(null)
199
- try{await(window.Razorpay?Promise.resolve():new Promise((e,r)=>{const n=document.querySelector(`script[src="${de}"]`)
201
+ try{await(window.Razorpay?Promise.resolve():new Promise((e,r)=>{const n=document.querySelector(`script[src="${he}"]`)
200
202
  if(n)return void n.addEventListener("load",()=>e())
201
203
  const a=document.createElement("script")
202
- a.src=de,a.async=!0,a.onload=()=>e(),a.onerror=()=>r(new Error("Failed to load Razorpay")),document.body.appendChild(a)}))
203
- const e=await K(n,a,o)
204
- await new Promise((r,t)=>{window.Razorpay?new window.Razorpay({key:e.razorpay_key_id,amount:e.amount_paise,currency:e.currency,order_id:e.razorpay_order_id,name:"Checkout",handler:async e=>{try{const t=await G(n,a,{razorpay_order_id:e.razorpay_order_id,razorpay_payment_id:e.razorpay_payment_id,razorpay_signature:e.razorpay_signature,payment_method:"prepaid"})
204
+ a.src=he,a.async=!0,a.onload=()=>e(),a.onerror=()=>r(new Error("Failed to load Razorpay")),document.body.appendChild(a)}))
205
+ const e=await Q(n,a,o)
206
+ await new Promise((r,t)=>{window.Razorpay?new window.Razorpay({key:e.razorpay_key_id,amount:e.amount_paise,currency:e.currency,order_id:e.razorpay_order_id,name:"Checkout",handler:async e=>{try{const t=await Z(n,a,{razorpay_order_id:e.razorpay_order_id,razorpay_payment_id:e.razorpay_payment_id,razorpay_signature:e.razorpay_signature,payment_method:"prepaid"})
205
207
  null==p||p("payment_method_selected",t.payment_method),u(t.payment_method),r()}catch(e){t(e)}},modal:{ondismiss:()=>t(new Error("Payment cancelled"))}}).open():t(new Error("Razorpay unavailable"))})}catch(e){b(e instanceof Error?e.message:"Payment failed")}finally{f(!1)}},disabled:m,children:m?"Processing…":`Pay ${_} online`}),l&&d?r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--full",onClick:async()=>{f(!0),b(null)
206
- try{const e=await Z(n,a)
207
- null==p||p("payment_method_selected",e.payment_method),u(e.payment_method)}catch(e){b(e instanceof Error?e.message:"Failed to select COD")}finally{f(!1)}},disabled:m,style:{marginTop:8},children:"Cash on Delivery"}):null,i?e("p",{className:"qr-payment-step__meta",children:["Session ",i.slice(0,8),"…"]}):null]})},ue=({onOtpSent:a,onSkip:l,functionBaseUrl:s,merchantId:d})=>{const[c,u]=t(""),[h,p]=t(!1),[m,f]=t(null),y=o(null),b=i(e=>{u(e.target.value.trim()),f(null)},[]),v=i(async e=>{var r
208
+ try{const e=await X(n,a)
209
+ null==p||p("payment_method_selected",e.payment_method),u(e.payment_method)}catch(e){b(e instanceof Error?e.message:"Failed to select COD")}finally{f(!1)}},disabled:m,style:{marginTop:8},children:"Cash on Delivery"}):null,i?e("p",{className:"qr-payment-step__meta",children:["Session ",i.slice(0,8),"…"]}):null]})},me=({onOtpSent:a,onSkip:l,functionBaseUrl:s,merchantId:d})=>{const[c,u]=t(""),[h,p]=t(!1),[m,f]=t(null),y=o(null),b=i(e=>{u(e.target.value.trim()),f(null)},[]),v=i(async e=>{var r
208
210
  if(e.preventDefault(),!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c))return f("Enter a valid email address."),void(null==(r=y.current)||r.focus())
209
211
  p(!0),f(null)
210
- try{const{reused:e}=await j({functionBaseUrl:s,merchantId:d},c)
212
+ try{const{reused:e}=await J({functionBaseUrl:s,merchantId:d},c)
211
213
  a(c.toLowerCase(),{reused:e})}catch(e){f(e instanceof Error?e.message:"Failed to send code. Please try again.")}finally{p(!1)}},[c,s,d,a])
212
214
  return e("div",{className:"qr-auth-step",children:[r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-auth-step__title",children:"Faster checkout"}),r("p",{className:"qr-auth-step__sub",children:"Enter your email to load saved addresses"}),e("form",{onSubmit:v,noValidate:!0,children:[r("div",{className:"qr-email-field"+(m?" qr-email-field--error":""),children:r("input",{ref:y,type:"email",inputMode:"email",className:"qr-email-field__input",placeholder:"you@example.com",value:c,onChange:b,autoComplete:"email","aria-label":"Email address","aria-describedby":m?"qr-email-error":void 0,"aria-invalid":!!m,disabled:h})}),m&&r("p",{id:"qr-email-error",className:"qr-auth-step__error",role:"alert",children:m}),r("button",{type:"submit",className:"qr-btn qr-btn--primary qr-btn--full",disabled:h||c.length<5,children:h?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):e(n,{children:["Send Code",r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M5 12h14M12 5l7 7-7 7"})})]})})]}),r("button",{type:"button",className:"qr-auth-step__skip",onClick:l,disabled:h,children:"Skip, enter address manually"})]})}
213
- function he(e){const[r,n]=e.split("@")
214
- return!n||r.length<=1?e:`${r[0]}***@${n}`}const pe=({email:a,codeReused:l=!1,onVerified:d,onBack:c,functionBaseUrl:u,merchantId:h,sessionContext:p})=>{const[m,f]=t(Array(6).fill("")),[y,b]=t(!1),[v,_]=t(null),[g,q]=t(60),[w,N]=t(!1),k=o([]),C=o(null)
215
+ function fe(e){const[r,n]=e.split("@")
216
+ return!n||r.length<=1?e:`${r[0]}***@${n}`}const ye=({email:a,codeReused:l=!1,onVerified:d,onBack:c,functionBaseUrl:u,merchantId:h,sessionContext:p})=>{const[m,f]=t(Array(6).fill("")),[y,b]=t(!1),[v,_]=t(null),[g,q]=t(60),[w,N]=t(!1),k=o([]),C=o(null)
215
217
  s(()=>(C.current=setInterval(()=>{q(e=>e<=1?(clearInterval(C.current),0):e-1)},1e3),()=>{C.current&&clearInterval(C.current)}),[])
216
218
  const x=e=>{var r
217
219
  return null==(r=k.current[e])?void 0:r.focus()},E=i((e,r)=>{const n=r.replace(/\D/g,"").slice(-1)
@@ -223,38 +225,38 @@ const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6)
223
225
  if(!r)return
224
226
  const n=Array(6).fill("")
225
227
  r.split("").forEach((e,r)=>{n[r]=e}),f(n),_(null),x(Math.min(r.length,5))},[]),I=m.join(""),P=6===I.length&&!m.includes(""),T=i(async()=>{if(P){b(!0),_(null)
226
- try{const e=await W({functionBaseUrl:u,merchantId:h},a,I,p)
228
+ try{const e=await V({functionBaseUrl:u,merchantId:h},a,I,p)
227
229
  d(e.session_token,e.buyer_id,e.session_id)}catch(e){_(e instanceof Error?e.message:"Verification failed. Please try again."),f(Array(6).fill("")),x(0)}finally{b(!1)}}},[P,I,a,u,h,d,p])
228
230
  s(()=>{P&&!y&&T()},[P])
229
231
  const A=i(async()=>{if(!(g>0||w)){N(!0),_(null),f(Array(6).fill(""))
230
- try{await j({functionBaseUrl:u,merchantId:h},a),q(60),C.current=setInterval(()=>{q(e=>e<=1?(clearInterval(C.current),0):e-1)},1e3),x(0)}catch(e){_(e instanceof Error?e.message:"Failed to resend code.")}finally{N(!1)}}},[g,w,u,h,a])
231
- return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:c,disabled:y,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-auth-step__title",children:"Check your email"}),r("p",{className:"qr-auth-step__sub",children:l?r(n,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):e(n,{children:["6-digit code sent to ",r("strong",{children:he(a)})]})}),r("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter verification code",children:m.map((e,n)=>r("input",{ref:e=>{k.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${v?" qr-otp-box--error":""}`,value:e,onChange:e=>E(n,e.target.value),onKeyDown:e=>S(n,e),onPaste:L,onFocus:e=>e.target.select(),"aria-label":`Code digit ${n+1}`,disabled:y,autoComplete:0===n?"one-time-code":"off"},n))}),v&&r("p",{className:"qr-auth-step__error",role:"alert",children:v}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:T,disabled:!P||y,children:y?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify Code"}),r("p",{className:"qr-auth-step__resend",children:g>0?e("span",{children:["Resend code in ",g,"s"]}):r("button",{type:"button",className:"qr-link-btn",onClick:A,disabled:w,children:w?"Sending…":"Resend Code"})})]})}
232
- function me(e){if("undefined"!=typeof window){const e=window.innerWidth
232
+ try{await J({functionBaseUrl:u,merchantId:h},a),q(60),C.current=setInterval(()=>{q(e=>e<=1?(clearInterval(C.current),0):e-1)},1e3),x(0)}catch(e){_(e instanceof Error?e.message:"Failed to resend code.")}finally{N(!1)}}},[g,w,u,h,a])
233
+ return e("div",{className:"qr-auth-step",children:[r("button",{type:"button",className:"qr-back-btn qr-back-btn--auth",onClick:c,disabled:y,children:r("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:r("path",{d:"M19 12H5M12 5l-7 7 7 7"})})}),r("div",{className:"qr-auth-step__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"24",cy:"24",r:"24",fill:"var(--qr-primary-light)"}),r("rect",{x:"11",y:"15",width:"26",height:"18",rx:"3",stroke:"var(--qr-primary)",strokeWidth:"1.8",fill:"none"}),r("path",{d:"M11 18l13 9 13-9",stroke:"var(--qr-primary)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-auth-step__title",children:"Check your email"}),r("p",{className:"qr-auth-step__sub",children:l?r(n,{children:"Use the code we sent earlier — it's still valid for your next checkout."}):e(n,{children:["6-digit code sent to ",r("strong",{children:fe(a)})]})}),r("div",{className:"qr-otp-boxes",role:"group","aria-label":"Enter verification code",children:m.map((e,n)=>r("input",{ref:e=>{k.current[n]=e},type:"text",inputMode:"numeric",maxLength:1,className:`qr-otp-box${e?" qr-otp-box--filled":""}${v?" qr-otp-box--error":""}`,value:e,onChange:e=>E(n,e.target.value),onKeyDown:e=>S(n,e),onPaste:L,onFocus:e=>e.target.select(),"aria-label":`Code digit ${n+1}`,disabled:y,autoComplete:0===n?"one-time-code":"off"},n))}),v&&r("p",{className:"qr-auth-step__error",role:"alert",children:v}),r("button",{type:"button",className:"qr-btn qr-btn--primary qr-btn--full",onClick:T,disabled:!P||y,children:y?r("span",{className:"qr-spinner qr-spinner--sm","aria-hidden":"true"}):"Verify Code"}),r("p",{className:"qr-auth-step__resend",children:g>0?e("span",{children:["Resend code in ",g,"s"]}):r("button",{type:"button",className:"qr-link-btn",onClick:A,disabled:w,children:w?"Sending…":"Resend Code"})})]})}
234
+ function be(e){if("undefined"!=typeof window){const e=window.innerWidth
233
235
  return e<768?"mobile":e<1024?"tablet":"desktop"}const r=(e??"").toLowerCase()
234
- return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function fe(){return"web"}function ye(){const e=function(){if("undefined"!=typeof navigator&&navigator.userAgent)return navigator.userAgent.slice(0,512)}()
235
- return{deviceType:me(e),platform:"web",userAgent:e}}const be=["utm_source","utm_medium","utm_campaign"]
236
- function ve(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
237
- for(const e of be){const a=r.searchParams.get(e)
238
- a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function _e(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const ge=({address:n,onEditAddress:a})=>e("div",{className:"qr-success",children:[r("div",{className:"qr-success__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 52 52",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"26",cy:"26",r:"26",fill:"var(--qr-success, #10b981)",opacity:"0.12"}),r("circle",{cx:"26",cy:"26",r:"20",fill:"var(--qr-success, #10b981)"}),r("path",{d:"M15 26l8 8 14-16",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-success__title",children:"Address Saved!"}),r("p",{className:"qr-success__address",children:n.formattedAddress}),r("div",{className:"qr-success__meta",children:e("span",{className:"qr-digipin-badge qr-digipin-badge--inline",children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:n.digipin})]})}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--sm",onClick:a,children:"Change Address"})]}),qe=({apiKey:l,apiBaseUrl:d="https://api.quantaroute.com",onComplete:u,onError:h,defaultLat:p,defaultLng:m,theme:f="light",className:y="",style:b,mapHeight:v="380px",title:_="Add Delivery Address",indiaBoundaryUrl:g,enableSearch:q=!0,enablePhoneAuth:w=!1,merchantId:N="",supabaseFunctionBaseUrl:k="",brandColor:C,logoUrl:x,headerBanner:E,onCheckoutEvent:S,enableCod:L=!1,codCartTotalPaise:P,codSessionToken:T="",enableEmailAuth:B=!1,variant:D,utmParams:M,enablePayment:O=!1,paymentAmountPaise:U,onPaymentComplete:F,enablePrepaidNudge:j=!1,prepaidNudgeCopy:W,prepaidNudgeCtaUrl:J})=>{const K=w?"phone":B?"email":"none",G="phone"===K?"phone":"email"===K?"email":"map",Z=Boolean(O&&U&&k),[Y,X]=t(G),[re,ne]=t(null),[ae,te]=t(null),[ie,de]=t(null),[he,me]=t(""),[fe,be]=t(!1),[_e,qe]=t(!1),[we,Ne]=t(null),[ke,Ce]=t(null),xe=o(Y),Ee=c(()=>M??ve(),[M]),Se=c(()=>ye(),[]),Le=c(()=>({utm_source:Ee.utm_source,utm_medium:Ee.utm_medium,utm_campaign:Ee.utm_campaign,device_type:Se.deviceType,platform:Se.platform,user_agent:Se.userAgent,experiment_variant:D}),[Ee,Se,D]),Ie={functionBaseUrl:k,merchantId:N},Pe=(null==ie?void 0:ie.sessionToken)||T
239
- s(()=>{xe.current=Y},[Y])
240
- const Te=i(e=>{const r={...e,sessionId:e.sessionId??(null==ie?void 0:ie.sessionId),buyerId:e.buyerId??(null==ie?void 0:ie.buyerId),authChannel:e.authChannel??("phone"===K?"phone":"email"===K?"email":"none"),deviceType:e.deviceType??Se.deviceType,platform:e.platform??Se.platform,userAgent:e.userAgent??Se.userAgent,experimentVariant:e.experimentVariant??D,timestamp:(new Date).toISOString()}
241
- if(S)try{S(r)}catch{}N&&k&&z(Ie,{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==ie?void 0:ie.sessionToken).catch(()=>{})},[ie,K,Se,D,S,N,k,Ie])
236
+ return/ipad|tablet/.test(r)?"tablet":/mobile|iphone|android/.test(r)?"mobile":"desktop"}function ve(){return"web"}function _e(){const e=function(){if("undefined"!=typeof navigator&&navigator.userAgent)return navigator.userAgent.slice(0,512)}()
237
+ return{deviceType:be(e),platform:"web",userAgent:e}}const ge=["utm_source","utm_medium","utm_campaign"]
238
+ function qe(e){try{const r=new URL(e??("undefined"!=typeof window?window.location.href:"")),n={}
239
+ for(const e of ge){const a=r.searchParams.get(e)
240
+ a&&(n[e]=a.slice(0,256))}return n}catch{return{}}}function we(e){return Boolean(e.utm_source||e.utm_medium||e.utm_campaign)}const Ne=({address:n,onEditAddress:a})=>e("div",{className:"qr-success",children:[r("div",{className:"qr-success__icon","aria-hidden":"true",children:e("svg",{viewBox:"0 0 52 52",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r("circle",{cx:"26",cy:"26",r:"26",fill:"var(--qr-success, #10b981)",opacity:"0.12"}),r("circle",{cx:"26",cy:"26",r:"20",fill:"var(--qr-success, #10b981)"}),r("path",{d:"M15 26l8 8 14-16",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r("h3",{className:"qr-success__title",children:"Address Saved!"}),r("p",{className:"qr-success__address",children:n.formattedAddress}),r("div",{className:"qr-success__meta",children:e("span",{className:"qr-digipin-badge qr-digipin-badge--inline",children:[r("span",{className:"qr-digipin-badge__label",children:"DigiPin"}),r("span",{className:"qr-digipin-badge__code",children:n.digipin})]})}),r("button",{type:"button",className:"qr-btn qr-btn--ghost qr-btn--sm",onClick:a,children:"Change Address"})]}),ke=({apiKey:l,apiBaseUrl:d="https://api.quantaroute.com",onComplete:u,onError:h,defaultLat:p,defaultLng:m,theme:f="light",className:y="",style:b,mapHeight:v="380px",title:_="Add Delivery Address",indiaBoundaryUrl:g,enableSearch:q=!0,enablePhoneAuth:w=!1,merchantId:N="",supabaseFunctionBaseUrl:k="",brandColor:C,logoUrl:x,headerBanner:E,onCheckoutEvent:S,enableCod:L=!1,codCartTotalPaise:I,codSessionToken:P="",enableEmailAuth:T=!1,variant:B,utmParams:$,enablePayment:O=!1,paymentAmountPaise:M,onPaymentComplete:U,enablePrepaidNudge:F=!1,prepaidNudgeCopy:j,prepaidNudgeCtaUrl:W,registerController:J})=>{const V=w?"phone":T?"email":"none",H="phone"===V?"phone":"email"===V?"email":"map",Q=Boolean(O&&M&&k),[Z,X]=t(H),[ee,ne]=t(null),[te,ie]=t(null),[oe,le]=t(null),[se,he]=t(""),[fe,be]=t(!1),[ve,ge]=t(!1),[we,ke]=t(null),[Ce,xe]=t(null),Ee=o(Z),Se=c(()=>$??qe(),[$]),Le=c(()=>_e(),[]),Ie=c(()=>({utm_source:Se.utm_source,utm_medium:Se.utm_medium,utm_campaign:Se.utm_campaign,device_type:Le.deviceType,platform:Le.platform,user_agent:Le.userAgent,experiment_variant:B}),[Se,Le,B]),Pe={functionBaseUrl:k,merchantId:N},Te=(null==oe?void 0:oe.sessionToken)||P
241
+ s(()=>{Ee.current=Z},[Z])
242
+ const Ae=i(e=>{const r={...e,sessionId:e.sessionId??(null==oe?void 0:oe.sessionId),buyerId:e.buyerId??(null==oe?void 0:oe.buyerId),authChannel:e.authChannel??("phone"===V?"phone":"email"===V?"email":"none"),deviceType:e.deviceType??Le.deviceType,platform:e.platform??Le.platform,userAgent:e.userAgent??Le.userAgent,experimentVariant:e.experimentVariant??B,timestamp:(new Date).toISOString()}
243
+ if(S)try{S(r)}catch{}N&&k&&G(Pe,{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==oe?void 0:oe.sessionToken).catch(()=>{})},[oe,V,Le,B,S,N,k,Pe])
242
244
  s(()=>{if(!N||!k)return
243
- const e=()=>{"done"!==xe.current&&(null==ie?void 0:ie.sessionToken)&&(V(Ie,ie.sessionToken,xe.current).catch(()=>{}),Te({type:"session_abandoned",step:xe.current}))}
244
- return window.addEventListener("pagehide",e),()=>window.removeEventListener("pagehide",e)},[null==ie?void 0:ie.sessionToken,N,k,Ie,Te]),s(()=>{(null==ie?void 0:ie.sessionToken)&&N&&k&&H(Ie,ie.sessionToken).then(Ne).catch(()=>Ne(null))},[null==ie?void 0:ie.sessionToken,N,k,Ie])
245
- const Ae=c(()=>function(e,r){const n=null==r?void 0:r.trim()
245
+ const e=()=>{"done"!==Ee.current&&(null==oe?void 0:oe.sessionToken)&&(K(Pe,oe.sessionToken,Ee.current).catch(()=>{}),Ae({type:"session_abandoned",step:Ee.current}))}
246
+ return window.addEventListener("pagehide",e),()=>window.removeEventListener("pagehide",e)},[null==oe?void 0:oe.sessionToken,N,k,Pe,Ae]),s(()=>{(null==oe?void 0:oe.sessionToken)&&N&&k&&Y(Pe,oe.sessionToken).then(ke).catch(()=>ke(null))},[null==oe?void 0:oe.sessionToken,N,k,Pe])
247
+ const Be=c(()=>function(e,r){const n=null==r?void 0:r.trim()
246
248
  if(!n)return e
247
249
  const a={"--qr-primary":n,"--qr-primary-dark":n,"--qr-border-focus":n,"--qr-primary-light":`color-mix(in srgb, ${n} 18%, white)`}
248
- return e?{...e,...a}:a}(b,C),[b,C]),Be=()=>{Te({type:"auth_skipped",step:"map"}),X("map")},De=async e=>{if(te(e),Te({type:"address_completed",step:Z?"payment":"done",digipin:e.digipin,buyerId:null==ie?void 0:ie.buyerId}),null==ie?void 0:ie.sessionToken){R(Ie,ie.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
249
- try{await $(Ie,ie.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&&Pe?X("payment"):(X("done"),u(e))}
250
- s(()=>{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"}[Y]
251
- e&&Te({type:e,step:Y,buyerId:null==ie?void 0:ie.buyerId})},[Y]),s(()=>{B&&"email"===K&&(N&&k||null==h||h(new Error("enableEmailAuth requires merchantId and supabaseFunctionBaseUrl on CheckoutWidget.")))},[B,K,N,k,h])
250
+ return e?{...e,...a}:a}(b,C),[b,C]),$e=()=>{Ae({type:"auth_skipped",step:"map"}),X("map")},De=async e=>{if(ie(e),Ae({type:"address_completed",step:Q?"payment":"done",digipin:e.digipin,buyerId:null==oe?void 0:oe.buyerId}),(null==oe?void 0:oe.sessionToken)&&(z(Pe,oe.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{}),!e.addressId))try{await R(Pe,oe.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:!1})}catch{}Q&&Te?X("payment"):(X("done"),u(e))},Oe=()=>"form"===Z?(X("map"),!0):"map"===Z&&(null==oe?void 0:oe.sessionToken)?(X("saved"),!0):"email-otp"===Z?(X("email"),!0):"otp"===Z?(X("phone"),!0):"payment"===Z&&(X("form"),!0)
251
+ s(()=>{J&&J({goBack:()=>{const e=Ee.current
252
+ return"form"===e?(X("map"),!0):"map"===e&&(null==oe?void 0:oe.sessionToken)?(X("saved"),!0):"email-otp"===e?(X("email"),!0):"otp"===e?(X("phone"),!0):"payment"===e&&(X("form"),!0)},getStep:()=>Ee.current})},[J,null==oe?void 0:oe.sessionToken]),s(()=>{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"}[Z]
253
+ e&&Ae({type:e,step:Z,buyerId:null==oe?void 0:oe.buyerId})},[Z]),s(()=>{T&&"email"===V&&(N&&k||null==h||h(new Error("enableEmailAuth requires merchantId and supabaseFunctionBaseUrl on CheckoutWidget.")))},[T,V,N,k,h])
252
254
  const Me=function(e,r,n){if("none"===r){if(n){const r=["map","form","payment","done"].indexOf(e)
253
255
  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)
254
- return-1===a?0:a}(Y,K,Z),Oe=function(e,r){return"none"===e?r?3:2:r?6:5}(K,Z)
255
- return e("div",{className:`qr-checkout qr-checkout--${f} ${y}`,style:Ae,"data-testid":"quantaroute-checkout",children:["done"!==Y&&e(n,{children:[e("div",{className:"qr-header",children:[e("div",{className:"qr-header__brand",children:[x?r("img",{src:x,alt:"",className:"qr-header__logo-img",width:28,height:28,decoding:"async"}):e("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("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r("circle",{cx:"12",cy:"10",r:"3"})]}),r("span",{className:"qr-header__title",children:_})]}),(()=>{const n=Array.from({length:Oe+1},(e,r)=>r)
256
- return r("div",{className:"qr-progress",role:"progressbar","aria-valuenow":Me+1,"aria-valuemin":1,"aria-valuemax":Oe+1,"aria-label":`Step ${Me+1} of ${Oe+1}`,children:n.map(n=>e(a.Fragment,{children:[r("div",{className:"qr-progress__dot"+(Me>=n?" qr-progress__dot--active":"")}),n<Oe&&r("div",{className:"qr-progress__line"+(Me>n?" qr-progress__line--active":"")})]},n))})})()]}),E?r("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:E}):null,we?e("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[we.banner_copy,we.banner_cta_url?e(n,{children:[" ",r("a",{href:we.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===Y&&B&&r(ue,{onOtpSent:(e,r)=>{me(e),be(Boolean(null==r?void 0:r.reused)),Te({type:"email_otp_sent",step:"email-otp",mobile:e}),X("email-otp")},onSkip:Be,functionBaseUrl:k,merchantId:N}),"email-otp"===Y&&B&&he&&r(pe,{email:he,codeReused:fe,onVerified:(e,r,n)=>{de({mobile:he,sessionToken:e,sessionId:n??"",buyerId:r}),Te({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),X("saved")},onBack:()=>X("email"),functionBaseUrl:k,merchantId:N,sessionContext:Le}),"phone"===Y&&w&&r(Q,{onOtpSent:e=>{de(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Te({type:"otp_sent",step:"otp",mobile:e}),X("otp")},onSkip:Be,functionBaseUrl:k,merchantId:N}),"otp"===Y&&ie&&r(ee,{mobile:ie.mobile,onVerified:(e,r,n)=>{de({mobile:(null==ie?void 0:ie.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Te({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),X("saved")},onBack:()=>X("phone"),functionBaseUrl:k,merchantId:N,sessionContext:Le}),"saved"===Y&&(null==ie?void 0:ie.sessionToken)&&r(oe,{sessionToken:ie.sessionToken,functionBaseUrl:k,merchantId:N,onSelectAddress:e=>{Te({type:"saved_address_selected",step:Z?"payment":"done",buyerId:null==ie?void 0:ie.buyerId,digipin:e.digipin}),(null==ie?void 0:ie.sessionToken)&&R(Ie,ie.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
257
- 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"}
258
- De(r)},onAddNew:()=>X("map")}),"map"===Y&&r(I,{onLocationConfirm:(e,r,n)=>{ne({lat:e,lng:r,digipin:n}),Te({type:"location_confirmed",step:"form",digipin:n,buyerId:null==ie?void 0:ie.buyerId}),X("form")},defaultLat:p,defaultLng:m,mapHeight:v,theme:f,indiaBoundaryUrl:g,enableSearch:q,apiKey:l,apiBaseUrl:d,brandColor:C}),"form"===Y&&re&&r(A,{digipin:re.digipin,lat:re.lat,lng:re.lng,apiKey:l,apiBaseUrl:d,onAddressComplete:async e=>{await De(e)},onBack:()=>{"form"===Y?X("map"):"map"===Y&&(null==ie?void 0:ie.sessionToken)?X("saved"):"email-otp"===Y&&X("email")},onError:h,theme:f}),"payment"===Y&&Z&&Pe&&U&&r(ce,{checkoutConfig:Ie,sessionToken:Pe,sessionId:null==ie?void 0:ie.sessionId,amountPaise:U,enableCod:L,codAllowed:_e,theme:f,onComplete:e=>{Ce(e),Te({type:"payment_method_selected",step:"done",paymentMethod:e}),X("done"),ae&&u(ae),null==F||F({paymentMethod:e,sessionId:null==ie?void 0:ie.sessionId})},onBack:()=>X("form"),onEvent:(e,r)=>Te({type:e,step:"payment",paymentMethod:r,buyerId:null==ie?void 0:ie.buyerId})}),"done"===Y&&ae&&e(n,{children:[r(ge,{address:ae,onEditAddress:()=>{Te({type:"widget_reset",step:G}),X(G),ne(null),te(null)}}),ke?e("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",style:{textAlign:"center",margin:"8px 16px"},children:["Paid via ","cod"===ke?"Cash on Delivery":"online payment"]}):null,L&&N&&k&&Pe?e(n,{children:[r(le,{checkoutConfig:Ie,sessionToken:Pe,pincode:ae.pincode,cartTotalPaise:P??U,theme:f,onCodAllowedChange:qe}),j&&_e?r(se,{copy:W??"Save more when you pay online — faster delivery & exclusive offers.",ctaUrl:J,theme:f}):null]}):null]}),e("div",{className:"qr-footer",children:[r("span",{children:"Powered by"}),r("a",{href:"https://quantaroute.com",target:"_blank",rel:"noopener noreferrer",className:"qr-footer__link",children:"QuantaRoute"}),r("span",{className:"qr-footer__flag","aria-label":"Made in India",children:"🇮🇳"})]})]})}
259
- function we(e,r){return c(()=>{if(!b(e,r))return null
260
- try{return m(e,r)}catch{return null}},[e,r])}export{A as AddressForm,qe as CheckoutWidget,le as CodAvailabilityBanner,p as DIGIPIN_BOUNDS,pe as EmailOtpStep,ue as EmailStep,I as MapPinSelector,ee as OtpStep,ce as PaymentStep,Q as PhoneStep,se as PrepaidNudge,oe as SavedAddressStep,C as autocompleteAddress,ve as captureUtmFromUrl,J as checkCodEligibility,$ as createAddress,K as createPaymentOrder,qe as default,U as deleteAddress,me as detectDeviceType,fe as detectPlatform,Y as fetchPrepaidNudgeConfig,H as fetchSessionOffer,m as getDigiPin,f as getLatLngFromDigiPin,ye as getWebDeviceContext,_e as hasUtmParams,y as isValidDigiPin,b as isWithinIndia,O as listAddresses,z as logFunnelEvent,k as looksLikeDigiPin,q as lookupLocation,R as notifyAddressCompleted,V as notifySessionAbandoned,N as pincodeHasDeliveryOffice,Z as recordCodPayment,x as reverseGeocode,j as sendEmailOtp,B as sendOtp,F as setDefaultAddress,we as useDigiPin,E as useGeolocation,w as validatePincode,W as verifyEmailOtp,D as verifyOtp,G as verifyPayment}
256
+ return-1===a?0:a}(Z,V,Q),Ue=function(e,r){return"none"===e?r?3:2:r?6:5}(V,Q)
257
+ return e("div",{className:`qr-checkout qr-checkout--${f} ${y}`,style:Be,"data-testid":"quantaroute-checkout",children:["done"!==Z&&e(n,{children:[e("div",{className:"qr-header",children:[e("div",{className:"qr-header__brand",children:[x?r("img",{src:x,alt:"",className:"qr-header__logo-img",width:28,height:28,decoding:"async"}):e("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("path",{d:"M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z"}),r("circle",{cx:"12",cy:"10",r:"3"})]}),r("span",{className:"qr-header__title",children:_})]}),(()=>{const n=Array.from({length:Ue+1},(e,r)=>r)
258
+ return r("div",{className:"qr-progress",role:"progressbar","aria-valuenow":Me+1,"aria-valuemin":1,"aria-valuemax":Ue+1,"aria-label":`Step ${Me+1} of ${Ue+1}`,children:n.map(n=>e(a.Fragment,{children:[r("div",{className:"qr-progress__dot"+(Me>=n?" qr-progress__dot--active":"")}),n<Ue&&r("div",{className:"qr-progress__line"+(Me>n?" qr-progress__line--active":"")})]},n))})})()]}),E?r("div",{className:"qr-header-banner",role:"region","aria-label":"Merchant message",children:E}):null,we?e("div",{className:"qr-offer-banner",role:"region","aria-label":"Special offer",children:[we.banner_copy,we.banner_cta_url?e(n,{children:[" ",r("a",{href:we.banner_cta_url,target:"_blank",rel:"noopener noreferrer",children:"Learn more"})]}):null]}):null]}),"email"===Z&&T&&r(me,{onOtpSent:(e,r)=>{he(e),be(Boolean(null==r?void 0:r.reused)),Ae({type:"email_otp_sent",step:"email-otp",mobile:e}),X("email-otp")},onSkip:$e,functionBaseUrl:k,merchantId:N}),"email-otp"===Z&&T&&se&&r(ye,{email:se,codeReused:fe,onVerified:(e,r,n)=>{le({mobile:se,sessionToken:e,sessionId:n??"",buyerId:r}),Ae({type:"email_verified",step:"saved",buyerId:r,sessionId:n}),X("saved")},onBack:Oe,functionBaseUrl:k,merchantId:N,sessionContext:Ie}),"phone"===Z&&w&&r(re,{onOtpSent:e=>{le(r=>({mobile:e,sessionToken:"",sessionId:"",buyerId:(null==r?void 0:r.buyerId)??""})),Ae({type:"otp_sent",step:"otp",mobile:e}),X("otp")},onSkip:$e,functionBaseUrl:k,merchantId:N}),"otp"===Z&&oe&&r(ae,{mobile:oe.mobile,onVerified:(e,r,n)=>{le({mobile:(null==oe?void 0:oe.mobile)??"",sessionToken:e,sessionId:n??"",buyerId:r}),Ae({type:"phone_verified",step:"saved",buyerId:r,sessionId:n}),X("saved")},onBack:Oe,functionBaseUrl:k,merchantId:N,sessionContext:Ie}),"saved"===Z&&(null==oe?void 0:oe.sessionToken)&&r(de,{sessionToken:oe.sessionToken,functionBaseUrl:k,merchantId:N,onSelectAddress:e=>{Ae({type:"saved_address_selected",step:Q?"payment":"done",buyerId:null==oe?void 0:oe.buyerId,digipin:e.digipin}),(null==oe?void 0:oe.sessionToken)&&z(Pe,oe.sessionToken,{pincode:e.pincode,digipin:e.digipin,state:e.state,district:e.district,locality:e.locality}).catch(()=>{})
259
+ 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",addressId:e.id}
260
+ De(r)},onAddNew:()=>X("map")}),"map"===Z&&r(A,{onLocationConfirm:(e,r,n)=>{ne({lat:e,lng:r,digipin:n}),Ae({type:"location_confirmed",step:"form",digipin:n,buyerId:null==oe?void 0:oe.buyerId}),X("form")},defaultLat:p,defaultLng:m,mapHeight:v,theme:f,indiaBoundaryUrl:g,enableSearch:q,apiKey:l,apiBaseUrl:d,brandColor:C}),"form"===Z&&ee&&r(D,{digipin:ee.digipin,lat:ee.lat,lng:ee.lng,apiKey:l,apiBaseUrl:d,onAddressComplete:async e=>{await De(e)},onBack:Oe,onError:h,theme:f}),"payment"===Z&&Q&&Te&&M&&r(pe,{checkoutConfig:Pe,sessionToken:Te,sessionId:null==oe?void 0:oe.sessionId,amountPaise:M,enableCod:L,codAllowed:ve,theme:f,onComplete:e=>{xe(e),Ae({type:"payment_method_selected",step:"done",paymentMethod:e}),X("done"),te&&u(te),null==U||U({paymentMethod:e,sessionId:null==oe?void 0:oe.sessionId})},onBack:Oe,onEvent:(e,r)=>Ae({type:e,step:"payment",paymentMethod:r,buyerId:null==oe?void 0:oe.buyerId})}),"done"===Z&&te&&e(n,{children:[r(Ne,{address:te,onEditAddress:()=>{Ae({type:"widget_reset",step:H}),X(H),ne(null),ie(null)}}),Ce?e("p",{className:"qr-cod-banner__text qr-cod-banner__text--ok",style:{textAlign:"center",margin:"8px 16px"},children:["Paid via ","cod"===Ce?"Cash on Delivery":"online payment"]}):null,L&&N&&k&&Te?e(n,{children:[r(ce,{checkoutConfig:Pe,sessionToken:Te,pincode:te.pincode,cartTotalPaise:I??M,theme:f,onCodAllowedChange:ge}),F&&ve?r(ue,{copy:j??"Save more when you pay online — faster delivery & exclusive offers.",ctaUrl:W,theme:f}):null]}):null]}),e("div",{className:"qr-footer",children:[r("span",{children:"Powered by"}),r("a",{href:"https://quantaroute.com",target:"_blank",rel:"noopener noreferrer",className:"qr-footer__link",children:"QuantaRoute"}),r("span",{className:"qr-footer__flag","aria-label":"Made in India",children:"🇮🇳"})]})]})}
261
+ function Ce(e,r){return c(()=>{if(!q(e,r))return null
262
+ try{return v(e,r)}catch{return null}},[e,r])}export{D as AddressForm,ke as CheckoutWidget,ce as CodAvailabilityBanner,p as DIGIPIN_BOUNDS,ye as EmailOtpStep,me as EmailStep,A as MapPinSelector,ae as OtpStep,pe as PaymentStep,re as PhoneStep,ue as PrepaidNudge,de as SavedAddressStep,S as autocompleteAddress,qe as captureUtmFromUrl,H as checkCodEligibility,R as createAddress,Q as createPaymentOrder,ke as default,j as deleteAddress,be as detectDeviceType,ve as detectPlatform,ee as fetchPrepaidNudgeConfig,Y as fetchSessionOffer,y as formatDigiPin,v as getDigiPin,_ as getLatLngFromDigiPin,_e as getWebDeviceContext,we as hasUtmParams,b as isCompleteDigiPinInput,g as isValidDigiPin,q as isWithinIndia,F as listAddresses,G as logFunnelEvent,E as looksLikeDigiPin,k as lookupLocation,f as normalizeDigiPinInput,z as notifyAddressCompleted,K as notifySessionAbandoned,x as pincodeHasDeliveryOffice,X as recordCodPayment,L as reverseGeocode,J as sendEmailOtp,O as sendOtp,W as setDefaultAddress,Ce as useDigiPin,I as useGeolocation,C as validatePincode,V as verifyEmailOtp,M as verifyOtp,Z as verifyPayment}