1import{T as e,l as t,s as r,u as n,m as s}from"./2c1ab0fe.GMbxnz74.js";import{aS as o,d9 as a,cl as i,w as c,S as u,ao as l}from"./4c290a1e.C6TDJ9Fn.js";import{dy as d,bi as p,f as h,dz as m}from"./164ad2e3.BbIvMjRY.js";import{a as f}from"./5fda1420.KYpufQ--.js";import{p as g,u as y,C as v,P as b}from"./7ee73f43.BDuSjxVB.js";import{p as w,c as k,a as P,g as M,h as E,b as I,d as L,i as T,j as x,k as A,f as C,e as S,u as D,C as j,l as _,n as H,o as B}from"./2a0f03e4.C7RPc5cd.js";import{i as U}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 N{constructor(e){this.customEventNamespace="CheckoutSheetProtocolConsumer",this.#e=R.fromEnvironment(),this.#t=new WeakMap,this.#r=e}#r;#e;#t;postMessageToConsumer(e){return f(this.#r,e,this.#e)}addEventListener(e,t){const r=new AbortController,n=this.#t.get(t)??new Map;n.set(e,r),this.#t.set(t,n),this.#e?.addEventListener("message",r=>{r.data.name===e&&t(r)},{signal:r.signal}),window.addEventListener(`${this.customEventNamespace}.${e}`,t,{signal:r.signal})}removeEventListener(e,t){this.#t.get(t)?.get(e)?.abort()}postMessage(e,t){const r=new CustomEvent(`${this.customEventNamespace}.${e}`,t);window.dispatchEvent(r)}}class R{static fromEnvironment(){return window.opener?new R(window.opener):window.parent!==window?new R(window.parent):void 0}#n;constructor(e){this.#n=e}addEventListener(e,t,r){window.addEventListener("message",e=>{var r;e.source===this.#n&&null!=(r=e.data)&&"object"==typeof r&&"_ecp"in r&&"string"==typeof r._ecp&&t(e)},r)}postMessage(e){this.#n.postMessage({_ecp:"2025-10",data:e},"*")}}const $=({children:t,version:r,mapDefaults:n,eventListenersHook:s,eventMessageMapper:a})=>{const{client:i}=o(d),c=s();return t(e(()=>{const e=e=>{if(i){const t=a(e);t&&g(i,t)}};return{schema:{version:r,eventMessageMapper:a,eventListeners:c,defaultsMapper:t=>n(t,e),postMessageHandler:e}}},[c,r,a,i,n]))};function z(e){return{handlerId:"error",body:[{group:"authentication",code:e.status.toLowerCase(),reason:e.reason||void 0}]}}function K(e){if(e)return e.lines.reduce((e,t)=>{if(!t)return e;const r=function(e){if(U(e)){const t=e.amount;if(!t)return;const r=e.discount,n=r.value,{valueType:s,value:o}=w(n);return{title:r.title,amount:t,valueType:s,value:o,applicationType:r.type}}}(t);return r&&e.push(r),e},[])}function O({total:e,subtotal:t,taxes:r,taxesIncluded:n,discountLines:s,shipping:o}){return{total:e,subtotal:t,taxes:P(r),taxesIncluded:n,discounts:K(s),shipping:k(o)}}function W({flowType:e,cartToken:t,negotiated:r,receipt:n}){const{confirmationPage:s,purchaseOrder:{email:o,phone:a,shippingAddress:i,billingAddress:c,paymentLines:u},orderIdentity:{id:l}}=n,d=M(r,n),p=O({total:d.total,subtotal:d.subtotal,taxes:d.taxes,taxesIncluded:d.merchandiseLines?.taxesIncluded,discountLines:d.discountLines,shipping:d.delivery}),h=E(t,d.merchandiseLines,p),m=s.url;return{flowType:e,confirmationURL:m,orderDetails:{id:l,cart:h,email:o,phone:a,shippingAddress:i,billingAddress:c,paymentMethods:L(u),deliveries:I(d.delivery,i)},thankYouPageUrl:m,orderId:l,cart:h}}function Y(e){return{handlerId:"completed",body:W(e)}}function F(e){return{handlerId:e.type,body:{paymentUrl:e.paymentUrl}}}function G(e){const t=e.reasons?.map(t=>({type:"checkout_blocking",flowType:e.flowType,group:"checkout",reason:t}));return{handlerId:"error",body:t&&t.length>0?t:[{type:"checkout_blocking",flowType:e.flowType,group:"checkout"}]}}function V(e){return{handlerId:"locale",body:{locale:e.locale}}}function q(e){return{handlerId:"error",body:[{flowType:e.flowType,group:"checkout",...(t=e.receipt,{status:t.status,type:t.failure.type,reason:"payment"===t.failure.type?t.failure.code:void 0})}]};var t}const J={buyerInfo:["regular","checkoutDefaults"],billingAddress:["regular","payPal","shopPay"],paymentInfo:["checkoutDefaults"]};function Q(e){return{handlerId:"stateChange",body:{...function(e){const{deliveries:t,flowType:r}=e,n=t?.map(e=>("SHIPPING"===e.method&&!["regular","checkoutDefaults"].includes(r)&&e.details?.location&&(e.details.location=void 0),e));return{...e,deliveries:n}}(function({flowType:e,negotiated:t}){const{cartToken:r,contactInfo:n,acceptsMarketing:s,merchandiseLines:o,billingAddress:a,shippingAddress:i,total:c,subtotal:u,taxes:l,discountLines:d,delivery:p,selectedPaymentMethod:h}=t,m=O({total:c,subtotal:u,taxes:l,taxesIncluded:o?.taxesIncluded,discountLines:d,shipping:p}),f=function(e){return["shopPay","shopPayLogin","checkoutDefaults","applePay","googlePay","payPal","amazonPay","buyWithPrime","shopifyInstallments"].includes(e)?e:"regular"}(e),g=function(e){const t={acceptsMarketing:Boolean(e.acceptsMarketing)};return J.buyerInfo.includes(e.flowType)&&(t.email=e.contactInfo?.email||void 0,t.selectedShippingAddress=e.checkoutDefaultsSelectedShippingAddress),J.billingAddress.includes(e.flowType)&&e.billingAddress&&(t.selectedPaymentMethod={referenceId:"",cardType:"",lastFourDigits:"",expirationMonth:"",expirationYear:"",billingAddress:e.billingAddress}),J.paymentInfo.includes(e.flowType)&&(t.selectedPaymentMethod=e.checkoutDefaultsSelectedPaymentMethod),t}({flowType:f,contactInfo:n,billingAddress:a,acceptsMarketing:s,checkoutDefaultsSelectedShippingAddress:i,checkoutDefaultsSelectedPaymentMethod:h}),y=I(p,i);return{flowType:f,cart:E(r,o,m),buyer:g,deliveries:y}}(e))}}}function X(e){return{handlerId:"updateProgressButton",body:{state:e.state,stage:e.stage}}}function Z(e){return{handlerId:"error",body:e.violationErrors.map(t=>({flowType:e.flowType,group:t.group,type:t.type,code:t.code,reason:t.violation?.nonLocalizedMessage}))}}function ee(){const e=y(),n=a(),s=t(void 0),o=r(t=>{s.current=t.detail?.sessionId,e.emit()},[s,e]);return p(e=>{const t=s.current;"error"===e.type&&t&&window.mobileCheckoutSdkIdentity&&(n(),s.current=void 0)}),i(({parts:e,reason:t})=>{const r=s.current;if(!r||!window.mobileCheckoutSdkIdentity||function(e){return"progression"!==e&&"completion"!==e}(t))return{behavior:"allow"};const n=function(e){return e.paymentLines.peek().find(({method:{type:e}})=>"direct"===e)}(e);return n?{behavior:"allow",perform:()=>{e.paymentLines.value=c(e.paymentLines.peek(),function(e,t,r=!0){const{acceptedSubscriptionTerms:n,paymentMethodIdentifier:s}=t.method;return{method:{type:"direct",sessionId:e,acceptedSubscriptionTerms:n,paymentMethodIdentifier:s,cardSource:r?"SAVED_CREDIT_CARD":void 0}}}(r,n))}}:{behavior:"allow"}}
1),o}function te(){const t=ee(),{observability:r}=u();return e(()=>({messageKey:"submitPayment",handler:e=>{r.log("checkout_sheet_protocol_submit_payment_message_received","Handling submitPayment message."),t(e)}}),[t,r])}function re(e){return{handlerId:"error",body:[{group:"killswitch",reason:e.reason||void 0}]}}function ne(){const t=ee(),{observability:n}=u(),s=r(()=>{const e=document?.activeElement;e instanceof HTMLElement&&e.blur()},[]),o=r(async e=>{n.log("checkout_sheet_protocol_progress_message_received","Handling progress message."),s(),await Promise.resolve(),t(e)},[t,s,n]);return e(()=>({messageKey:"progress",handler:o}),[o])}function se(e){return{handlerId:"error",body:[{group:"authentication",code:e.error,reason:e.reason||void 0}]}}function oe(e){switch(e.type){case"completed":return Y(e);case"receiptError":return q(e);case"stateChange":return Q(e);case"init":return F(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authenticationError":return se(e);case"journeyProgressionError":return G(e);case"webPixels":return C(e);case"expired":return A(e);case"configuration":return x(e);case"unrecoverable":return T(e);case"locale":return V(e);case"killswitch":return re(e)}}function ae(){const t=D(),r=ne();return e(()=>({progress:r,presented:t}),[r,t])}function ie({flowType:e,cartToken:t,negotiated:r,receipt:n}){const{confirmationPage:s,purchaseOrder:{email:o,phone:a,shippingAddress:i,billingAddress:c,paymentLines:u},orderIdentity:{id:l}}=n,d=M(r,n),p=O({total:d.total,subtotal:d.subtotal,taxes:d.taxes,taxesIncluded:d.merchandiseLines?.taxesIncluded,discountLines:d.discountLines,shipping:d.delivery}),h=E(t,d.merchandiseLines,p);return{flowType:e,confirmationURL:s.url,orderDetails:{id:l,cart:h,email:o,phone:a,billingAddress:c,paymentMethods:L(u),deliveries:I(d.delivery,i)}}}function ce(e){return{handlerId:"completed",body:ie(e)}}const ue={"2024-04":{mapDefaults:_,eventListenersHook:function(){const t=D(),r=te();return e(()=>({submitPayment:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return Y(e);case"receiptError":return q(e);case"stateChange":return Q(e);case"init":return F(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authentication":return z(e);case"journeyProgressionError":return G(e);case"webPixels":return C(e);case"expired":return A(e);case"configuration":return x(e);case"unrecoverable":return T(e);case"locale":return V(e)}}},"2024-07":{mapDefaults:_,eventListenersHook:function(){const t=D(),r=te();return e(()=>({submitPayment:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return Y(e);case"receiptError":return q(e);case"stateChange":return Q(e);case"init":return F(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authentication":return z(e);case"journeyProgressionError":return G(e);case"webPixels":return C(e);case"expired":return A(e);case"configuration":return x(e);case"unrecoverable":return T(e);case"locale":return V(e)}}},"2024-10":{mapDefaults:_,eventListenersHook:ae,eventMessageMapper:oe},"2025-01":{mapDefaults:_,eventListenersHook:function(){const t=D(),r=ne();return e(()=>({progress:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return ce(e);case"receiptError":return q(e);case"stateChange":return Q(e);case"init":return F(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authenticationError":return se(e);case"journeyProgressionError":return G(e);case"webPixels":return C(e);case"expired":return A(e);case"configuration":return x(e);case"unrecoverable":return T(e);case"locale":return V(e);case"killswitch":return re(e)}}},"2025-04":{mapDefaults:_,eventListenersHook:function(){const t=D(),r=ne();return e(()=>({progress:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return ce(e);case"receiptError":return q(e);case"stateChange":return Q(e);case"init":return F(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authenticationError":return se(e);case"journeyProgressionError":return G(e);case"webPixels":return C(e);case"expired":return A(e);case"configuration":return x(e);case"unrecoverable":return T(e);case"locale":return V(e);case"killswitch":return re(e)}}},unstable:{mapDefaults:_,eventListenersHook:ae,eventMessageMapper:oe}},le=({children:e})=>{const t=h(),r=t?.schema||Array.from(l)[0];return n(de,{version:r,children:t=>n(v.Provider,{value:t,children:[n(j,{}),e]})})},de=({children:e,version:t})=>{const{mapDefaults:r,eventListenersHook:s,eventMessageMapper:o}=ue[t];return n($,{version:t,mapDefaults:r,eventListenersHook:s,eventMessageMapper:o,children:e})}
1,pe=({children:t})=>{const r=m(),{observability:o}=u(),a=e(()=>new N(o),[o]),i=h(),c=Boolean(i);s(()=>(r.value&&!window.Shopify?.CheckoutSheetProtocol&&(window.Shopify={...window.Shopify,CheckoutSheetProtocol:a},window.addEventListener("click",H)),()=>{delete window.Shopify?.CheckoutSheetProtocol,window.removeEventListener("click",H)}),[a,r.value]);const l=e(()=>({client:r.value?a:null,config:i}),[r.value,a,i]);return B(r.value,c),n(d.Provider,{value:l,children:n(b,{children:n(le,{children:t})})})};export{pe as CheckoutSheetProtocolProvider};
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.