import{v as o,u as e,i as n,E as t,h as s,m as a,t as r}from"./2c1ab0fe.Dbn2KvkT.js";import{al as i,am as l,W as c,an as u,ao as p,ap as h,d as y,aq as d,N as f}from"./4b4bc88f.z1yoAwwH.js";const P=i("CheckoutSheetProtocolSchemaContext");function m(o,e){o.postMessageToConsumer(e)}var v=(o=>(o.Continue="continue",o.Cancel="cancel",o))(v||{});class w{constructor(){this.listeners=new Set}listen(o){return this.listeners.add(o),()=>{this.listeners.delete(o)}}emit(o="continue"){this.listeners.forEach(e=>e(o))}}const T=n(void 0);function E(){const o=t(T);if(null==o)throw new l("Missing CheckoutProtocolEventContext");return o}function _(o){const e=E();s(()=>e.listen(o),[o,e])}function b({children:n}){const t=o(()=>new w,[]);return e(T.Provider,{value:t,children:n})}const g=i("MobileCheckoutSdkSchemaContext");function S(){const o=t(P),e=t(g);if(!o&&!e)throw new l("No Checkout Sheet Protocol or Mobile Checkout SDK Schema context found");return o||e}const C=[{brand:"APPLE_PAY",flowType:"applePay"},{brand:"GOOGLE_PAY",flowType:"googlePay"},{brand:"PAYPAL_EXPRESS",flowType:"payPal"},{brand:"SHOPIFY_INSTALLMENTS",flowType:"shopifyInstallments"},{brand:c.AmazonPay,flowType:"amazonPay"},{brand:c.BuyWithPrime,flowType:"buyWithPrime"}];function M(){const{checkout:{identity:o,negotiator:e},router:n,shopPay:t}=y(),s=e.parts.paymentLines;return a(()=>{const e="shopPay"===o.current.value,a=n.currentUrlMatches("/shoppay_login"),r=s.value,i=t.session.paymentMethodOption.value,l=[{condition:a,flowType:"shopPayLogin"},{condition:"SHOPIFY_INSTALLMENTS"===i?.name.toUpperCase(),flowType:"shopifyInstallments"},{condition:e,flowType:"shopPay"},...C.map(({brand:o,flowType:e})=>{return{condition:(n=o,Object.values(c).includes(n)?Boolean(d(r,o)):Boolean(f(r,o))),flowType:e};var n})];return l.find(({condition:o})=>o)?.flowType??"regular"})}const k=()=>{const{schema:{postMessageHandler:o}}=S(),{observability:e}=y();return{handleViolationEvent:r((n,t)=>{e.log("checkout_sheet_protocol_violation_event_emitted","Emitting event: `violation`."),o({type:"violation",flowType:t,violationErrors:n})},[o,e]),handleJourneyProgressionErrorEvent:r((n,t)=>{e.log("checkout_sheet_protocol_journey_progression_error_event_emitted","Emitting event: `journeyProgressionError`."),o({type:"journeyProgressionError",flowType:t,reasons:n})},[o,e])}};export{P as C,v as E,g as M,b as P,S as a,M as b,k as c,_ as d,m as p,E as u};