import{q as m,y as w,a as x}from"./dist-vendor.a3kfnPsb.js";import{a as g,B as b}from"./shop-pay-FullScreenBackground.Bxb6RI8a.js";import{lx as E}from"./shop-pay-ButtonWithRegisterWebPixel.CUNg0UCj.js";var P=(e=>(e.Generic="generic",e.SignInFailed="sign_in_failed",e.ContinueWithShopPay="continue_with_shop_pay",e))(P||{});const z=()=>{const{environment:{services:{shopServer:e}},shop:{myshopifyDomain:r},source:{checkoutSessionIdentifier:n},url:t}=g();return{exchangeSessionTokenForCookie:m(async({token:h,origin:d,analytics_trace_id:i})=>{const o=new URLSearchParams({token:h,origin:d,shopify_domain:r});n&&o.set("checkout_token",n),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})},[n,r,t,e.url])}},W=()=>{const{environment:{services:{shopServer:e}},shop:r}=g(),n=parseInt(b(r.id),10);return{extendBuyerIdentity:m(async()=>{await fetch(new URL(`/checkout/${n}/shopify_pay/extend_buyer_identity`,e.url),{method:"GET",keepalive:!0})},[n,e.url])}},S="shopify_pay",l=":";var a=(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))(a||{}),B=(e=>(e.AllowNoInitialEmail="allowNoInitialEmail",e.Create="create",e.Hidden="hidden",e.OriginChanged="originChanged",e.Ready="ready",e.CheckoutQueueToken="checkoutQueueToken",e))(B||{}),F=(e=>(e.ShopifyPayUserNotFound="shopify_pay_user_not_found",e))(F||{}),M=(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))(M||{});function N(e,r={delimiter:l,messageKey:S}){return[r.messageKey,r.delimiter,JSON.stringify(e)].join("")}function T(e){return N(e)}function D(e,r){e&&e.contentWindow?.postMessage(T(r),"*")}function H({targetId:e,onLoaded:r,onClosed:n,onHidden:t,onError:p,onLoggedIn:h,onReady:d,onResized:i,onShareCaptchaToken:o,onEmailChange:u,skip:f=!1}){const _=m(s=>{switch(s.action){case a.Closed:return n?.();case a.Hidden:return t?.();case a.Error:return p?.(s.message,s.apiError,s.email);case a.Loaded:return r?.();case a.LoggedIn:return h?.(s.token,s.shop_pay_access_token);case a.Ready:return d?.(s.phoneNumber);case a.Resized:return i?.(parseInt(s.height,10));case a.ShareCaptchaToken:return o?.(s.token);case a.EmailChanged:return u?.(s.email,s.isUserFound)}},[n,t,p,r,h,d,i,o,u]),{environment:v}=g(),k=v.services.payShopifyCom.url;w(()=>{if(f)return;const s=({data:c,origin:C})=>{if(C!==k||!c||typeof c!="string"||!c.includes(l))return;const[I,...L]=c.split(l);if(I===S)try{const y=JSON.parse(L.join(l));(e&&y.targetId===e||!e)&&_(y)}catch{}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[_,k,e,f])}function K(){const e=E();return x(()=>Array.from(e.value.values()).filter(n=>n.length>0).length>1)}export{M as A,l as D,S as M,a as R,B as S,P as U,z as a,W as b,H as c,F as d,D as p,K as u};
