var __FSCheckoutGlobalInternal__=function(h){"use strict";var Z=Object.defineProperty,tt=Object.defineProperties;var et=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var U=(h,l,d)=>l in h?Z(h,l,{enumerable:!0,configurable:!0,writable:!0,value:d}):h[l]=d,L=(h,l)=>{for(var d in l||(l={}))q.call(l,d)&&U(h,d,l[d]);if(O)for(var d of O(l))W.call(l,d)&&U(h,d,l[d]);return h},Q=(h,l)=>tt(h,et(l));var j=(h,l)=>{var d={};for(var u in h)q.call(h,u)&&l.indexOf(u)<0&&(d[u]=h[u]);if(h!=null&&O)for(var u of O(h))l.indexOf(u)<0&&W.call(h,u)&&(d[u]=h[u]);return d};var a=(h,l,d)=>U(h,typeof l!="symbol"?l+"":l,d);var M=(h,l,d)=>new Promise((u,v)=>{var P=f=>{try{b(d.next(f))}catch(I){v(I)}},x=f=>{try{b(d.throw(f))}catch(I){v(I)}},b=f=>f.done?u(f.value):Promise.resolve(f.value).then(P,x);b((d=d.apply(h,l)).next())});const l={Log(...i){console&&console.log&&console.log(...i)},Error(...i){console&&console.error&&console.error(...i)},Warn(...i){console&&console.warn&&console.warn(...i)},Debug(...i){console&&console.debug&&console.debug(...i)}};function d(i,t){const e=i.contentWindow,s=i.src,r={};if(!e||!s)return null;const n=function(o){if(!(o&&o.origin&&o.origin.indexOf("js.stripe.com")>0||o.origin.indexOf("www.paypal.com")>0)&&o.origin===t&&o&&o.data&&typeof o.data=="string"&&o.data.charAt(0)==="{")try{const c=JSON.parse(o.data);typeof c=="object"&&c.type&&r[c.type]&&r[c.type].forEach(m=>{m(c.data)})}catch(c){l.Error(c)}};return window.addEventListener("message",n),{on(o,c){r[o]||(r[o]=[]),r[o].push(c)},one(o,c,m=!1){m&&delete r[o],!r[o]&&this.on(o,c)},destroy(){window.removeEventListener("message",n)},post(o,c){e.postMessage(JSON.stringify({type:o,data:c}),s.replace(/([^:]+:\/\/[^/]+).*/,"$1"))}}}const u=2147483647;function v(){const i=function(){return Math.floor((1+Math.random())*65536).toString(16).substring(1)};return i()+i()+"-"+i()+"-"+i()+"-"+i()+"-"+i()+i()+i()}function P(){let i=!1;try{const t=navigator.userAgent.toLowerCase();/edge\/|trident\/|msie /.test(t)?i=!0:t.indexOf("safari")!==-1&&(t.indexOf("chrome")>-1||(i=!0))}catch(t){}return i}function x(i){return typeof i=="undefined"||typeof i=="function"||typeof i=="object"&&i!==null}function b(i){return x(i)?null:i===null?"null":i===!0?"1":i===!1?"0":encodeURIComponent(i).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A").replace(/%20/g,"+")}function f(i){const t=[];return Object.keys(i).forEach(e=>{const s=i[e],r=b(s);r!==null&&t.push(`${e}=${r}`)}),t.join("&")}function I(i){const t={};Object.entries(i).forEach(([s,r])=>{x(r)||(t[s]=r)});const{sandbox:e}=i;return e&&e.ctx&&e.token&&(t.s_ctx_ts=e.ctx,t.sandbox=e.token),t}function V(i){return i.pageY<=20}function y(){return typeof window=="undefined"}function A(i,t){if(i==null)throw new Error(t)}function G(i){if(i===null)return!1;const t=i.toLowerCase();return t==="1"||t==="true"}class z{constructor(t){a(this,"styleElement");a(this,"bodyScrollDisableClassName");a(this,"isFlashingBrowser");a(this,"overflow",{x:0,y:0});a(this,"metaColorSchemeValue",null);a(this,"metaColorSchemeElement",null);this.guid=t,this.bodyScrollDisableClassName=`is-fs-checkout-open-${this.guid}`,this.styleElement=document.createElement("style"),this.styleElement.textContent+=this.getBasicStyle(),this.isFlashingBrowser=P()||!y()&&!!document.querySelector("#___gatsby"),this.metaColorSchemeElement=document.head.querySelector('meta[name="color-scheme"]')}addStyle(t){this.styleElement.textContent+=t}attach(){return document.head.appendChild(this.styleElement),this}remove(){return document.head.contains(this.styleElement)&&document.head.removeChild(this.styleElement),this}disableBodyScroll(){this.backupScrollPosition(),document.body.classList.add(this.bodyScrollDisableClassName)}enableBodyScroll(){document.body.classList.remove(this.bodyScrollDisableClassName),this.restoreScrollPosition()}disableMetaColorScheme(){this.metaColorSchemeElement&&(this.metaColorSchemeValue=this.metaColorSchemeElement.getAttribute("content"),this.metaColorSchemeElement.setAttribute("content","light"))}enableMetaColorScheme(){this.metaColorSchemeElement&&this.metaColorSchemeValue&&(this.metaColorSchemeElement.setAttribute("content",this.metaColorSchemeValue),this.metaColorSchemeValue=null)}getBasicStyle(){return`body.${this.bodyScrollDisableClassName} { overflow: hidden !important; }`}backupScrollPosition(){this.overflow={x:document.documentElement.scrollTop,y:document.documentElement.scrollLeft}}restoreScrollPosition(){document.documentElement.scrollTop=this.overflow.x,document.documentElement.scrollLeft=this.overflow.y}}const S=class S{constructor(t,e,s="Loading Freemius Checkout"){a(this,"loaderElement");a(this,"isOpen",!1);a(this,"loaderElementId");this.style=t,this.loaderElementId=`fs-loader-${this.style.guid}`,this.loaderElement=document.createElement("div"),this.loaderElement.id=this.loaderElementId,this.loaderElement.innerHTML=`<img src="${e}" alt="${s}" />`,this.style.addStyle(this.getStyle())}show(){return this.isOpen?this:(this.loaderElement.classList.add("show"),document.body.appendChild(this.loaderElement),this.isOpen=!0,this)}hide(){return this.isOpen?(this.loaderElement.classList.remove("show"),this.isOpen=!1,setTimeout(()=>{this.hideImmediate()},S.TRANSITION_TIME),this):this}hideImmediate(){return this.loaderElement.parentNode&&(this.loaderElement.classList.remove("show"),this.loaderElement.parentNode.removeChild(this.loaderElement),this.isOpen=!1),this}getStyle(){return`#${this.loaderElementId} { display: none; position: fixed; z-index: ${u-1}; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; text-align: left; background: rgba(0, 0, 0, 0.6); transition: opacity ${S.TRANSITION_TIME}ms ease-out; will-change: opacity; opacity: 0; } #${this.loaderElementId}.show { opacity: 1; display: block; } #${this.loaderElementId} img { position: absolute; top: 40%; left: 50%; width: auto; height: auto; margin-left: -25px; background: #fff; padding: 10px; border-radius: 50%; box-shadow: 2px 2px 2px rgba(0,0,0,0.1); }`}};a(S,"TRANSITION_TIME",200);let D=S;const w=class w{constructor(t,e,s,r,n){a(this,"postman",null);a(this,"iFrame");a(this,"iFrameWrapper");a(this,"loadedEventListeners",new Set);a(this,"closedEventListeners",new Set);this.baseUrl=t,this.visibleClass=r,this.checkoutOptions=n;const{iFrame:o,iFrameWrapper:c}=this.attachIFrame(t,e,s);this.iFrame=o,this.iFrameWrapper=c,this.addEventListeners()}static getWrapperID(t){return`${t}-wrapper`}close(){var t;(t=this.postman)==null||t.post("close",null)}onClosed(t){this.closedEventListeners.add(t)}onLoaded(t){this.loadedEventListeners.add(t)}addToExitIntent(t){t.addListener(()=>{var e,s,r;(e=this.postman)==null||e.post("exit_intent",null),(r=(s=this.checkoutOptions).onExitIntent)==null||r.call(s)})}attachIFrame(t,e,s){var m;const r=`${t}/?${f(e)}#${encodeURIComponent(document.location.href)}`,n=document.createElement("iframe");n.id=s,n.src=r,n.setAttribute("allowTransparency","true"),n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.setAttribute("style","background: rgba(0,0,0,0.003); border: 0 none transparent;"),n.setAttribute("frameborder","0"),n.setAttribute("data-testid",n.id);const o=(m=this.checkoutOptions.modal_title)!=null?m:w.DEFAULT_TITLE;n.setAttribute("title",o);const c=document.createElement("div");return c.setAttribute("role","dialog"),c.setAttribute("aria-label",o),c.setAttribute("aria-modal","true"),c.setAttribute("data-testid",`${n.id}-wrapper`),c.id=w.getWrapperID(s),c.appendChild(n),document.body.appendChild(c),{iFrame:n,iFrameWrapper:c}}addEventListeners(){var c,m,F,C,R;const{success:t,purchaseCompleted:e,cancel:s,track:r,afterOpen:n,afterClose:o}=this.checkoutOptions;this.postman=d(this.iFrame,this.baseUrl),(c=this.postman)==null||c.one("upgraded",p=>{try{t==null||t(p)}catch(g){l.Error(g)}this.dispatchOnClosed(),this.removeIFrameAndPostman(),o==null||o()},!0),(m=this.postman)==null||m.one("purchaseCompleted",p=>{try{e==null||e(p)}catch(g){l.Error(g)}},!0),(F=this.postman)==null||F.one("canceled",()=>{try{s==null||s()}catch(p){l.Error(p)}this.dispatchOnClosed(),this.removeIFrameAndPostman(),o==null||o()},!0),(C=this.postman)==null||C.on("track",p=>{try{r==null||r(p.event,p)}catch(g){l.Error(g)}}),(R=this.postman)==null||R.one("loaded",()=>{var p;this.dispatchOnLoaded(),(p=this.iFrame)==null||p.classList.add(this.visibleClass);try{n==null||n()}catch(g){l.Error(g)}},!0)}removeIFrameAndPostman(){var t;(t=this.postman)==null||t.destroy(),this.postman=null,this.iFrame.remove(),this.iFrameWrapper.remove(),this.closedEventListeners.clear(),this.loadedEventListeners.clear()}dispatchOnLoaded(){this.loadedEventListeners.forEach(t=>t())}dispatchOnClosed(){this.closedEventListeners.forEach(t=>t())}};a(w,"DEFAULT_TITLE","Checkout");let k=w;const _=class _{constructor(t,e,s){a(this,"iFrameID");this.style=t,this.options=e,this.baseUrl=s,this.iFrameID=`fs-checkout-page-${this.style.guid}`}create(t){const e=L(L({},this.options),t);return new k(this.baseUrl,this.getQueryParams(e),this.iFrameID,_.VISIBLE_CLASS,e)}addStyle(){this.style.addStyle(this.getStyle())}getQueryParams(t){return L({mode:"dialog",guid:this.style.guid,_fs_checkout:!0},I(t))}getStyle(){return`#${this.iFrameID} { z-index: ${u-1}; background: rgba(0,0,0,0.003); border: 0 none transparent; visibility: ${this.style.isFlashingBrowser?"hidden":"visible"}; margin: 0; padding: 0; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; -webkit-tap-highlight-color: transparent; overflow: hidden; } #${this.iFrameID}.${_.VISIBLE_CLASS} { visibility: visible; } #${k.getWrapperID(this.iFrameID)} { z-index: ${u-1}; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; overflow: hidden; }`}};a(_,"VISIBLE_CLASS","show");let T=_;class H{constructor(t,e,s,r,n){a(this,"checkoutIFrameBuilder");a(this,"checkoutIFrame",null);a(this,"lastFocusedElement",null);this.style=t,this.exitIntent=e,this.loader=s,this.checkoutIFrameBuilder=new T(this.style,n,r),this.checkoutIFrameBuilder.addStyle()}isOpen(){return this.checkoutIFrame!==null}open(t){return this.isOpen()?this:(this.backupFocusedElement(),this.style.attach(),this.style.disableBodyScroll(),this.style.disableMetaColorScheme(),this.loader.show(),this.exitIntent.attach(),this.checkoutIFrame=this.checkoutIFrameBuilder.create(t),this.checkoutIFrame.onLoaded(this.onLoaded.bind(this)),this.checkoutIFrame.onClosed(this.onClosed.bind(this)),this.checkoutIFrame.addToExitIntent(this.exitIntent),this)}close(){var t;return(t=this.checkoutIFrame)==null||t.close(),this.loader.hideImmediate(),this}onLoaded(){this.loader.hide()}onClosed(){this.checkoutIFrame=null,this.loader.hide(),this.style.enableBodyScroll(),this.style.enableMetaColorScheme(),this.exitIntent.detach(),this.restoreFocusedElement(),this.style.remove()}backupFocusedElement(){var t;this.lastFocusedElement=(t=document.activeElement)!=null?t:null}restoreFocusedElement(){var t,e;this.lastFocusedElement&&((e=(t=this.lastFocusedElement).focus)==null||e.call(t),this.lastFocusedElement=null)}}class K{constructor(t){a(this,"exitIntentId");a(this,"exitIntentDiv",null);a(this,"clearExitIntentListener",null);a(this,"listeners",[]);this.style=t,this.exitIntentId=`fs-exit-intent-${this.style.guid}`,this.style.addStyle(this.getStyle())}isAttached(){return this.exitIntentDiv!==null}addListener(...t){this.listeners.push(...t)}attach(...t){if(t&&this.addListener(...t),this.isAttached())return this;this.exitIntentDiv=document.createElement("div"),this.exitIntentDiv.id=this.exitIntentId,document.body.appendChild(this.exitIntentDiv);const e=document.documentElement;let s=null;const r=300,n=c=>{V(c)&&(s=window.setTimeout(()=>{try{this.fireListeners()}catch(m){l.Error(m)}},r))},o=()=>{s&&(clearTimeout(s),s=null)};return e.addEventListener("mouseleave",n),e.addEventListener("mouseenter",o),this.clearExitIntentListener=()=>{s&&(clearTimeout(s),s=null),e.removeEventListener("mouseleave",n),e.removeEventListener("mouseenter",o)},this}detach(){var t,e;return this.isAttached()?((t=this.exitIntentDiv)==null||t.remove(),this.exitIntentDiv=null,(e=this.clearExitIntentListener)==null||e.call(this),this):this}fireListeners(){this.listeners.forEach(t=>{t()})}getStyle(){return`#${this.exitIntentId} { z-index: ${u}; border: 0; background: transparent; position: fixed; padding: 0; margin: 0; height: 10px; left: 0; right: 0; width: 100%; top: 0; }`}}const E=class E{constructor(t){a(this,"queryParams",null);this.url=t,this.queryParams=this.parseQueryStringForCart()}hasCart(){return this.queryParams!==null}getPluginID(){return A(this.queryParams,E.NO_CART_FOUND_MESSAGE),this.queryParams.__fs_plugin_id}getPluginPublicKey(){return A(this.queryParams,E.NO_CART_FOUND_MESSAGE),this.queryParams.__fs_plugin_public_key}matchesPluginID(t){const e=Number.parseInt(this.getPluginID(),10),s=Number.parseInt(t.toString(),10);return Number.isFinite(e)&&Number.isFinite(s)&&e===s}getCheckoutOptions(){A(this.queryParams,E.NO_CART_FOUND_MESSAGE);const t={plugin_id:"",public_key:""};return Object.entries(this.queryParams).forEach(([e,s])=>{e==="__fs_plugin_id"?t.plugin_id=s:e==="__fs_plugin_public_key"?t.public_key=s:t[e]=s}),t}parseQueryStringForCart(){const t="__fs_authorization",e=new URLSearchParams(this.url.search);if(!e.has(t))return null;const s={};return e.forEach((r,n)=>{n.startsWith("__fs_")&&(s[n]=r)}),s}};a(E,"NO_CART_FOUND_MESSAGE","No cart was found");let N=E;const B="https://checkout.freemius.com",J="http://checkout.freemius-local.com:8080";class ${constructor(t,e=!0,s=null){a(this,"options",{plugin_id:0,public_key:""});a(this,"guid");a(this,"baseUrl");a(this,"style");a(this,"loader");a(this,"checkoutPopup");a(this,"exitIntent");a(this,"cart");var F,C;this.baseUrl=s!=null?s:B;const m=t,{plugin_id:r,product_id:n,public_key:o}=m,c=j(m,["plugin_id","product_id","public_key"]);if(!r&&!n)throw new Error("Must provide a product_id to options.");this.options=Q(L({},c),{public_key:o,plugin_id:n!=null?n:r}),this.guid=v(),!y()&&(this.baseUrl=s!=null?s:(F=window.FS)!=null&&F.__FS__IS_TEST__?J:B,this.style=new z(this.guid),this.loader=new D(this.style,(C=t.loadingImageUrl)!=null?C:`${this.baseUrl}/assets/img/spinner.svg`,t.loadingImageAlt),this.exitIntent=new K(this.style),this.checkoutPopup=new H(this.style,this.exitIntent,this.loader,this.baseUrl,this.options),this.cart=new N(new URL(window.location.href)),e&&this.recoverCart())}open(t){return M(this,null,function*(){var e,s;if(!y()){if((e=this.checkoutPopup)!=null&&e.isOpen()){l.Warn("Checkout popup already open. Please close it first before opening it again.");return}if(document.body)(s=this.checkoutPopup)==null||s.open(t);else return new Promise(r=>{document.addEventListener("DOMContentLoaded",()=>{var n;(n=this.checkoutPopup)==null||n.open(t),r()},{once:!0})})}})}close(){var t;y()||(t=this.checkoutPopup)==null||t.close()}destroy(){y()||this.close()}getGuid(){return this.guid}recoverCart(){var t,e;if((t=this.cart)!=null&&t.hasCart()&&((e=this.cart)!=null&&e.matchesPluginID(this.options.plugin_id))){const s=this.cart.getCheckoutOptions();this.open(s)}}}class X{constructor(t){a(this,"parsedUrl",null);try{this.parsedUrl=new URL(t)}catch(e){this.parsedUrl=null}}hasDunning(){var s;if(!this.parsedUrl)return!1;const t=this.parsedUrl.searchParams.get("_fs_dunning"),e=(s=this.parsedUrl.searchParams.get("_fs_plugin_id"))!=null?s:this.parsedUrl.searchParams.get("_fs_product_id");return G(t)&&e!==null}getCheckoutOptions(){if(!this.parsedUrl)throw new Error("No dunning information found in the URL.");const t={product_id:""};return this.parsedUrl.searchParams.forEach((s,r)=>{if(r.startsWith("_fs_")){const n=r.replace("_fs_","");t[n]=s}}),Object.hasOwn(t,"plugin_id")&&(t.product_id=t.plugin_id,delete t.plugin_id),t}}function Y(i){return M(this,null,function*(){if(y())return null;const t=new X(window.location.href);if(t.hasDunning()){const e=new $(t.getCheckoutOptions());return yield e.open(i),e}return null})}return window.FS=window.FS||{},window.FS.Checkout=$,window.FS.postman=d,window.FS.Logger=l,Y(window.FS.paymentMethodUpdateEvents).catch(i=>{l.Error("Error restoring dunning checkout:",i)}),h.Checkout=$,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}),h}({});
//# sourceMappingURL=checkout.global.js.map
