import{d as e,q as o,ar as t,an as n,v as r,T as l,at as i,i as s,p as a,y as c,B as d,t as u,g as p,a1 as h,u as f,o as m,I as v,_ as g,R as w,r as N,A as b,n as _,U as O,l as x,au as y}from"./chunk.common_D520SWRp.esm.js";import{M as I,A as C}from"./chunk.modal_zlIbEjjJ.esm.js";function F(o){var t;const{notify:n}=a(),[r,l]=e(null),[i,s]=e(!1);c((()=>{(()=>{d(this,void 0,void 0,(function*(){const e=yield function(){return d(this,arguments,void 0,(function*(e=location.origin){const o=fetch(`${e}/meta.json`);try{const e=yield o;return yield e.json()}catch(e){return null}}))}(o);e?l(e):n(new Error("Failed to fetch store metadata")),s(!0)}))})()}),[n,o]);const u=null!==(t=null==r?void 0:r.name)&&void 0!==t?t:"the store";return{loaded:i,storeId:null==r?void 0:r.id,storeMetadata:r,storeName:u}}function L({anchorElement:e,devMode:o,onClose:t,storefrontOrigin:n}){var r;const{trackUserAction:l}=u(),{translate:i}=p(),{loaded:a,storeId:c,storeName:d}=F(n),v=c?`https://shop.app/sid/${c}`:"#";if(h()){const e=i("shopFollowButton.followingModal.title",{store:d}),o=i("shopFollowButton.followingModal.subtitle"),n=i("shopFollowButton.continueGeneric");return f(I,{onDismiss:t,popupDisabled:!0,variant:"follow",visible:a,children:f("div",{className:"m-auto p-6 font-sans",children:[f("div",{className:"relative m-auto pb-4 text-center",children:[f("h2",{className:"mb-2 px-6 text-subtitle text-black",children:e}),f("p",{className:"overflow-hidden text-ellipsis whitespace-pre-line text-body-small text-grayscale-d1",children:o})]}),f("div",{className:"flex justify-center",children:f("button",{className:"w-full rounded-md bg-purple-primary p-3 leading-6 text-white no-underline",onClick:function(){l({userAction:"FOLLOWING_GET_SHOP_APP_CLICK"}),s.open(v,"_self"),t()},type:"button",children:n})})]})})}const g=null!==(r=i("shopFollowButton.followingModal.qrAltText"))&&void 0!==r?r:"";let w=c?`https://shop.app/qr/sid/${c}`:"#";return o&&(w="https://shop.app/qr/sid/59659354134"),f(I,{anchorTo:e,disableMinWidth:!0,hideHeader:!0,onDismiss:t,popupDisabled:!0,variant:"follow",visible:a,children:f("div",{className:"m-auto w-55 p-6 font-sans",children:[f("div",{className:"relative m-auto pb-4 text-center",children:f("p",{className:"overflow-hidden text-ellipsis whitespace-pre-line text-grayscale-d1",children:i("shopFollowButton.followingModal.qrHeader",{store:d})})}),f("div",{className:"m-auto w-37 bg-white forced-color-adjust-none",children:f("img",{src:w,alt:g})}),f("div",{className:"flex justify-center px-0 pb-0 pt-4 text-purple-primary",children:f(m,{className:"h-5"})})]})})}function M({className:e,filled:o}){return f("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",children:f("path",{fill:o?"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 k=({clientId:h,devMode:v=!1,storefrontOrigin:g})=>{const{trackPageImpression:w,trackUserAction:I}=u(),{translate:F}=p(),k=N(),{notify:S}=a(),E=b(null),T=b(null),[A,B]=function({key:r,type:l="localStorage",defaultValue:i}){const s=`signInWithShop:${r}`,[a,c]=e((()=>{const e=n(s,{session:"sessionStorage"===l});if(!e)return i;try{return JSON.parse(e)}catch(e){return i}}));return[a,o((e=>{c(e),t(s,JSON.stringify(e),{session:"sessionStorage"===l})}),[s,l])]}({key:"following",defaultValue:!1}),[P,W]=e(!1),[j,D]=e(!1),G=function(e){const{recordCounter:o}=r();return l((()=>{try{if(e&&i(e))return e}catch(e){e instanceof Error&&o("shop_js_invalid_storefront_origin",{attributes:{error:e}})}return s.location.origin}),[e,o])}(g),[q,H]=e();c((()=>{w({page:A?"COMPONENT_LOADED_FOLLOWING":"COMPONENT_LOADED_NOT_FOLLOWING"})}),[A,w]),c((()=>{if(!E.current||void 0===w||!x())return;const e=new IntersectionObserver((o=>{for(const{isIntersecting:t}of o)t&&(null==e||e.disconnect(),w({page:"FOLLOW_BUTTON_SHOWN_IN_VIEWPORT"}))}));return e.observe(E.current),()=>{e.disconnect()}}),[w]);const z=o((()=>{var e;return A?(w({page:"FOLLOWING_GET_SHOP_APP_CTA"}),W(!0)):(I({userAction:"FOLLOW_ON_SHOP_CLICKED"}),v?B(!0):(D(!0),void(null===(e=T.current)||void 0===e||e.open("user_button_clicked"))))}),[v,A,B,w,I]);const U=_("absolute inset-y-0 -z-10 rounded-max bg-purple-primary",A?"w-9 animate-follow":"w-full group-hover_bg-purple-d0"),V=_("group relative inline-flex h-9 items-center rounded-max bg-transparent",A&&"gap-x-1-5"),$=_("cursor-pointer whitespace-nowrap pr-3 font-sans text-button-large transition-colors",A?"text-black":"text-white"),R=A?"shopFollowButton.following":"shopFollowButton.follow",{authorizeUrl:J}=O({clientId:h,error:q,flow:"follow",proxy:!0,redirectType:"iframe",responseType:"code"}),K=j?f(C,{onClose:()=>W(!1),onComplete:function(e){return d(this,arguments,void 0,(function*({loggedIn:e,shouldFinalizeLogin:o,email:t}){e&&o&&(yield y(G,(e=>{S(new Error(e))}))),k("completed",{loggedIn:e,email:t}),B(!0),D(!1),W(!1)}))},onError:function({code:e,email:o,message:t}){var n;k("error",{code:e,email:o,message:t}),"retriable_server_error"===e&&(q===e&&(null===(n=T.current)||void 0===n||n.reload()),H("retriable_server_error"))},onLoaded:function(){var e;!A&&j&&(null===(e=T.current)||void 0===e||e.open("user_button_clicked"))},proxy:!0,ref:T,src:J,storefrontOrigin:G,variant:"follow"}):null,Q=A&&P&&G?f(L,{anchorElement:E,devMode:v,onClose:()=>W(!1),storefrontOrigin:G}):null;return f("div",{className:"relative z-0",children:[f("button",{className:V,onClick:z,type:"button",ref:E,children:[f("div",{className:U}),f("div",{className:"px-2 text-white",children:f(M,{className:"size-5",filled:A})}),f("span",{className:$,children:F(R,{shop:f(m,{className:"relative inline-block h-4 w-auto"})})})]}),K,Q]})},S=e=>d(void 0,void 0,void 0,(function*(){return{shopFollowButton:{follow:"Seguir en {shop}",following:"Siguiendo en {shop}",continueGeneric:"Continuar",followingModal:{title:"Visitar {store} en Shop",subtitle:"Todo lo que necesitas para comprar, hacer seguimientos y efectuar pagos desde un único lugar.",qrHeader:"Escanear para visitar {store} en la aplicación Shop",qrAltText:"Código QR de la aplicación Shop"}}}}));v((e=>{var{devMode:o,element:t}=e,n=g(e,["devMode","element"]);return f(w,{devMode:o,element:t,monorailProps:{analyticsContext:"loginWithShopFollow",flow:"follow"},featureName:"ShopFollowButton",getFeatureDictionary:S,children:f(k,Object.assign({},n,{devMode:o}))})}),{name:"shop-follow-button",props:{clientId:"string",devMode:"boolean",storefrontOrigin:"string"},shadow:"open"}); //# sourceMappingURL=client.shop-follow-button_HF45h596.es.esm.js.map