import{a1 as U,b as f,g as F,s as i,a0 as S}from"./app-583c7dce.js";import{u as x}from"./useEmitter-7699a4d3.js";const R=(c,h,I="yes")=>{const g=U(),s=f({}),v=f({}),n=f(!1),b=x(),M=(t,e,l="patch",r=null)=>{s.value={},n.value=!0,c.selectedUrl?l==="patch"?i.patch(t,e).then(a=>{d(a,r)}).catch(({response:a})=>{u(a)}).finally(()=>o()):i.put(t,e).then(a=>{d(a,r)}).catch(({response:a})=>{u(a)}).finally(()=>o()):i.post(t,e).then(a=>{d(a,r)}).catch(({response:a})=>{u(a)}).finally(()=>o())},u=t=>{var e,l;t.status===422?s.value=(e=t==null?void 0:t.data)==null?void 0:e.errors:(s.value={},g.error((l=t==null?void 0:t.data)==null?void 0:l.message))},d=(t,e)=>{var l;g.success((l=t==null?void 0:t.data)==null?void 0:l.message),b.emit("reload-"+c.tableId),e&&h("success"),y()},o=()=>{n.value=!1},y=()=>{S.getInstance(document.getElementById(c.modalId)).hide(),h("close")},m=f(!1),E=()=>{m.value=!0,i.get(c.selectedUrl).then(({data:t})=>{v.value=t}).finally(()=>m.value=!1)};return F(()=>{c.selectedUrl&&I==="yes"&&E()}),{preloader:n,pageLoader:m,formData:v,errors:s,save:M,closeModal:y,getEditData:E,afterSuccess:d,afterError:u,afterFinalResponse:o}};export{R as u};
