import{q as m,y as x}from"./vendor.CynPCimz.js";import{b as g,ag as E}from"./app.BXvw8ij6.js";const U=()=>{const{environment:{services:{shopServer:e}},shop:{myshopifyDomain:r},source:{checkoutSessionIdentifier:a},url:t}=g();return{exchangeSessionTokenForCookie:m(async({token:d,origin:h,analytics_trace_id:i})=>{const o=new URLSearchParams({token:d,origin:h,shopify_domain:r});a&&o.set("checkout_token",a),i&&o.set("analytics_trace_id",i);const u=new URL(t.shopPaySession(),e.url);return u.search=o.toString(),fetch(u.href,{method:"POST",keepalive:!0})},[a,r,t,e.url])}},B=()=>{const{environment:{services:{shopServer:e}},shop:r}=g(),a=parseInt(E(r.id),10);return{extendBuyerIdentity:m(async()=>{await fetch(new URL(`/checkout/${a}/shopify_pay/extend_buyer_identity`,e.url),{method:"GET",keepalive:!0})},[a,e.url])}},S="shopify_pay",l=":";var n=(e=>(e.Closed="closed",e.EmailChanged="emailChanged",e.Error="error",e.Hidden="hidden",e.Loaded="loaded",e.LoggedIn="loggedIn",e.Ready="ready",e.Resized="resized",e.ShareCaptchaToken="shareCaptchaToken",e))(n||{}),b=(e=>(e.AllowNoInitialEmail="allowNoInitialEmail",e.Create="create",e.Hidden="hidden",e.OriginChanged="originChanged",e.Ready="ready",e.CheckoutQueueToken="checkoutQueueToken",e))(b||{}),L=(e=>(e.ShopifyPayUserNotFound="shopify_pay_user_not_found",e))(L||{}),T=(e=>(e.FraudGuard="fraud_guard",e.InvalidEmail="invalid_email",e.InvalidPhone="invalid_phone",e.LimitExceeded="limit_exceeded",e.PhoneBlocked="phone_blocked",e.RecordNotFound="record_not_found",e))(T||{});function M(e,r={delimiter:l,messageKey:S}){return[r.messageKey,r.delimiter,JSON.stringify(e)].join("")}function N(e){return M(e)}function O(e,r){e&&e.contentWindow?.postMessage(N(r),"*")}function z({targetId:e,onLoaded:r,onClosed:a,onHidden:t,onError:y,onLoggedIn:d,onReady:h,onResized:i,onShareCaptchaToken:o,onEmailChange:u,skip:f=!1}){const k=m(s=>{switch(s.action){case n.Closed:return a?.();case n.Hidden:return t?.();case n.Error:return y?.(s.message,s.apiError,s.email);case n.Loaded:return r?.();case n.LoggedIn:return d?.(s.token,s.shop_pay_access_token);case n.Ready:return h?.(s.phoneNumber);case n.Resized:return i?.(parseInt(s.height,10));case n.ShareCaptchaToken:return o?.(s.token);case n.EmailChanged:return u?.(s.email,s.isUserFound)}},[a,t,y,r,d,h,i,o,u]),{environment:C}=g(),_=C.services.payShopifyCom.url;x(()=>{if(f)return;const s=({data:c,origin:v})=>{if(v!==_||!c||typeof c!="string"||!c.includes(l))return;const[I,...w]=c.split(l);if(I===S)try{const p=JSON.parse(w.join(l));(e&&p.targetId===e||!e)&&k(p)}catch{}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[k,_,e,f])}export{T as A,l as D,S as M,n as R,b as S,B as a,z as b,L as c,O as p,U as u};
