import{i as e,I as o,_ as t,u as n,R as i,p as r,t as s,g as a,d as l,h as c,A as u,j as d,J as p,K as h,y as g,T as m,L as f,M as S,q as v,B as _,N as w,O as b,Q as y,U as I,V as x,W as C,X as T,Y as W,o as k,Z as O,a0 as N,k as A}from"./chunk.common_zpuuaMLp.esm.js";import{A as M}from"./chunk.modal_BhWf-Xv9.esm.js";const P={loginWithShop:"default",loginWithShopSelfServe:"self_serve_customer_accounts",loginWithShopClassicCustomerAccounts:"classic_customer_accounts",loginWithShopPrequal:"shop_pay_installments_prequal",loginWithShopPaymentRequest:"payment_request",loginWithShopCheckoutExtension:"default",loginWithShopCheckoutModal:"checkout_modal",loginWithShopShopWeb:"",shopCashOffers:"shop_cash_offers"};function U({analyticsContext:e="loginWithShop",checkoutToken:o,checkoutVersion:t,flowVersion:n,shopId:i,source:r,uxMode:s}){return{analyticsContext:e,checkoutVersion:t,checkoutToken:o,flow:P[e],flowVersion:n,shopId:i,source:r,uxMode:s}}const B=["loginWithShop"],L=o=>{var{action:i,activatorId:P,analyticsContext:U="loginWithShop",anchorTo:L,autoOpen:j,bordered:q,email:R,emailInputSelector:V,experiments:E,firstname:H,fullWidth:G,hideButton:K,lastname:z,persistAfterSignIn:D=!0,proxy:F=!1,uxMode:$="iframe",version:J}=o,Q=t(o,["action","activatorId","analyticsContext","anchorTo","autoOpen","bordered","email","emailInputSelector","experiments","firstname","fullWidth","hideButton","lastname","persistAfterSignIn","proxy","uxMode","version"]);const{notify:X}=r(),{trackPageImpression:Y,trackUserAction:Z}=s(),{translate:ee}=a(),[oe,te]=l(!0),{instanceId:ne}=c(),ie=u(P?d.getElementById(P):null),re=u(null),se=u(null),ae=u(null),[le,ce]=l(),ue=p({experiments:E,defaultUxMode:"redirect",uxMode:$}),{getSubmittedEmail:de,updateEmailToPost:pe,updateNamesToPost:he}=h({email:R,emailInputSelector:V,iframeRef:se});g((()=>{he(H,z)}),[H,z,he]);const ge=m((()=>{const e=e=>_(void 0,[e],void 0,(function*({detail:e}){ce(void 0);const o=e.email;yield pe(o)}));return{requestShow:e,start:e}}),[pe]);f(ge),g((()=>{var e,o;i&&("follow"===i?null===(e=console.warn)||void 0===e||e.call(console,"[Sign in with Shop] The action prop is deprecated, please use instead."):null===(o=console.warn)||void 0===o||o.call(console,`[Sign in with Shop] Received deprecated attribute: action, "${i}"`))}),[i,X]),g((()=>{K||Y({page:"SIGN_IN_WITH_SHOP_BUTTON"})}),[K,Y]);const me=S({storefrontOrigin:Q.storefrontOrigin}),fe=v((e=>_(void 0,void 0,void 0,(function*(){const{email:o,givenName:t,userInteracted:n}=e;let i;D||te(!1),n||(i=ee("shopLoginButton.toast.action"));let r=ee("shopLoginButton.toast.default");t&&(r=ee("shopLoginButton.toast.user",{user:t}));const s={actionText:i,analyticsTraceId:ne,flow:Q.flow,subText:o,text:r};B.includes(U)?w(s):"windoid"===ue&&b(y,s),yield me(e)}))),[ue,U,ne,D,Q.flow,ee,me]),Se="loginWithShopPrequal"===U?{disableSignUp:!1,flow:"prequal",flowVersion:"unspecified",hideCopy:!1,isCompactLayout:!1,proxy:!0}:{},ve=m((()=>{var e;return void 0!==J&&(null===(e=console.warn)||void 0===e||e.call(console,`[Sign in with Shop] Received deprecated attribute: version, "${J}"`)),F||"2"===J}),[F,J]),{authorizeUrl:_e,getAuthorizeUrl:we}=I(Object.assign(Object.assign(Object.assign({analyticsContext:U,error:le,experiments:E},Q),{proxy:ve,uxMode:ue}),Se)),be=v((({code:e})=>{var o;switch(e){case"server_error":w({analyticsTraceId:ne,flow:Q.flow,text:ee("shopLoginButton.subject_mapping_error"),variant:"error"});break;case"retriable_server_error":le===e&&(null===(o=se.current)||void 0===o||o.reload()),ce(e)}}),[le,ne,Q.flow,ee]),ye=x({handleComplete:fe,handleError:be,windoidRef:ae}),Ie=v((o=>{switch(ue){case"windoid":ae.current=C(o,ye);break;case"redirect":e.location.href=o}}),[ue,ye]),xe=v((()=>{Z({userAction:"SIGN_IN_WITH_SHOP_BUTTON_CLICK"}),Ie(_e)}),[_e,Ie,Z]),Ce=T(xe,150,!0),Te=v((()=>{var e;Z({userAction:"SIGN_IN_WITH_SHOP_PROMPT_CHANGE_CLICK"}),null===(e=null==se?void 0:se.current)||void 0===e||e.close({dismissMethod:"prompt_change",reason:"user_prompt_change_clicked"})}),[Z]),We=W({getAuthorizeUrl:we,getEmail:de,iframeRef:se,openWindoid:Ie}),ke=K||ie.current||!oe?null:n(O,{bordered:q,fullWidth:G,onClick:Ce,ref:re,children:ee("shopLoginButton.continue",{shop:n(k,{className:"flex aspect-branded-button-icon h-branded-button-icon w-auto translate-y-[0.015em] self-center"})})}),Oe="iframe"===ue,Ne=ie.current?ie:re,Ae=Oe?Ne:void 0,Me=m((()=>Oe?_e:we({uxRole:"prompt"})),[_e,we,Oe]),Pe=Oe||N()?"default":"wide",Ue=m((()=>{const o=!(void 0===e||!e.Shopify||!e.Shopify.SignInWithShop)&&["initCustomerAccounts","initCustomerAccountsSignUp","initShopForNewCustomerAccounts"].some((o=>"function"==typeof e.Shopify.SignInWithShop[o]));return"windoid"!==ue&&"redirect"!==ue||o}),[ue]);return n(A,{children:[ke,Ue&&n(M,{activator:Ae,anchorTo:L,autoOpen:j&&!ae.current,onComplete:fe,onError:be,onPromptChange:Te,onPromptContinue:We,proxy:ve,ref:se,src:Me,modalType:Pe,variant:"default"})]})},j=e=>_(void 0,void 0,void 0,(function*(){return{shopLoginButton:{title:"Sign in with Shop",continue:"Sign in with {shop}",toast:{default:"Signed in with Shop",user:"Signed in as {user}",action:"Switch"},subject_mapping_error:"To sign in with this email, continue without Shop."}}}));o((e=>{var{element:o}=e,r=t(e,["element"]);return n(i,{element:o,featureName:"ShopLoginButton",getFeatureDictionary:j,monorailProps:U(r),children:n(L,Object.assign({},r))})}),{methods:["requestShow","start","showToast"],name:"shop-login-button",props:{action:"string",activatorId:"string",analyticsContext:"string",anchorTo:"string",apiKey:"string",autoOpen:"boolean",avoidPayAltDomain:"boolean",bordered:"boolean",checkoutVersion:"string",clientId:"string",codeChallenge:"string",codeChallengeMethod:"string",consentChallenge:"string",disableSignUp:"boolean",email:"string",emailInputSelector:"string",experiments:"string",firstname:"string",flow:"string",flowVersion:"string",fullWidth:"boolean",hideButton:"boolean",keepModalOpen:"boolean",lastname:"string",persistAfterSignIn:"boolean",popUpFeatures:"string",popUpName:"string",proxy:"boolean",redirectType:"string",redirectUri:"string",requireVerification:"boolean",responseMode:"string",responseType:"string",returnUri:"string",scope:"string",source:"string",state:"string",storefrontDomain:"string",uxMode:"string",version:"string"},shadow:"open"}); //# sourceMappingURL=client.shop-login-button_D-X5HJtB.en.esm.js.map