const y="#install-content",u="#install-stepper";let f=!1;function w(){const e=document.querySelector(u+" [data-step-active]");e&&e.classList.add("step-loading")}function g(){document.querySelectorAll(u+" .step-loading").forEach(e=>e.classList.remove("step-loading"))}function p(e){try{const t=new URL(e,location.href);return t.origin!==location.origin?!1:/(^|\/)install(\/|$|\?)/.test(t.pathname)}catch{return!1}}function S(e,t){const r=new DOMParser().parseFromString(e,"text/html"),n=r.querySelector(y),i=document.querySelector(y);if(!n||!i){location.assign(t);return}const a=r.querySelector(u),s=document.querySelector(u),l=s?s.querySelectorAll("[data-step-done]").length:0;i.replaceWith(n),a&&s&&s.replaceWith(a),r.title&&(document.title=r.title);try{r.querySelectorAll("script:not([src])").forEach(o=>{if((o.type||"").includes("module"))return;const m=o.textContent||"";if(!m.trim())return;const d=document.createElement("script");d.textContent=m,document.body.appendChild(d),d.remove()})}catch{}try{window.Alpine&&typeof window.Alpine.initTree=="function"&&(window.Alpine.initTree(n),a&&window.Alpine.initTree(a))}catch{}try{const o=(a||document).querySelectorAll("[data-step-done]");o.length&&o.length>l&&o[o.length-1].classList.add("step-flip")}catch{}const c=n.closest(".install-scroll");c&&c.scrollTo&&c.scrollTo(0,0),n.classList.add("step-enter");try{history.pushState({},"",t)}catch{}}async function h(e,t={}){if(f)return;f=!0,w();const r=Date.now();try{const n=await fetch(e,{method:t.method||"GET",body:t.body||void 0,headers:{"X-Requested-With":"XMLHttpRequest",Accept:"text/html"},credentials:"same-origin",redirect:"follow"});if(!n.ok&&n.status!==422)throw new Error("HTTP "+n.status);const i=n.url||e;if(!p(i)){location.assign(i);return}let a=i;try{a=new URL(i,location.href).pathname}catch{}if(/\/install\/run(\/|$|\?)/.test(a)){location.assign(i);return}const s=await n.text(),l=560-(Date.now()-r);l>0&&await new Promise(c=>setTimeout(c,l)),S(s,i)}catch{g(),location.assign(e)}finally{f=!1}}function b(e){if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;const t=e.target.closest&&e.target.closest("a[href]");!t||t.target==="_blank"||t.hasAttribute("download")||t.dataset.noPjax!=null||p(t.getAttribute("href"))&&(e.preventDefault(),h(t.href,{method:"GET"}))}function A(e){const t=e.target;if(!(t instanceof HTMLFormElement)||t.dataset.noPjax!=null||t.hasAttribute("x-data")||t.hasAttribute("@submit.prevent")||t.hasAttribute("x-on:submit.prevent")||(t.getAttribute("method")||"get").toLowerCase()!=="post")return;const r=t.getAttribute("action")||location.href;if(p(r)){if(typeof t.reportValidity=="function"&&!t.reportValidity()){e.preventDefault();return}e.preventDefault(),h(r,{method:"POST",body:new FormData(t)})}}function E(){window.installGo=h,document.addEventListener("click",b),document.addEventListener("submit",A,!0),window.addEventListener("popstate",()=>{location.reload()})}export{E as default};
