import"jquery";import"./bootstrap.esm-Bb7dPm-H.js";import{s}from"./toastr-helper-Wdj0mZjX.js";import{g as u,r as l}from"./api-DZ3cXm1m.js";function m(){document.querySelectorAll(".is-invalid").forEach(t=>{t.classList.remove("is-invalid")}),document.querySelectorAll(".invalid-feedback").forEach(t=>{t.textContent=""})}function p(t){Object.keys(t).forEach(o=>{const r=document.getElementById(`edit_${o}`)||document.querySelector(`[name="${o}"]`);if(r){r.classList.add("is-invalid");const n=r.parentNode.querySelector(".invalid-feedback");n&&(n.textContent=t[o][0])}})}function f(t){var a;t.preventDefault();const o=document.getElementById("serverGroupForm"),r=o.querySelector('button[type="submit"]')||document.querySelector(`button[type="submit"][form="${o.id}"]`),n=new FormData;n.append("_method","PUT"),n.append("name",document.getElementById("edit_name").value),n.append("fill_strategy",document.getElementById("edit_fill_strategy").value),Array.from(document.querySelectorAll('input[name="servers[]"]:checked')).map(e=>e.value).forEach(e=>{n.append("servers[]",e)});const d=r.innerHTML;r.disabled=!0,r.innerHTML='<i class="fas fa-spinner fa-spin me-2"></i>'+((a=window.translations.messages)==null?void 0:a.loading)||"Loading...",m();const i=e=>({method:"POST",headers:{Accept:"application/json",Authorization:`Bearer ${e}`,"X-Requested-With":"XMLHttpRequest"},body:n});(async()=>{let e=await fetch(window.routes.serverGroups.update,i(u()));if(e.status===401){const c=await l();c&&(e=await fetch(window.routes.serverGroups.update,i(c)))}return e})().then(e=>e.json()).then(e=>{e.success?(s("success",e.message),setTimeout(()=>{window.location.href=window.routes.serverGroups.index},1500)):e.errors?p(e.errors):s("danger",e.message||"An error occurred.")}).catch(e=>{console.error("Error:",e),s("danger","An error occurred.")}).finally(()=>{r.disabled=!1,r.innerHTML=d})}document.addEventListener("DOMContentLoaded",function(){const t=document.getElementById("serverGroupForm");t&&t.addEventListener("submit",f)});
