import{i as e,I as o,_ as t,u as n,R as i,e as r,o as s,s as a,g as l,d as c,h as u,A as d,j as p,J as h,K as g,y as m,T as f,L as S,M as v,q as w,B as _,N as y,O as b,Q as I,U as C,V as x,W as T,X as W,Y as O,Z as k,a0 as A,a1 as M,k as N}from"./chunk.common_0OUaOowp.esm.js";import{A as P}from"./chunk.modal_CGo_dVj3.esm.js";const U={loginWithShop:"default",loginWithShopEmbed:"embed",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 B({analyticsContext:e="loginWithShop",checkoutToken:o,checkoutVersion:t,flowVersion:n,shopId:i,source:r,uxMode:s}){return{analyticsContext:e,checkoutVersion:t,checkoutToken:o,flow:U[e],flowVersion:n,shopId:i,source:r,uxMode:s}}const L=["loginWithShop"],j=o=>{var{action:i,activatorId:U,analyticsContext:B="loginWithShop",anchorTo:j,autoOpen:q,bordered:E,email:R,emailInputSelector:V,experiments:H,firstname:G,fullWidth:K,hideButton:z,lastname:D,persistAfterSignIn:F=!0,proxy:$=!1,uxMode:J="iframe",version:Q}=o,X=t(o,["action","activatorId","analyticsContext","anchorTo","autoOpen","bordered","email","emailInputSelector","experiments","firstname","fullWidth","hideButton","lastname","persistAfterSignIn","proxy","uxMode","version"]);const{dispatch:Y}=r(),{notify:Z}=s(),{trackPageImpression:ee,trackUserAction:oe}=a(),{translate:te}=l(),[ne,ie]=c(!0),{instanceId:re}=u(),se=d(U?p.getElementById(U):null),ae=d(null),le=d(null),ce=d(null),[ue,de]=c(),pe=h({defaultUxMode:"redirect",uxMode:J}),{getSubmittedEmail:he,updateEmailToPost:ge,updateNamesToPost:me}=g({email:R,emailInputSelector:V,iframeRef:le});m((()=>{me(G,D)}),[G,D,me]);const fe=f((()=>{const e=e=>_(void 0,[e],void 0,(function*({detail:e}){de(void 0);const o=e.email;yield ge(o)}));return{requestShow:e,start:e}}),[ge]);S(fe),m((()=>{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,Z]),m((()=>{z||ee({page:"SIGN_IN_WITH_SHOP_BUTTON"})}),[z,ee]);const Se=v({storefrontOrigin:X.storefrontOrigin}),ve=w((e=>_(void 0,void 0,void 0,(function*(){const{email:o,givenName:t,userInteracted:n}=e;let i;F||ie(!1),n||(i=te("shopLoginButton.toast.action"));let r=te("shopLoginButton.toast.default");t&&(r=te("shopLoginButton.toast.user",{user:t}));const s={actionText:i,analyticsTraceId:re,flow:X.flow,subText:o,text:r};L.includes(B)?y(s):"windoid"===pe&&b(I,s),yield Se(e)}))),[pe,B,re,F,X.flow,te,Se]),we="loginWithShopPrequal"===B?{disableSignUp:!1,flow:"prequal",flowVersion:"unspecified",hideCopy:!1,isCompactLayout:!1,proxy:!0}:{},_e=f((()=>{var e;return void 0!==Q&&(null===(e=console.warn)||void 0===e||e.call(console,`[Sign in with Shop] Received deprecated attribute: version, "${Q}"`)),$||"2"===Q}),[$,Q]),{authorizeUrl:ye,getAuthorizeUrl:be}=C(Object.assign(Object.assign(Object.assign({analyticsContext:B,error:ue,experiments:H},X),{proxy:_e,uxMode:pe}),we)),Ie=w((({code:e})=>{var o;switch(e){case"server_error":y({analyticsTraceId:re,flow:X.flow,text:te("shopLoginButton.subject_mapping_error"),variant:"error"});break;case"retriable_server_error":ue===e&&(null===(o=le.current)||void 0===o||o.reload()),de(e)}}),[ue,re,X.flow,te]),Ce=x({handleClose:()=>{Y({type:"windoidClosed"})},handleComplete:ve,handleError:Ie,handleOpen:()=>{Y({type:"windoidOpened"})},windoidRef:ce}),xe=w((o=>{switch(pe){case"windoid":ce.current=T(o,Ce);break;case"redirect":e.location.href=o}}),[pe,Ce]),Te=w((()=>{oe({userAction:"SIGN_IN_WITH_SHOP_BUTTON_CLICK"}),xe(ye)}),[ye,xe,oe]),We=W(Te,150,!0),Oe=w((()=>{var e;oe({userAction:"SIGN_IN_WITH_SHOP_PROMPT_CHANGE_CLICK"}),null===(e=null==le?void 0:le.current)||void 0===e||e.close({dismissMethod:"prompt_change",reason:"user_prompt_change_clicked"})}),[oe]),ke=O({getAuthorizeUrl:be,getEmail:he,iframeRef:le,openWindoid:xe}),Ae=z||se.current||!ne?null:n(A,{bordered:E,fullWidth:K,onClick:We,ref:ae,children:te("shopLoginButton.continue",{shop:n(k,{})})}),Me="iframe"===pe,Ne=se.current?se:ae,Pe=Me?Ne:void 0,Ue=f((()=>Me?ye:be({uxRole:"prompt"})),[ye,be,Me]),Be=Me||M()?"default":"wide",Le=f((()=>{const o=!(void 0===e||!e.Shopify||!e.Shopify.SignInWithShop)&&["initCustomerAccounts","initCustomerAccountsSignUp","initShopForNewCustomerAccounts"].some((o=>"function"==typeof e.Shopify.SignInWithShop[o]));return"windoid"!==pe&&"redirect"!==pe||o}),[pe]);return n(N,{children:[Ae,Le&&n(P,{activator:Pe,anchorTo:j,autoOpen:q&&!ce.current,onComplete:ve,onError:Ie,onPromptChange:Oe,onPromptContinue:ke,proxy:_e,ref:le,src:Ue,modalType:Be,variant:"default"})]})},q=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:q,monorailProps:B(r),children:n(j,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",proxyCoreIdp:"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_BtqW_SIO.en.esm.js.map