(()=>{var e,n,o,i,t,a,r,d,s,c,u,l,p,g,w,f,h,m;window.centaurPiano=window.centaurPiano||{redirectTo:!1,loginReload:"enabled",ajaxUrl:!1,checkSync:!1,logged_in:!1,reset_token:!1},window.centaurPiano.controls=(n=new Event("pianoLoginSuccess"),o=function(e){"no"!==centaurPiano.loginReload&&(e=void 0===e?centaurPiano.redirectTo:e,window.location.href===e?window.location.reload():window.location.replace(e))},i=function(e){pianoLoaded.then((()=>{if(!window.tp.user.isUserValid()&&!window.centaurPiano.logged_in)return console.error("Nothing to do!",e),!1;let n={method:"POST",headers:{Accept:"application/json"},body:new URLSearchParams};n.body.append("nonce",window.centaurPiano.nonce),n.body.append("uid",void 0===e.uid?window.tp.user.getProvider().getUser().uid:e.uid),n.body.append("token",void 0===e.token?window.tp.user.getProvider().getToken():e.token),n.body.append("action",void 0===e.action?window.centaurPiano.logged_in?"piano_profile_update":"piano_login":e.action),fetch(window.centaurPiano.ajaxUrl,n).then((e=>e.json())).then((n=>{if(200!==n.status)throw new Error(n.message?n.message:"Unknown error");"function"==typeof e.success&&e.success(n)})).catch("function"==typeof e.failure?e.failure:console.error)})).catch(console.error)},t=async function(){let e=new Promise((function(e,n){window.tp.pianoId.isUserValid()?e(window.tp.pianoId.getToken()):window.centaurPiano.logged_in?i({action:"piano_relog",token:!1,uid:!1,success:function(o){o&&o.user_token?e(o.user_token):n("Authentication token invalid",o)},failure:function(e){n(e.message?e.message:"Error collecting authentication token",e)}}):n("No token available")}));return await e},a=(e,n,o)=>new Promise(((i,t)=>e().then(i).catch((r=>n>1?(e=>new Promise((n=>setTimeout(n,e))))(o).then(a.bind(null,e,n-1,o)).then(i).catch(t):t(r))))),r=!1,d=async function(e){return console.debug("Starting Piano login"),window.tp.pianoId.loginByToken(e),await async function(){let e=0;return a((()=>window.tp.user.isUserValid()?r?Promise.resolve({msg:"Login by token process completed",state:!0}):(console.debug("Waiting for login process to complete",++e),Promise.reject()):(console.debug("Login failed",++e),Promise.resolve({msg:"Login failed",state:!1}))),300,100)}().then((e=>e.state?Promise.resolve(e.msg):Promise.reject(e.msg)))},s={loginSuccess:function(){console.debug("Piano: Login success."),r=!0,window.centaurPiano.logged_in?(console.debug("Piano: Login complete event triggering."),window.dispatchEvent(n)):window.tp.user.isUserValid()&&(console.debug("Piano: Not logged into service provider."),i({action:"piano_login",success:()=>{console.debug("Piano: Service provider logged in."),o()},failure:e=>{console.debug("Piano: Failed to log in to service provider."),!0===confirm(e.message+"\n\nDo you want to reload the page and try again?")&&(window.tp.user.logout(),window.location.reload())}}))},loginFailed:e=>{console.debug("Piano: Login failed",e)},loginRequired:function(){console.debug("Piano: Login required."),w()},loggedOut:function(){console.debug("Piano: Logged out."),window.centaurPiano.logged_in&&i({action:"piano_logout",token:!1,uid:!1,success:()=>o})},profileUpdate:function(){console.debug("Piano: Profile update."),i({action:"piano_profile_update"})},onShow:function(){var e,n=document.querySelectorAll(".pianoLoading");for(e=0;e0?"new_password":"restore",{})}),!0)})).catch(console.error)},w=function(){pianoLoaded.then((function(){l("tinypassRegister",(function(e){return p(e,"login",{})}),!0)})).catch(console.error)},f={running:!1,elements:[],watch:function(){for(var e in f.elements)if(f.elements.hasOwnProperty(e)&&(i=f.elements[e],t=void 0,a=void 0,t=i.getBoundingClientRect(),a=Math.max(document.documentElement.clientHeight,window.innerHeight),!(t.bottom<0||t.top-a>=0))){var n=void 0!==f.elements[e].dataset.pianoScreen&&f.elements[e].dataset.pianoScreen,o=void 0!==f.elements[e].dataset.pianoArgs&&JSON.parse(f.elements[e].dataset.pianoArgs);l("tinypass"+n,function(e,n){return function(o){return p(o,e,n)}}(n,o)),f.elements.splice(e,1)}var i,t,a;0===f.elements.length&&(f.running=!1,window.removeEventListener("scroll",f.watch))},addElement:function(e){f.elements.push(e),f.running||window.addEventListener("scroll",f.watch)}},h=function(e){var n,o="abcdefghijklmnopqrstuvwxyz",i="",t=e/4;for(n=0;n{var n,o=document.querySelectorAll("[data-piano-screen]");for(window.tp.pianoId.init(s),window.centaurPiano.checkSync&&window.tp.user.isUserValid()&&i({action:"piano_profile_update"}),window.centaurPiano.logged_in&&!window.tp.user.isUserValid()&&(console.debug("Login disconnection"),t().then((e=>a((()=>(console.debug("Trying to login with token"),d(e))),5,2e3))).then(console.debug).catch((e=>{console.error("Piano: Authentication token login failure.",e),i({action:"piano_logout",token:!1,uid:!1,success:m})}))),document.addEventListener("keyup",(function(n){"Escape"===n.key&&void 0!==e&&(n.stopPropagation(),e.remove())})),n=0;n0?c.time:1,setTimeout(function(e,n){return function(){l("tinypass"+e.dataset.pianoScreen,(function(o){return p(o,e.dataset.pianoScreen,n)}))}}(r,c),1e3*c.time);break;case"scroll":f.addElement(r)}else r.addEventListener("click",(function(){window.tp.user.isUserValid()&&window.tp.pianoId.logout()}))}})).catch(console.error),{createModal:l,showMyAccount:function(){pianoLoaded.then((function(){l("tinypassMyAccount",(function(e){return p(e,"myaccount",{})}))})).catch(console.error)},showRegistration:function(){pianoLoaded.then((function(){l("tinypassRegister",(function(e){return p(e,"register",{})}),!0)})).catch(console.error)},showPasswordRecover:g,showNewPassword:g,showLogin:w,showOffer:function(e,n,o){pianoLoaded.then((function(){l("tinypassRegister",(function(i){return p(i,"offer",{offer:e,templateId:n,terms:o})}))})).catch(console.error)},show:p,getAuthToken:t}),"remove"in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)})})(); //# sourceMappingURL=centaurpiano.min.js.map