jQuery(document).ready(function(r){r("#tb-manage-connection").dialog({title:"Templateberg Manage Connection",dialogClass:"wp-dialog",autoOpen:!1,draggable:!1,width:"auto",modal:!0,resizable:!1,closeOnEscape:!0,position:{my:"center",at:"center",of:window},open:function(){r(".ui-widget-overlay,#tb-connect-btn,#tb-cancel-btn,#tb-send-question-btn").bind("click",function(){r("#tb-manage-connection").dialog("close")})}}),r("#tb-open-manage-connection").click(function(e){e.preventDefault(),r("#tb-manage-connection").dialog("open")});let e=window.location.search;e.match("connecting")&&!e.match("isPopup")&&setTimeout(function(){window.location.href=templateberg.admin_url},3e3),r(".tb-accordion__header a").click(function(e){e.preventDefault();let t=r(this),a=t.attr("href");r(".tb-accordion__bodywrap").addClass("hidden"),r(a).removeClass("hidden")});let s;function c(){r.ajax({type:"GET",url:templateberg.restUrl+"templateberg/v1/is_connected",data:{},beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",templateberg.restNonce)}}).done(function(e){e&&(s&&s.close(),location.reload())}).fail(function(e,t,a){console.log(e+" :: "+t+" :: "+a)}).always(function(){})}r("#tb-connect-btn").click(function(e){var t,a,n,o,l;e.preventDefault(),t=r(this).attr("href"),a="Templateberg",n=650,o=500,l=(screen.width-n)/2,e=(screen.height-o)/4,t+="&isPopup=yes",s=window.open(t,a,"resizable=yes, width="+n+", height="+o+", top="+e+", left="+l),r.ajax({type:"POST",url:ajaxurl,data:{action:"templateberg_gutentor",security:templateberg.nonce},success:function(e){console.log(e);setInterval(c,2e3)},error:function(e,t,a){console.log(a)}})});let n=r(".tb-purchase__data");function a(e){r.ajax({type:"POST",url:templateberg.restUrl+"templateberg/v1/purchases",data:{purchases:e},beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",templateberg.restNonce)}}).done(function(e){n.html(e)}).fail(function(e,t,a){n.html("Error! Problem on your server. Refresh and try again!"),console.log(e+" :: "+t+" :: "+a)}).always(function(){})}function t(e=!1,t=1){let n=r(".tb-gutenberg-templates");let a={paged:t};e&&(a.reset=!0),r.ajax({type:"GET",url:templateberg.restUrl+"templateberg/v1/gutenberg_templates",data:a,beforeSend:function(e){r("body").addClass("tb-template-popup"),r("body").addClass("tb-template-popup-loading"),n.show(),r("#tb-list__popup_loader").show(),e.setRequestHeader("X-WP-Nonce",templateberg.restNonce)}}).done(function(e){location.reload()}).fail(function(e,t,a){n.html("Error! Problem on your server. Refresh and try again!"),console.log(e+" :: "+t+" :: "+a)}).always(function(){location.reload()})}function o(e=!1,t=1){let n=r(".tb-themes-template-kits");let a={paged:t};e&&(a.reset=!0),r.ajax({type:"GET",url:templateberg.restUrl+"templateberg/v1/theme_templates",data:a,beforeSend:function(e){r("body").addClass("tb-template-popup"),r("body").addClass("tb-template-popup-loading"),n.show(),r("#tb-list__popup_loader").show(),e.setRequestHeader("X-WP-Nonce",templateberg.restNonce)}}).done(function(e){location.reload()}).fail(function(e,t,a){n.html("Error! Problem on your server. Refresh and try again!"),console.log(e+" :: "+t+" :: "+a)}).always(function(){location.reload()})}function l(t,a){let n=window.location.href,e=new RegExp("[?|&]"+t+"=[0-9a-zA-Z_+-|.,;]*");if(e.test(n)){let e=new RegExp("[?&]"+t+"=([^&#]*)");var o=e.exec(n)[0].charAt(0);n=n.replace(e,o+t+"="+a)}else{t=t+"="+a;n.indexOf("?")||(n+="?"),-1'),d.attr("disabled",!0),d.closest(".ai-item").addClass("tb-action-importing")),u(!0)}),setTimeout(function(){let e=window.location.href,t=new RegExp("[?|&]reset=[0-9a-zA-Z_+-|.,;]*");if(t.test(e)){let e=new URL(location);e.searchParams.delete("reset"),e.searchParams.delete("from"),history.replaceState(null,null,e)}},1),"templateberg-gutenberg-templates"===i("page")?templateberg.has_templates.gutenberg_templates?r(".tb-gutenberg-templates").show():t():"templateberg-themes-template-kits"===i("page")&&("available"===i("type")?(templateberg.has_templates.available_themes?r(".tb-themes-template-kits").show():o(),m()):p()?"loaded"!==i("selected-theme")?u(!0):r(".tb-themes-template-kits").show():(templateberg.has_templates.current_theme||templateberg.has_templates.current_theme_nothing?r(".tb-themes-template-kits").show():u(!0),m()))});