import{ac as E,u as j,ci as T,g1 as b,p as e,h as B,E as m,cf as C,j as a,ae as F,g9 as P,c7 as R,F as n,r as _,e as k,ak as A}from"./bundle.CHKSNOJF.js";import{u as D}from"./useActions-DStR9fLW.js";import{P as N}from"./PreviousNextNavigation-vVnyKojr.js";function H(){const{documentTitle:v}=E("edit_vendor"),[r]=j(),{id:o}=T(),{data:t}=b({id:o}),[s,c]=e.useState(),[l,x]=e.useState(),[i,u]=e.useState(!1),[d,p]=e.useState([]),h=D(),g=[{name:r("vendors"),href:"/vendors"},{name:r("edit_vendor"),href:B("/vendors/:id/edit",{id:o})}];e.useEffect(()=>{t&&(c({...t}),p(m.cloneDeep(t.contacts)))},[t]);const y=C(),S=async()=>{i||(n.processing(),m.set(s,"contacts",d),u(!0),await y({excludeToasters:!0}),_("PUT",k("/api/v1/vendors/:id",{id:o}),s).then(()=>{n.success("updated_vendor"),A(["vendors"])}).catch(f=>{f.response?.status===422&&(n.dismiss(),x(f.response.data))}).finally(()=>u(!1)))};return a.jsx(F,{title:v,breadcrumbs:g,navigationTopRight:s&&a.jsx(R,{onSaveClick:S,resource:s,actions:h,disableSaveButton:!s||i}),afterBreadcrumbs:a.jsx(N,{entity:"vendor"}),children:s&&a.jsx(P,{vendor:s,setVendor:c,errors:l,contacts:d,setContacts:p,page:"edit"})})}export{H as default};
