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