import{d as e,q as o,at as t,ap as n,t as r,T as l,av as i,i as s,B as a,o as c,y as d,s as u,g as p,a1 as h,u as f,x as m,I as v,_ as g,R as w,p as N,A as b,n as _,U as O,l as y,aw as x}from"./chunk.common_CKtMJpz4.esm.js";import{M as k,A as I}from"./chunk.modal_DmDXaa6V.esm.js";function L(e,o){return a(this,void 0,void 0,(function*(){try{const t=yield fetch(e,o);return"ok"in t&&!t.ok?null:function(e){return a(this,void 0,void 0,(function*(){try{return e&&"function"==typeof e.json?yield e.json():null}catch(e){return null}}))}(t)}catch(e){return null}}))}function C(o){var t;const{notify:n}=c(),[r,l]=e(null),[i,s]=e(!1);d((()=>{(()=>{a(this,void 0,void 0,(function*(){const e=yield function(){return a(this,arguments,void 0,(function*(e=location.origin){return L(`${e}/meta.json`)}))}(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 F({anchorElement:e,devMode:o,onClose:t,storefrontOrigin:n}){var r;const{trackUserAction:l}=u(),{translate:i}=p(),{loaded:a,storeId:c,storeName:d}=C(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(k,{headerLogo:f(m,{className:"h-4-5 text-purple-primary"}),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(k,{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 S=({clientId:h,devMode:v=!1,storefrontOrigin:g})=>{const{trackPageImpression:w,trackUserAction:k}=u(),{translate:L}=p(),C=N(),{notify:S}=c(),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,j]=e(!1),[W,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();d((()=>{w({page:A?"COMPONENT_LOADED_FOLLOWING":"COMPONENT_LOADED_NOT_FOLLOWING"})}),[A,w]),d((()=>{if(!E.current||void 0===w||!y())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"}),j(!0)):(k({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,k]);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=W?f(I,{onClose:()=>j(!1),onComplete:function(e){return a(this,arguments,void 0,(function*({loggedIn:e,shouldFinalizeLogin:o,email:t}){e&&o&&(yield x(G,(e=>{S(new Error(e))}))),C("completed",{loggedIn:e,email:t}),B(!0),D(!1),j(!1)}))},onError:function({code:e,email:o,message:t}){var n;C("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&&W&&(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(F,{anchorElement:E,devMode:v,onClose:()=>j(!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:L(R,{shop:f(m,{className:"relative inline-block h-4 w-auto"})})})]}),K,Q]})},E=e=>a(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:E,children:f(S,Object.assign({},n,{devMode:o}))})}),{name:"shop-follow-button",props:{clientId:"string",devMode:"boolean",storefrontOrigin:"string"},shadow:"open"}); //# sourceMappingURL=client.shop-follow-button_CeYn8ylL.es.esm.js.map