(function(a){let b,c,d=a(document),e=0;"undefined"!=typeof elementor&&elementor.hooks.addAction("panel/open_editor/widget/form",(a,d,e)=>{c=e.getContainer(),b=e.model.id}),d.on("click",".elementor_ap_google_sheet_credentials_validate button",function(b){b.preventDefault();const d=a(this);let j=a(".elementor_ap_google_sheet_client_id input").val(),k=a(".elementor_ap_google_sheet_client_secret input").val(),l=a(".ap-google-sheet-redirect-uri").text();f(d),i("https://accounts.google.com/o/oauth2/v2/auth?client_id="+j+"&redirect_uri="+l+"&scope="+"https://www.googleapis.com/auth/spreadsheets"+"&access_type=offline&include_granted_scopes=true&state=state_parameter_passthrough_value&response_type=code&prompt="+"consent").then(function(b){b?a.ajax({type:"POST",url:"https://accounts.google.com/o/oauth2/token",contentType:"application/x-www-form-urlencoded; charset=utf-8",dataType:"json",data:{client_id:j,client_secret:k,code:b,redirect_uri:l,grant_type:"authorization_code"},success:function(b){var f=Math.round;b.refresh_token&&("undefined"==typeof c?(a("#elementor_ap_google_sheet_access_token").val(b.access_token),a("#elementor_ap_google_sheet_refresh_token").val(b.refresh_token),a("#elementor_ap_google_sheet_expires_in").val(f(new Date().getTime()/1e3)+b.expires_in)):$e.run("document/elements/settings",{container:c,settings:{ap_google_sheet_access_token:b.access_token,ap_google_sheet_refresh_token:b.refresh_token,ap_google_sheet_expires_in:f(new Date().getTime()/1e3)+b.expires_in}}),g(d),e=1)}}):h(d)})}),d.on("change","[data-setting=\"ap_google_sheet_url\"]",function(){$e.run("document/elements/settings",{container:c,settings:{ap_google_sheet_id:/\/spreadsheets\/d\/([a-zA-Z0-9-_]+)/.exec(a("[data-setting=\"ap_google_sheet_url\"]").val())[1]}})});const f=function(b){b.removeClass("success error").addClass("loading"),a("i",b).removeClass("fa-check fa-close").addClass("fa-spin")},g=function(b){b.removeClass("loading success").addClass("success"),a("i",b).removeClass("fa-refresh fa-spin fa-close").addClass("fa-check").css("color","green")},h=function(b){b.removeClass("loading success").addClass("error"),a("i",b).removeClass("fa-refresh fa-spin fa-check").addClass("fa-close").css("color","red")},i=function(b){let c=a.Deferred();const d=450,e=window.top.outerHeight/2+window.top.screenY-300,f=window.top.outerWidth/2+window.top.screenX-d/2;let g=window.open(b,"_blank",`width=${d}, height=${600}, top=${e}, left=${f}`),h=window.setInterval(function(){try{let a=g.document.URL;if(-1!==a.indexOf("code")){window.clearInterval(h),g.close();let b=j(a,"code");c.resolve(b)}else-1!==g.document.URL.indexOf("error")&&(window.clearInterval(h),g.close(),c.resolve())}catch(a){}g.closed&&(window.clearInterval(h),c.resolve())},100);return c},j=function(a,b){b=b.replace(/[[]/,"[").replace(/[]]/,"]");let c="[?&]"+b+"=([^&#]*)",d=new RegExp(c),e=d.exec(a);return decodeURIComponent(e[1])};window.onbeforeunload=function(){if(1===e)return"New information not saved. Do you wish to leave the page?"},d.on("click","#elementor-panel-saver-button-publish-label",function(){e=0}),a("input[name='submit']").on("click",function(){e=0})})(jQuery);