1import{T as e,s as t,u as n,m as s}from"./2c1ab0fe.GMbxnz74.js";import{aS as i,S as o,an as r,cE as a}from"./4c290a1e.C6TDJ9Fn.js";import{p as c,M as d,P as l}from"./7ee73f43.BDuSjxVB.js";import{cR as u,cS as p}from"./164ad2e3.BbIvMjRY.js";import{c as h,a as m,m as g,b as v,g as f,d as b,e as k,f as y,u as _,h as w,i as M,j as E,k as L,C,l as S,n as x,o as A}from"./2a0f03e4.C7RPc5cd.js";import{p as I}from"./5fda1420.KYpufQ--.js";import{i as P}from"./0a7dffce.DfUtZWCu.js";import"./app.CepNJbvh.js";import"./9f047e05.CCJUgz_L.js";import"./60a453ce.CkhHeRBc.js";import"./21cc90a2.DAzJmttM.js";import"./bb728e1c.iawBHR84.js";import"./05a2a9c8.BOU7FMWw.js";class D{constructor(e){this.customEventNamespace="MobileCheckoutSdk",this.#e=new Map,this.#t=new Map,this.#n=e}#n;#e;#t;postMessageToConsumer(e){return I(this.#n,e)}addEventListener(e,t){window.addEventListener(`${this.customEventNamespace}.${e}`,t,!1);let n=this.#e.get(e);null==n&&(n=new Set,this.#e.set(e,n)),n.add(t);const s=this.#t.get(e);if(s?.length){this.#t.delete(e),this.#n.log("mobile_checkout_sdk_client_message_replayed",`Replaying ${s.length} buffered '${e}' message(s) on first listener attach.`,{messageKey:e,queueDepth:s.length});for(const t of s)window.dispatchEvent(new CustomEvent(`${this.customEventNamespace}.${e}`,t))}}removeEventListener(e,t){window.removeEventListener(`${this.customEventNamespace}.${e}`,t);const n=this.#e.get(e);null!=n&&(n.delete(t),0===n.size&&this.#e.delete(e))}postMessage(e,t){const n=`${this.customEventNamespace}.${e}`;if(0===(this.#e.get(e)?.size??0)){const n=this.#t.get(e)??[];return n.length>=50&&(n.shift(),this.#n.log("mobile_checkout_sdk_client_message_buffer_overflow",`Inbound message buffer for '${e}' exceeded 50 entries; dropping oldest.`,{messageKey:e,cap:50})),n.push(t),this.#t.set(e,n),void this.#n.log("mobile_checkout_sdk_client_message_buffered",`Buffered '${e}' message â no listener attached yet.`,{messageKey:e,queueDepth:n.length})}window.dispatchEvent(new CustomEvent(n,t))}dispatchMessage(e,t){this.postMessage(e,t)}}function j(){return i(u)}const T=({children:t,version:n,mapDefaults:s,eventListenersHook:i,eventMessageMapper:r})=>{const{client:a}=j(),d=i(),{observability:l}=o();return t(e(()=>{const e=e=>{if(a){const t=r(e);t?(l.log("mobile_checkout_sdk_message_posted","MobileCheckoutSdkVersionedSchemaContext - sending post message to client",{handlerId:t.handlerId,post_message_body:t.body}),c(a,t)):l.log("mobile_checkout_sdk_message_posted",`MobileCheckoutSdkVersionedSchemaContext - failed to map event ${e.type}`,{event:e})}};return{schema:{version:n,eventMessageMapper:r,eventListeners:d,defaultsMapper:t=>s(t,e),postMessageHandler:e}}},[d,n,r,a,s,l]))};function $(e){if(e&&0!==e.lines.length)return e.lines.reduce((e,t)=>{if(!P(t))return e;const n=t.amount;return n?{amount:e.amount+n.amount,currencyCode:n.currencyCode}:e},{amount:0,currencyCode:""})}function R({total:e,subtotal:t,taxes:n,discountLines:s,shipping:i}){return{total:e,subtotal:t,taxes:m(n),discounts:$(s),shipping:h(i)}}function V(e){return{image:e.image?g(e.image):void 0,quantity:e.quantity,title:e.title,price:e.totalPrice,merchandiseId:e.variantId,productId:e.productId}}function H({flowType:e,negotiated:t,receipt:n}){const s=N(t,n),{confirmationPage:i,purchaseOrder:{email:o,phone:r,shippingAddress:a,billingAddress:c,paymentLines:d},orderIdentity:{id:l}}=n,u=i.url;return{flowType:e,confirmationURL:u,orderDetails:{id:l,cart:s,email:o,phone:r,shippingAddress:a,billingAddress:c,paymentMethods:b(d),deliveries:v(f(t,n).delivery,a)},thankYouPageUrl:u,orderId:l,cart:s}}function N(e,t){const n=f(e,t);return{lines:n.merchandiseLines?.lines?.map(V)??[],price:R({total:n.total,subtotal:n.subtotal,taxes:n.taxes,discountLines:n.discountLines,shipping:n.delivery})}}function B({flowType:e,negotiated:t,receipt:n}){const s=N(t,n),{confirmationPage:i,purchaseOrder:{email:o,shippingAddress:r,billingAddress:a,paymentLines:c},orderIdentity:{id:d}}=n,l=i.url;return{flowType:e,confirmationURL:l,orderDetails:{id:d,cart:s,email:o||"",shippingAddress:r,billingAddress:a,paymentMethods:b(c)},thankYouPageUrl:l,orderId:d,cart:s}}function U(e){const t={preloading:"false"};
1if(e&&"object"==typeof e&&!(e instanceof Map)){const n=e;"preloading"in n&&"string"==typeof n.preloading&&(t.preloading=n.preloading)}return t}function O(){const{observability:n,mobileCheckoutSdk:s}=o(),{config:i}=s,r=t(e=>{const t=function(){const e=window.navigator.userAgent;return/iPhone|iOS/i.test(e)?"ios":/iPad/i.test(e)?"ipad":/Android/i.test(e)?"android":"unknown"}(),s={...U(e.detail.tags),os_platform:t,checkoutVariant:i.variant??"",schemaVersion:i.schema??"",sdkVersion:i.version??""};"histogram"!==e.detail?.type||"checkout_finished_loading"!==e.detail?.name||isNaN(e.detail?.value)?n.log("checkout_sheet_kit_invalid_instrumentation_event_received",'An "instrumentation" event was sent to checkout with invalid data.',{event:e,os_platform:t,config:i}):n.histogram({name:"csk_finished_loading",value:e.detail.value,attributes:s})},[n,i]);return e(()=>({messageKey:"instrumentation",handler:r}),[r])}function q(e){if(e)return e.lines.reduce((e,t)=>{const n=t,s=n.amount;return n&&s?(e.push(function(e,t){const n=e.value;let s,i;switch(n?.typename){case"PercentageValue":s="percentage",i=n.percentage;break;case"FixedAmountValue":s="fixedAmount",i=n.fixedAmount.amount;break;default:s=void 0,i=void 0}return{title:e.title,amount:t,valueType:s,value:i,applicationType:e.type}}(n.discount,s)),e):e},[])}function K({flowType:e,cartToken:t,negotiated:n,receipt:s}){const{confirmationPage:i,purchaseOrder:{email:o,phone:r,shippingAddress:a,billingAddress:c,paymentLines:d},orderIdentity:{id:l}}=s,u=f(n,s),p=function({total:e,subtotal:t,taxes:n,discountLines:s,shipping:i}){return{total:e,subtotal:t,taxes:m(n),discounts:q(s),shipping:h(i)}}({total:u.total,subtotal:u.subtotal,taxes:u.taxes,discountLines:u.discountLines,shipping:u.delivery}),g=w(t,u.merchandiseLines,p),k=i.url;return{flowType:e,confirmationURL:k,orderDetails:{id:l,cart:g,email:o,phone:r,shippingAddress:a,billingAddress:c,paymentMethods:b(d),deliveries:v(u.delivery,a)},thankYouPageUrl:k,orderId:l,cart:g}}function Y(e){return{handlerId:"completed",body:{...K(e)}}}class z extends Error{constructor(){super(...arguments),this.name="CheckoutSdkSchemaVersionError"}}const F={5.1:{mapDefaults:S,eventListenersHook:function(){return{}},eventMessageMapper:function(e){switch(e.type){case"completed":return function(e){return{handlerId:"completed",body:{flowType:e.flowType,cart:N(e.negotiated,e.receipt),...(t=e.receipt,{orderId:t.orderIdentity.id,thankYouPageUrl:t.confirmationPage.url})}};var t}(e);case"checkoutBlockingEvent":return k(e)}}},5.3:{mapDefaults:S,eventListenersHook:function(){return{}},eventMessageMapper:function(e){switch(e.type){case"completed":return function(e){return{handlerId:"completed",body:{...B(e)}}}(e);case"checkoutBlockingEvent":return k(e)}}},"7.0":{mapDefaults:S,eventListenersHook:function(){const t=_(),n=O();return e(()=>({instrumentation:n,presented:t}),[n,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return function(e){return{handlerId:"completed",body:{...H(e)}}}(e);case"checkoutBlockingEvent":return k(e);case"webPixels":return y(e)}}},"8.0":{mapDefaults:S,eventListenersHook:function(){const t=_(),n=O();return e(()=>({instrumentation:n,presented:t}),[n,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return Y(e);case"checkoutBlockingEvent":return k(e);case"webPixels":return y(e)}}},8.1:{mapDefaults:S,eventListenersHook:function(){const t=_(),n=O();return e(()=>({instrumentation:n,presented:t}),[n,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return Y(e);case"checkoutBlockingEvent":return k(e);case"webPixels":return y(e);case"expired":return L(e);case"configuration":return E(e);case"unrecoverable":return M(e)}}}},W=({children:e})=>{const{schemaVersion:t}=j(),{observability:s}=o(),i=function(e,t){return e&&r.has(e)?e:(t?.error(new z(`Invalid checkout SDK schema version requested: ${e}. Using latest schema version: ${a}`)),a)}(t,s);return n(G,{version:i,children:t=>n(d.Provider,{value:t,children:[n(C,{}),e]})})},G=({children:e,version:t})=>{const{mapDefaults:s,eventListenersHook:i,eventMessageMapper:o}=F[t];return n(T,{version:t,mapDefaults:s,eventListenersHook:i,eventMessageMapper:o,children:e})},J=({children:t})=>{const{observability:i,mobileCheckoutSdk:r}=o(),a=e(()=>new D(i),[i]),c=p();s(()=>{r.enabled&&r.config.variant&&i?.addErrorMetadata("mobileCheckoutSdk",{variant:r.config.variant,version:r.config.version,schemaVersion:r.config.schema})},[i,r]),s(()=>
1{if(!r.variant.recovery)return r.enabled&&!window.MobileCheckoutSdk&&(i.log("mobile_checkout_sdk_provider_bridge_set","MobileCheckoutSdkProvider - setting window.MobileCheckoutSdk and emitting ready event"),window.MobileCheckoutSdk=a,window.dispatchEvent(new Event("mobileCheckoutBridgeReady")),window.addEventListener("click",x)),()=>{i.log("mobile_checkout_sdk_provider_bridge_deleted","MobileCheckoutSdkProvider - deleting window.MobileCheckoutSdk"),delete window.MobileCheckoutSdk,window.removeEventListener("click",x)};i.log("mobile_checkout_sdk_recovery_bridge_setup_skipped","MobileCheckoutSdkProvider - recovery mode, skipping setup")},[a,r,i]),r.config.type="MERCHANT",r.config.pixelEventsMode="STANDARD_RECOVERY"===r.config.variant?"DISABLED":"FORWARD_TO_CLIENT";const d=e(()=>({client:r.enabled?a:null,schemaVersion:r.config.schema||void 0,config:r.config}),[r,a]);return i.log("mobile_checkout_sdk_provider_context_value_computed","MobileCheckoutSdkProvider - computed context value",d),A(r.enabled,c),n(u.Provider,{value:d,children:n(l,{children:r.enabled&&!r.variant.recovery?n(W,{children:t}):t})})};export{J as MobileCheckoutSdkProvider};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.