import{t as s}from"./chunk.window_CAbVMZox.esm.js";import"./chunk.init_4RtmBDrg.esm.js";import{E as t,S as n,_ as r,d as e,g as o,i as a,j as i,k as l,n as c,p as u,r as m,t as p,w as h,x as d}from"./chunk.register_Cnn1s0Rw.esm.js";import{t as j}from"./chunk.hooks_B8JiKvZ3.esm.js";import{r as f,t as k}from"./chunk.storage_n5jjEbMM.esm.js";import{t as _}from"./chunk.css_3LXkvzsj.esm.js";import{t as w}from"./chunk.hooks_DeX7xKd-.esm.js";import{t as g}from"./chunk.StyleProvider_DzcQtacD.esm.js";import{n as v,t as N}from"./chunk.AuthorizeStateProvider_B7VsfgRh.esm.js";import{t as b}from"./chunk.useDispatchEvent_D243iQEj.esm.js";import{t as y}from"./chunk.ShopIcon_DXVMSuBo.esm.js";import{t as O}from"./chunk.I18n_BrCYFahW.it.esm.js";import{n as x,r as I,t as L}from"./chunk.useWindoidMessageHandler_DeLL7FQR.esm.js";import{t as S}from"./chunk.useAuthorizeUrl_DZkUx0R0.esm.js";import{t as M}from"./chunk.windoid_DL-SQbA5.esm.js";import{t as P}from"./chunk.useStorefrontOrigin_BRDaX6sb.esm.js";function T(s){var n;const{notify:r}=o(),[e,a]=t(null),[l,c]=t(!1);i((()=>{(async()=>{const t=await async function(s=location.origin){return async function(s,t){try{const n=await fetch(s,t);return"ok"in n&&!n.ok?null:async function(s){try{return s&&"function"==typeof s.json?await s.json():null}catch(s){return null}}(n)}catch(s){return null}}(`${s}/meta.json`)}(s);t?a(t):r(new Error("Failed to fetch store metadata")),c(!0)})()}),[r,s]);const u=null!==(n=null==e?void 0:e.name)&&void 0!==n?n:"the store";return{loaded:l,storeId:null==e?void 0:e.id,storeMetadata:e,storeName:u}}function C({anchorElement:t,onClose:n,storefrontOrigin:e}){var o;const{trackUserAction:a}=w(),{translate:i}=j(),{devMode:l}=d(),{loaded:c,storeId:m,storeName:p}=T(e),h=m?`https://shop.app/sid/${m}`:"#";if(u()){const t=i("shopFollowButton.followingModal.title",{store:p}),e=i("shopFollowButton.followingModal.subtitle"),o=i("shopFollowButton.continueGeneric");return r(v,{headerLogo:r(y,{className:"h-4-5 text-purple-primary"}),onDismiss:n,popupDisabled:!0,variant:"follow",visible:c,children:r("div",{className:"m-auto p-6 font-sans",children:[r("div",{className:"relative m-auto pb-4 text-center",children:[r("h2",{className:"mb-2 px-6 text-subtitle text-black",children:t}),r("p",{className:"overflow-hidden text-ellipsis whitespace-pre-line text-body-small text-grayscale-d1",children:e})]}),r("div",{className:"flex justify-center",children:r("button",{className:"w-full rounded-md bg-purple-primary p-3 leading-6 text-white no-underline",onClick:function(){a({userAction:"FOLLOWING_GET_SHOP_APP_CLICK"}),s.open(h,"_self"),n()},type:"button",children:o})})]})})}const f=null!==(o=i("shopFollowButton.followingModal.qrAltText"))&&void 0!==o?o:"";let k=m?`https://shop.app/qr/sid/${m}`:"#";return l&&(k="https://shop.app/qr/sid/59659354134"),r(v,{anchorTo:t,disableMinWidth:!0,hideHeader:!0,onDismiss:n,popupDisabled:!0,variant:"follow",visible:c,children:r("div",{className:"m-auto w-55 p-6 font-sans",children:[r("div",{className:"relative m-auto pb-4 text-center",children:r("p",{className:"overflow-hidden text-ellipsis whitespace-pre-line text-grayscale-d1",children:i("shopFollowButton.followingModal.qrHeader",{store:p})})}),r("div",{className:"m-auto w-37 bg-white forced-color-adjust-none",children:r("img",{src:k,alt:f})}),r("div",{className:"flex justify-center px-0 pb-0 pt-4 text-purple-primary",children:r(y,{className:"h-5"})})]})})}function F({className:s,filled:t}){return r("svg",{className:s,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",children:r("path",{fill:t?"currentColor":"none",stroke:"currentColor","stroke-linejoin":"round","stroke-width":"1.667",d:"m9.14 4.502.86.881.86-.881a3.82 3.82 0 0 1 5.437-.064l.064.064c1.498 1.536 1.518 4.014.062 5.576l-.062.066L10 16.666l-6.36-6.524c-1.52-1.557-1.52-4.083 0-5.641a3.822 3.822 0 0 1 5.5 0Z"})})}const E="shop_follow",A=({clientId:a,following:u,storefrontOrigin:m})=>{const{trackPageImpression:p,trackUserAction:g}=w(),{translate:v}=j(),N=b(),{notify:O}=o(),T=n(null),A=n(null),{devMode:B}=d(),[W,D]=function({key:s,type:n="localStorage",defaultValue:r}){const e=`signInWithShop:${s}`,[o,a]=t((()=>{const s=k(e,{session:"sessionStorage"===n});if(!s)return r;try{return JSON.parse(s)}catch(s){return r}}));return[o,l((s=>{a(s),f(e,JSON.stringify(s),{session:"sessionStorage"===n})}),[e,n])]}({key:"following",defaultValue:!1}),[z,R]=t(void 0===u?W:"true"===u),H=l((s=>{R(s),D(s)}),[D]);i((()=>{void 0!==u&&D("true"===u)}),[u,D]);const[U,G]=t(!1),q=P(m),[$,K]=t(),V=I({defaultUxMode:"redirect",uxMode:"windoid"}),J="windoid"===V;i((()=>{p({page:z?"COMPONENT_LOADED_FOLLOWING":"COMPONENT_LOADED_NOT_FOLLOWING"})}),[z,p]),i((()=>{if(!T.current||void 0===p||!e())return;const s=new IntersectionObserver((t=>{for(const{isIntersecting:n}of t)n&&(null==s||s.disconnect(),p({page:"FOLLOW_BUTTON_SHOWN_IN_VIEWPORT"}))}));return s.observe(T.current),()=>{s.disconnect()}}),[p]),i((()=>{const t=new URL(s.location.href);var n;"completed"===t.searchParams.get("shop_follow")&&(H(!0),t.searchParams.delete(E),null===(n=s.history)||void 0===n||n.replaceState({},"",t.toString()))}),[H]);const Q=h((()=>{if(J)return;const t=new URL(s.location.href);return t.searchParams.set(E,"completed"),`${t.pathname}${t.search}`}),[J]),{authorizeUrl:Z}=S({clientId:a,error:$,flow:"follow",proxy:!0,proxyCoreIdp:!0,responseType:"code",uxMode:V,...Q&&{returnTo:Q}}),X=l((async({avatar:s,givenName:t,loggedIn:n,shouldFinalizeLogin:r,email:e})=>{n&&r&&await x(q,(s=>{O(new Error(s))})),N("completed",{loggedIn:n,email:e}),n&&r&&J&&N("storefront:signincompleted",{avatar:(()=>{const n=c("shop-user-avatar"),r=(null==t?void 0:t[0])||(null==e?void 0:e[0])||"";return n.setAttribute("src",s||""),n.setAttribute("initial",r),n})()},!0),H(!0),G(!1)}),[N,J,O,H,q]),Y=l((({code:s,email:t,message:n})=>{N("error",{code:s,email:t,message:n}),"retriable_server_error"===s&&K("retriable_server_error")}),[N]),ss=L({handleComplete:X,handleError:Y,windoidRef:A}),ts=l((()=>B?H(!z):z?(p({page:"FOLLOWING_GET_SHOP_APP_CTA"}),G(!0)):(g({userAction:"FOLLOW_ON_SHOP_CLICKED"}),void(J?A.current=M(Z,ss):s.location.href=Z))),[Z,B,z,ss,J,H,p,g]),ns=_("absolute inset-y-0 -z-10 rounded-max bg-purple-primary",z?"w-9 animate-follow":"w-full group-hover_bg-purple-d0"),rs=_("group relative inline-flex h-9 items-center rounded-max bg-transparent",z&&"gap-x-1-5"),es=_("cursor-pointer whitespace-nowrap pr-3 font-sans text-button-large transition-colors",z?"text-black":"text-white"),os=z?"shopFollowButton.following":"shopFollowButton.follow",as=z&&U&&q?r(C,{anchorElement:T,onClose:()=>G(!1),storefrontOrigin:q}):null;return r("div",{className:"relative z-0",children:[r("button",{className:rs,onClick:ts,type:"button",ref:T,children:[r("div",{className:ns}),r("div",{className:"px-2 text-white",children:r(F,{className:"size-5",filled:z})}),r("span",{className:es,children:v(os,{shop:r(y,{className:"relative inline-block h-4 w-auto"})})})]}),as]})},B=async s=>await {shopFollowButton:{follow:"Segui su {shop}",following:"Stai seguendo su {shop}",continueGeneric:"Continua",followingModal:{title:"Visita {store} su Shop",subtitle:"Tutto ciò di cui hai bisogno per fare acquisti, tracciare ordini e pagare in un unico posto.",qrHeader:"Scansiona per visitare {store} sull’app Shop",qrAltText:"Codice QR dell’app Shop"}}};p((({devMode:s,element:t,...n})=>r(m,{devMode:s,element:t,featureName:"ShopFollowButton",children:r(g,{children:r(a,{monorailProps:{analyticsContext:"loginWithShopFollow",flow:"follow"},children:r(O,{getFeatureDictionary:B,children:r(N,{children:r(A,{...n})})})})})})),{name:"shop-follow-button",props:{clientId:"string",devMode:"boolean",following:"string",storefrontOrigin:"string"},shadow:"open"}); import"./chunk.document_DMcRsBXN.esm.js";import"./chunk.casing_U_9x-Om3.esm.js";import"./chunk.v4_C3N_0s0v.esm.js";import"./chunk.networkErrorMessages_Du380vAr.esm.js";import"./chunk.utils_Cjeq_SSZ.esm.js";import"./chunk.context_IZTYG4gY.esm.js";import"./chunk.PortalProvider_BcqAKZox.esm.js";import"./chunk.authorize_DINGMyE5.esm.js";import"./chunk.buildAuthorizeUrl_CHOrRT7v.esm.js";import"./chunk.validators_BbO3UEjF.esm.js";import"./chunk.buildUrlSearchParams_CtotqmnW.esm.js"; //# sourceMappingURL=client.shop-follow-button_DqVCWw1E.it.esm.js.map