import"./assets/bootstrap-DiRCdOSa.js";import"./assets/theme-switcher--vV5z1WW.js";const e=()=>{const e=window.location.pathname;let t;return t=e.endsWith("/update/index.php")?e.slice(0,-17):e.endsWith("/update/")?e.slice(0,-8):e.endsWith("/update")?e.slice(0,-7):e,t.endsWith("/")||(t+="/"),t};document.addEventListener("DOMContentLoaded",async()=>{(()=>{const e=document.getElementById("phpmyfaq-update-next-step-button"),t=document.getElementById("phpmyfaq-update-next-step");e&&t&&e.addEventListener("click",e=>{e.preventDefault();const n=parseInt(t.value,10);Number.isNaN(n)||n<1||window.location.replace(`?step=${n}`)})})(),await(async()=>{const t=window.location.pathname;if(t.endsWith("/update")||t.endsWith("/update/")||t.endsWith("/update/index.php")){const t=document.getElementById("phpmyfaq-update-installed-version");if(!t)return;const n=e();try{const e=await fetch(`${n}api/setup/check`,{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json"},body:t.value});if(!e.ok){let t;if((e.headers.get("content-type")||"").includes("application/json")){const n=await e.json();t=n.message||n.error||"Update check failed"}else{const n=await e.text();t=!n||"Not Found"===n||n.trimStart().startsWith("<")?"The server returned an error (HTTP "+e.status+"). Please check your server configuration: if you use Apache, verify the RewriteBase in your .htaccess matches your installation path. If you use nginx, check your rewrite configuration.":n}const n=document.getElementById("phpmyfaq-update-check-alert"),a=document.getElementById("phpmyfaq-update-check-result");return void(n&&a&&(n.classList.remove("d-none"),a.innerText=t))}const a=document.getElementById("phpmyfaq-update-next-step-button"),s=document.getElementById("phpmyfaq-update-check-success");s&&a&&(s.classList.remove("d-none"),a.classList.remove("disabled"),a.disabled=!1)}catch{const e="Could not connect to the update API. Please check your server configuration: if you use Apache, verify the RewriteBase in your .htaccess matches your installation path. If you use nginx, check your rewrite configuration.",t=document.getElementById("phpmyfaq-update-check-alert"),n=document.getElementById("phpmyfaq-update-check-result");t&&n&&(t.classList.remove("d-none"),n.innerText=e)}}})(),await(async()=>{const t=window.location.href;if(t.includes("/update")&&t.includes("step=2")){const t=document.getElementById("phpmyfaq-update-installed-version");if(!t)return;const a=e();try{const e=await fetch(`${a}api/setup/backup`,{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json"},body:t.value});if(!e.ok)return void console.error("Network response was not ok");await e.json()}catch(n){console.error("Backup creation failed:",n)}}})(),await(async()=>{const t=window.location.href;if(t.includes("/update")&&t.includes("step=3")){const t=document.getElementById("phpmyfaq-update-installed-version");if(!t)return;const a=e();try{const e=await fetch(`${a}api/setup/update-database`,{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json"},body:t.value}),n=await e.json(),s=document.getElementById("result-update");if(e.ok){s&&(s.style.width="100%",s.innerText="100%",s.classList.remove("progress-bar-animated"));const e=document.getElementById("phpmyfaq-update-database-success");e&&(e.classList.remove("d-none"),e.innerText=n.success)}else{s&&(s.style.width="100%",s.innerText="100%",s.classList.remove("progress-bar-animated"));const e=document.getElementById("phpmyfaq-update-database-error"),t=document.getElementById("error-messages");e&&t&&(e.classList.remove("d-none"),t.innerHTML=n.error)}}catch(n){console.error("Error details:",n);const e=document.getElementById("phpmyfaq-update-database-error");e&&(e.classList.remove("d-none"),e.innerText=`Error: ${n instanceof Error?n.message:String(n)}`)}}})()});
//# sourceMappingURL=update.js.map
