(()=>{const{ajaxurl:e,academy_nonce:o}=window.AcademyGlobal||{},i={socialLoginDom:"",init(){this.socialLoginDom=this.getElements(".academy-social-login"),this.socialLoginDom&&(this.facebookLogIn(),this.googleLogIn())},getElements:e=>document.querySelector(e),facebookLogIn(){window.academy_pro_is_loggedIn_facebook=!1;const i=this.socialLoginDom.querySelector(".academy-social-login__status"),n=this.socialLoginDom.querySelector(".academy-social-login__facebook");n&&(n.addEventListener("click",function(){academy_pro_is_loggedIn_facebook||FB.login(function(t){t.authResponse?FB.api("/me",{fields:"id, name, first_name, last_name, email, link, gender, locale, picture"},function(t){const a=FB.getAuthResponse().userID,s=FB.getAuthResponse().accessToken;window.academy_pro_is_loggedIn_facebook=!0;const c={id:t.id,name:t.name,first_name:t.first_name,last_name:t.last_name,email:t.email,link:t.link,send_email:!0};jQuery.post(e,{action:"academy_pro_social_login/facebook_login",...c,security:o,method:"post",dataType:"json",userID:a,access_token:s,beforeSend(){n.innerHTML="Loading..."}},function(e){e.success?(n.innerHTML="Success",i.innerHTML="<div class='academy-pro-login-form-status__success'>You have logged in successfully. Redirecting…</div>"):i.innerHTML=`<div class="academy-pro-login-form-status__error">${e.data}</div>`,setTimeout(()=>{!0===e.success&&window.location.reload(!0)},1e3)})}):i.innerHTML='<div class="academy-pro-login-form-status__error"><strong>Error:</strong> User cancelled login or did not fully authorize.</div>'},{scope:"email"})}),window.fbAsyncInit=function(){const e=n.getAttribute("data-appId");FB.init({appId:e,xfbml:!0,version:"v19.0"}),FB.AppEvents.logPageView()},function(e,o,i){let n,t=e.getElementsByTagName(o)[0];e.getElementById(i)||(n=e.createElement(o),n.id=i,n.src="https://connect.facebook.net/en_US/sdk.js",t.parentNode.insertBefore(n,t))}(document,"script","facebook-jssdk"))},googleLogIn(){window.academy_pro_is_google_loggedin=!1;const i=this.socialLoginDom.querySelector(".academy-social-login__status"),n=document.getElementById("academy-social-google-login");if(n){n.addEventListener("click",function(){window.academy_pro_is_google_loggedin=!0}),google.accounts.id.initialize({client_id:n.getAttribute("data-clientId"),callback:function(t){jQuery.post(e,{action:"academy_pro_social_login/google_login",security:o,method:"post",dataType:"json",id_token:t.credential,is_register:n.getAttribute("data-isRegister"),role:n.getAttribute("data-role")},function(e){e.success?i.innerHTML=`<div class='academy-social-login__status-success'>${e.data}</div>`:i.innerHTML=`<div class="academy-social-login__status-error">${e.data}</div>`,setTimeout(()=>{!0===e.success&&window.location.reload(!0)},1e3)})},auto_select:!1,cancel_on_tap_outside:!1}),google.accounts.id.renderButton(n,{theme:"outline",size:"large",logo_alignment:"center"}),google.accounts.id.prompt()}}};jQuery(document).ready(function(){i.init(),AcademyGlobal.hooks.addAction("after_dispatch_popup_login_content","academy-pro",function(){i.init()})})})();