1import{T as e,g as t,q as r,u as n,h as s}from"./2c1ab0fe.XVnTovwp.js";import{u as o,cP as a,b_ as i,cq as c,a as u,ae as l}from"./f67abd2c.DYpmk7mw.js";import{dD as d,bq as p,R as h,dE as m}from"./164ad2e3.hrg71Gqs.js";import{p as f,i as g}from"./app.Bke-0Cv3.js";import{p as y,u as v,C as b,P as w}from"./7ee73f43.DiwfQ4hU.js";import{p as k,c as P,a as M,g as E,h as I,b as L,d as T,i as x,j as A,k as C,f as D,e as S,u as j,C as _,l as H,n as B,o as R}from"./2a0f03e4.DhwQfXBC.js";import"./d0bb51ec.Bel_y502.js";import"./60a453ce.Al5ISuVm.js";import"./e12db40c.D-IRYT_x.js";import"./9dba8418.C8BcPjk_.js";import"./5ef0d995.D5UKDDjZ.js";import"./29034f35.B4fDNd4W.js";class U{constructor(e){this.customEventNamespace="CheckoutSheetProtocolConsumer",this.#e=N.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 N{static fromEnvironment(){return window.opener?new N(window.opener):window.parent!==window?new N(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&&y(i,t)}};return{schema:{version:r,eventMessageMapper:a,eventListeners:c,defaultsMapper:t=>n(t,e),postMessageHandler:e}}},[c,r,a,i,n]))};function q(e){return{handlerId:"error",body:[{group:"authentication",code:e.status.toLowerCase(),reason:e.reason||void 0}]}}function z(e){if(e)return e.lines.reduce((e,t)=>{if(!t)return e;const r=function(e){if(g(e)){const t=e.amount;if(!t)return;const r=e.discount,n=r.value,{valueType:s,value:o}=k(n);return{title:r.title,amount:t,valueType:s,value:o,applicationType:r.type}}}(t);return r&&e.push(r),e},[])}function F({total:e,subtotal:t,taxes:r,taxesIncluded:n,discountLines:s,shipping:o}){return{total:e,subtotal:t,taxes:M(r),taxesIncluded:n,discounts:z(s),shipping:P(o)}}function K({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=E(r,n),p=F({total:d.total,subtotal:d.subtotal,taxes:d.taxes,taxesIncluded:d.merchandiseLines?.taxesIncluded,discountLines:d.discountLines,shipping:d.delivery}),h=I(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:T(u),deliveries:L(d.delivery,i)},thankYouPageUrl:m,orderId:l,cart:h}}function O(e){return{handlerId:"completed",body:K(e)}}function W(e){return{handlerId:e.type,body:{paymentUrl:e.paymentUrl}}}function Y(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 G(e){return{handlerId:"locale",body:{locale:e.locale}}}function V(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=F({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=L(p,i);return{flowType:f,cart:I(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=v(),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 O(e);case"receiptError":return V(e);case"stateChange":return Q(e);case"init":return W(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authenticationError":return se(e);case"journeyProgressionError":return Y(e);case"webPixels":return D(e);case"expired":return C(e);case"configuration":return A(e);case"unrecoverable":return x(e);case"locale":return G(e);case"killswitch":return re(e)}}function ae(){const t=j(),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=E(r,n),p=F({total:d.total,subtotal:d.subtotal,taxes:d.taxes,taxesIncluded:d.merchandiseLines?.taxesIncluded,discountLines:d.discountLines,shipping:d.delivery}),h=I(t,d.merchandiseLines,p);return{flowType:e,confirmationURL:s.url,orderDetails:{id:l,cart:h,email:o,phone:a,billingAddress:c,paymentMethods:T(u),deliveries:L(d.delivery,i)}}}function ce(e){return{handlerId:"completed",body:ie(e)}}const ue={"2024-04":{mapDefaults:H,eventListenersHook:function(){const t=j(),r=te();return e(()=>({submitPayment:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return O(e);case"receiptError":return V(e);case"stateChange":return Q(e);case"init":return W(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authentication":return q(e);case"journeyProgressionError":return Y(e);case"webPixels":return D(e);case"expired":return C(e);case"configuration":return A(e);case"unrecoverable":return x(e);case"locale":return G(e)}}},"2024-07":{mapDefaults:H,eventListenersHook:function(){const t=j(),r=te();return e(()=>({submitPayment:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return O(e);case"receiptError":return V(e);case"stateChange":return Q(e);case"init":return W(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authentication":return q(e);case"journeyProgressionError":return Y(e);case"webPixels":return D(e);case"expired":return C(e);case"configuration":return A(e);case"unrecoverable":return x(e);case"locale":return G(e)}}},"2024-10":{mapDefaults:H,eventListenersHook:ae,eventMessageMapper:oe},"2025-01":{mapDefaults:H,eventListenersHook:function(){const t=j(),r=ne();return e(()=>({progress:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return ce(e);case"receiptError":return V(e);case"stateChange":return Q(e);case"init":return W(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authenticationError":return se(e);case"journeyProgressionError":return Y(e);case"webPixels":return D(e);case"expired":return C(e);case"configuration":return A(e);case"unrecoverable":return x(e);case"locale":return G(e);case"killswitch":return re(e)}}},"2025-04":{mapDefaults:H,eventListenersHook:function(){const t=j(),r=ne();return e(()=>({progress:r,presented:t}),[r,t])},eventMessageMapper:function(e){switch(e.type){case"completed":return ce(e);case"receiptError":return V(e);case"stateChange":return Q(e);case"init":return W(e);case"violation":return Z(e);case"checkoutBlockingEvent":return S(e);case"updateProgressButton":return X(e);case"authenticationError":return se(e);case"journeyProgressionError":return Y(e);case"webPixels":return D(e);case"expired":return C(e);case"configuration":return A(e);case"unrecoverable":return x(e);case"locale":return G(e);case"killswitch":return re(e)}}},unstable:{mapDefaults:H,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(b.Provider,{value:t,children:[n(_,{}),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 U(o),[o]),i=h(),c=Boolean(i);s(()=>(r.value&&!window.Shopify?.CheckoutSheetProtocol&&(window.Shopify={...window.Shopify,CheckoutSheetProtocol:a},window.addEventListener("click",B)),()=>{delete window.Shopify?.CheckoutSheetProtocol,window.removeEventListener("click",B)}),[a,r.value]);const l=e(()=>({client:r.value?a:null,config:i}),[r.value,a,i]);return R(r.value,c),n(d.Provider,{value:l,children:n(w,{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.