!function(){function t(){if(null===d)try{d=globalThis.parent&&globalThis.parent!==globalThis?globalThis.parent.window?.FleekDash?.debug||globalThis.FleekDash?.debug||!1:globalThis.FleekDash?.debug||!1}catch{d=globalThis.FleekDash?.debug||!1}return d}function e(){t()}function n(){t()}function a(){try{return new URL(globalThis.location.href).pathname.includes("theme-install.php")}catch{return globalThis.location.href.includes("theme-install.php")}}function i(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("theme");if(t&&""!==t.trim())return t.trim()}catch{return null}return null}function s(t){return new Promise(function(e){globalThis.setTimeout(e,t)})}function l(t,e){return g?null:(g=!0,async function(t,e){!function(t){if("undefined"==typeof jQuery)return;const e=jQuery('.theme-install[data-slug="'+t+'"]');e.length&&(e.addClass("updating-message"),"Installing..."!==e.html()&&e.data("originaltext",e.html()),e.text("Installing..."))}(t);const a=new UpdateOverlay({title:"Theme Installation"});let i;a.show(),a.addMessage("Starting installation for "+(e||t)+"...","info","download");try{i=await fetch(wpApiSettings.root+"fleekdash/v1/theme-directory/install",{method:"POST",credentials:"same-origin",headers:{"X-WP-Nonce":wpApiSettings.nonce,"Content-Type":"application/json"},body:JSON.stringify({slug:t,activate:!1})})}catch(d){return n(),a.addMessage("Could not start installation: "+(d&&d.message?d.message:"network error"),"error"),await s(3500),void globalThis.location.reload()}let l=null;try{l=await i.json()}catch{l=null}if(!i.ok||!l){const t=l&&(l.message||l.code)||"HTTP "+i.status;return a.addMessage("Installation request failed: "+String(t),"error"),await s(4e3),void globalThis.location.reload()}if(!l.job_id||!l.status)return a.addMessage("Invalid install response from server.","error"),await s(4e3),void globalThis.location.reload();const o=l.status,r=o.state,u="string"==typeof o.step?o.step:"",c="number"==typeof o.progress?o.progress:0;if(a.setActiveStepFraction(Math.min(1,Math.max(0,c/100))),"complete"===r)return a.setActiveStepFraction(1),a.addMessage(u||l.message||"Theme installed successfully","success","complete"),await s(2500),void globalThis.location.reload();if("failed"===r||!1===l.success){const t=o.error?String(o.error):u||l.message||"Installation failed";return a.addMessage(String(t),"error"),await s(4500),void globalThis.location.reload()}a.addMessage(l.message||"Installation ended with unexpected status: "+String(r),"warning"),await s(3500),globalThis.location.reload()}(t,e).finally(function(){g=!1}),"undefined"!=typeof jQuery?jQuery.Deferred().promise():{abort:function(){}})}function o(t){if(!a())return;if(!wpApiSettings||!wpApiSettings.root||!wpApiSettings.nonce)return;const n=function(t){if(!t||!t.closest)return null;const e=t.closest("a.theme-install, button.theme-install");return e&&function(t){return!(!t||"A"!==t.tagName&&"BUTTON"!==t.tagName||!t.classList.contains("theme-install")||t.classList.contains("disabled")||null===i(t))}(e)?e:null}(t.target);if(!n)return;if(t.defaultPrevented)return;if(0!==t.button)return;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return;t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation();const s=i(n),o=function(t,e){const n=(t.getAttribute("data-name")||"").replace(/\s+/g," ").trim();if(n)return n;const a=(t.textContent||"").replace(/\s+/g," ").trim();return a&&"install"!==a.toLowerCase()?a:e}(n,s);e(),l(s,o)}function r(){globalThis[u]||a()&&(wpApiSettings&&wpApiSettings.root&&wpApiSettings.nonce?(a()&&globalThis.wp&&wp.updates&&"function"==typeof wp.updates.installTheme&&(wp.updates[c]||wpApiSettings&&wpApiSettings.root&&wpApiSettings.nonce&&(wp.updates[c]=!0,e(),wp.updates.installTheme=function(t){const n=t&&t.slug?String(t.slug):"";if(!n)return{abort:function(){}};const a=(t&&t.name?String(t.name):"")||("undefined"!=typeof jQuery?String(jQuery('.theme-install[data-slug="'+n+'"]').data("name")||n):n);return e(),l(n,a)})),globalThis[u]=!0,globalThis.addEventListener("click",o,!0),e()):n())}const u="__fleekdashThemeDirectoryInstallBound",c="__fleekdashThemeInstallPatched";let d=null,g=!1;r(),globalThis[u]||"loading"!==document.readyState||document.addEventListener("DOMContentLoaded",r)}();
//# sourceMappingURL=theme-directory-install.js.map
