!function(){"use strict";document.addEventListener("DOMContentLoaded",(function(){const t=document.querySelector(".pdfp_license_popup");new e(t,{products:["pdfposter","uoGmX"],prefix:"pdfp"})}));class e{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return void console.error("modal undefined");const{products:i=[],prefix:n}=t;this.endpoint=("localhost"===window.location.host?"http://localhost/freemius":"https://bplugins.com")+"/wp-json/license/v1/gumroad",this.prefix=n,this.modal=e;const s=document.querySelector(`.${this.prefix}_modal_opener`),c=e.querySelector(".closer"),a=e.querySelector(".agree"),o=e.querySelector(".btn-activate"),l=e.querySelector(".btn-deactivate"),r=e.querySelector(".bpl_loader");this.headers={"content-Type":"application/json"},s?.addEventListener("click",(t=>{t.preventDefault(),e.style.display="block"})),c?.addEventListener("click",(t=>{t.preventDefault(),e.style.display="none"})),a?.addEventListener("click",(function(){o.disabled=!a?.checked})),o?.addEventListener("click",(async t=>{t.preventDefault(),r.style.display="inline-block",o.disabled=!0;const n=e.querySelector("input.license_key");if(n?.value){await this.activeLicense(n?.value,i)&&this.setNotice("notice-success","Plugin Activated!, Thank you")}else this.setNotice("notice-warning","Please input a license key");o.disabled=!1,r.style.display="none"})),l?.addEventListener("click",(async t=>{t.preventDefault(),r.style.display="inline-block",l.disabled=!0;const n=e.querySelector("input.license_key");if(n?.value){await this.deactiveLicense(n?.value,i)&&this.setNotice("notice-success","License key deactivated.")}l.disabled=!1,r.style.display="none"}))}verifyGumroad=(()=>{var e=this;return async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1?arguments[1]:void 0,n={};for(let e of t){let t=await fetch("https://api.gumroad.com/v2/licenses/verify",{method:"POST",headers:{"content-Type":"application/json"},body:JSON.stringify({product_permalink:e,license_key:i})}).then((e=>e.json())).then((e=>e));if(t.success){n=t;break}}const s=e.getQuantity(n),c=n?.purchase?.product_name?.includes("Sumo")||!1,a=n?.purchase?.permalink;return{quantity:s,success:n.success,permalink:a,isAppSumo:c}}})();serverHandler=async e=>{const t={quantity:1,website:window.location?.origin,product:"pdfposter",email:pdfpLicense?.email,action:"add",...e};return await fetch(this.endpoint,{method:"POST",headers:{"content-Type":"application/json"},body:JSON.stringify(t)}).then((e=>e.json())).then((e=>e))};activeLicense=async(e,t)=>{const{permalink:i,success:n,quantity:s,isAppSumo:c}=await this.verifyGumroad(t,e);if(n){const{active:t,message:i}=await this.serverHandler({license_key:e,quantity:s,isAppSumo:c});if(t){const t=new FormData;t.append("action","pdfp_active_license_key"),t.append("activated",1),t.append("license_key",e);const i=await fetch(pdfpLicense?.ajaxUrl,{method:"POST",body:t}).then((e=>e.json())).then((e=>e));return i?.success}this.setNotice("notice-warning",i)}else this.setNotice("notice-warning","Invalid License key")};deactiveLicense=async(e,t)=>{const{permalink:i,success:n,quantity:s,isAppSumo:c}=await this.verifyGumroad(t,e);if(n){if(await this.serverHandler({license_key:e,action:"deactive"})){const e=new FormData;e.append("action","pdfp_active_license_key"),e.append("activated",0),e.append("license_key","");const t=await fetch(pdfpLicense?.ajaxUrl,{method:"POST",body:e}).then((e=>e.json())).then((e=>e));return t?.success}this.setNotice("notice-warning","something went wrong!")}else this.setNotice("notice-warning","invalid license key!")};setNotice(e,t){const i=this.modal.querySelector(".license_notice"),n=document.createElement("div");n.classList=`notice ${e}`,n.innerText=t,i.appendChild(n),setTimeout((()=>{n.remove(),"notice-success"==e&&location.reload()}),3e3),setTimeout((()=>{"notice-success"==e&&location.reload()}),1e3)}getQuantity=e=>({"(Single Site)":1,"(3 Sites)":3,"(5 Sites)":5,"(Developer  - Unlimited)":1e3,"(Developer)":1e3}[e?.purchase?.variants]||1)}}();
//# sourceMappingURL=license.js.map