import"./bootstrap.esm-Bb7dPm-H.js";import{b as d,c as n}from"./toastr-helper-Wdj0mZjX.js";document.addEventListener("DOMContentLoaded",()=>{const s=document.getElementById("editServiceCostForm");s&&s.addEventListener("submit",t=>{t.preventDefault(),m()})});function m(){const s=document.getElementById("editServiceCostForm"),t=new FormData(s);t.set("is_active",t.get("is_active")?1:0);const c=[1,3,6,12,24,36],i={};c.forEach(o=>{const e=t.get(`periods[${o}]`);e!==null&&e!==""&&!isNaN(parseFloat(e))&&(i[o]=parseFloat(e)),t.delete(`periods[${o}]`)});const r=Object.fromEntries(t);r.periods=i,r._method="PUT",fetch(window.routes.serviceCosts.update,{method:"PUT",headers:{Authorization:"Bearer "+document.querySelector('meta[name="api-token"]').getAttribute("content"),"Content-Type":"application/json",Accept:"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify(r)}).then(async o=>{const e=await o.json().catch(()=>({}));if(o.ok&&(e!=null&&e.success))d((e==null?void 0:e.message)||"Saved");else if(o.status===422&&(e!=null&&e.errors)){const a=Object.values(e.errors).flat().join("<br>");n(a||"Validation error")}else n((e==null?void 0:e.message)||"An error occurred while updating")}).catch(()=>n("Network error"))}
