!function(){function t(){if(null===c)try{c=globalThis.parent&&globalThis.parent!==globalThis?globalThis.parent.window?.FleekDash?.debug||globalThis.FleekDash?.debug||!1:globalThis.FleekDash?.debug||!1}catch{c=globalThis.FleekDash?.debug||!1}return c}function e(){t()}function n(){t()}function i(){try{return new URL(globalThis.location.href).pathname.includes("plugin-install.php")}catch{return globalThis.location.href.includes("plugin-install.php")}}function a(t){const e=t.getAttribute("data-slug");if(e&&""!==String(e).trim())return String(e).trim();const n=t.getAttribute("href");if(!n)return null;try{const t=new URL(n,globalThis.location.href).searchParams.get("plugin");if(t&&""!==t.trim())return t.trim()}catch{return null}return null}function o(t){return new Promise(function(e){globalThis.setTimeout(e,t)})}function l(t){if(!i())return;if(!wpApiSettings||!wpApiSettings.root||!wpApiSettings.nonce)return;const l=t.target&&t.target.closest?t.target.closest("a"):null;if(!function(t){return!(!t||"A"!==t.tagName||!t.classList.contains("install-now")||!(t.getAttribute("href")||"").includes("action=install-plugin")||null===a(t))}(l))return;if(t.defaultPrevented)return;if(0!==t.button)return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return;if(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),u)return;u=!0;const r=a(l),s=(l.getAttribute("data-name")||"").replace(/\s+/g," ").trim()||r;e(),async function(i,a){const l=new UpdateOverlay({title:"Plugin Installation"});let r;l.show(),l.addMessage("Starting installation for "+(a||i)+"...","info","download");try{r=await fetch(wpApiSettings.root+"fleekdash/v1/plugin-directory/install",{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":wpApiSettings.nonce,"Content-Type":"application/json"},body:JSON.stringify({slug:i,activate:!1})})}catch(t){return n(),l.addMessage("Could not start installation: "+(t&&t.message?t.message:"network error"),"error"),await o(3500),void globalThis.location.reload()}let s=null;try{s=await r.json()}catch{s=null}if(!r.ok||!s){const t=s&&(s.message||s.code)||"HTTP "+r.status;return l.addMessage("Installation request failed: "+String(t),"error"),await o(4e3),void globalThis.location.reload()}if(!s.job_id||!s.status)return l.addMessage("Invalid install response from server.","error"),await o(4e3),void globalThis.location.reload();const c=s.status,u=c.state,h="string"==typeof c.step?c.step:"",d="number"==typeof c.progress?c.progress:0;if(l.setActiveStepFraction(Math.min(1,Math.max(0,d/100))),"complete"===u)return l.setActiveStepFraction(1),l.addMessage(h||s.message||"Plugin installed successfully","success","complete"),await o(2500),void function(t){let i;try{const t=g?new URL(globalThis.parent.location.href).origin+"/wp-admin/":new URL(globalThis.location.href).origin+"/wp-admin/";i=t+"?page=fleekdash#/plugins"}catch(a){n();const t=document.referrer&&""!==document.referrer?new URL(document.referrer).origin:new URL(globalThis.location.href).origin;i=t+"/wp-admin/?page=fleekdash#/plugins"}if(t&&"function"==typeof t.hide&&t.hide(),g&&globalThis.parent&&globalThis.parent!==globalThis){const t=function(){try{if(globalThis.parent&&globalThis.parent!==globalThis&&globalThis.parent.location&&globalThis.parent.location.origin)return globalThis.parent.location.origin}catch{}return"*"}();e();try{"*"!==t&&globalThis.parent.postMessage({type:"FLEEKDASH_REDIRECT",url:i},t)}catch(o){n()}return void globalThis.setTimeout(function(){e(),function(t){try{globalThis.open(t,"_top")||(globalThis.location.href=t)}catch{globalThis.location.href=t}}(i)},2e3)}globalThis.location.href=i}(l);if("failed"===u||!1===s.success){const t=c.error?String(c.error):h||s.message||"Installation failed";return l.addMessage(String(t),"error"),await o(4500),void globalThis.location.reload()}l.addMessage(s.message||"Installation ended with unexpected status: "+String(u),"warning"),await o(3500),globalThis.location.reload()}(r,s).finally(function(){u=!1})}function r(){globalThis[s]||i()&&(wpApiSettings&&wpApiSettings.root&&wpApiSettings.nonce?(globalThis[s]=!0,globalThis.addEventListener("click",l,!0),e()):n())}const s="__fleekdashPluginDirectoryInstallBound",g=globalThis.parent!==globalThis;let c=null,u=!1;r(),globalThis[s]||"loading"!==document.readyState||document.addEventListener("DOMContentLoaded",r)}();
//# sourceMappingURL=plugin-directory-install.js.map
