ruạṛ
import{T as D,bN as $,u as R,aa as j,p as a,cQ as k,c$ as M,bb as x,h as f,bK as V,a5 as I,j as d,W as O,c as t,bt as Q,S as U,cX as q,cY as B,cZ as F,c_ as H,a9 as K,bc as m,r as L,e as W,$ as X}from"./bundle.9abe88c8.js";import{P as Y}from"./PreviousNextNavigation-f6f14b66.js";function G(){const{documentTitle:b,setDocumentTitle:v}=D("edit_client"),{id:n}=$(),[l]=R(),C=j(),[T,g]=a.useState(!1),y=k({setIsPurgeOrMergeActionCalled:g}),{data:o,isLoading:S}=M({id:n,enabled:!T}),[p,h]=a.useState([]),[e,c]=a.useState(),[r,i]=a.useState();a.useEffect(()=>{if(o){c({...o});const s=x.cloneDeep(o.contacts);s.map(u=>u.password=""),h(s)}return()=>{g(!1)}},[o]),a.useEffect(()=>{v((e==null?void 0:e.display_name)||"edit_client")},[e]),a.useEffect(()=>{c(s=>x.set(s,"contacts",p))},[p]);const w=[{name:l("clients"),href:"/clients"},{name:b,href:f("/clients/:id",{id:n})},{name:l("edit"),href:f("/clients/:id",{id:n})}],A=V(),E=async()=>{m.processing(),await A(!0),L("PUT",W("/api/v1/clients/:id",{id:n}),{...e,documents:[]}).then(()=>{m.success("updated_client"),X(["clients"]),C(f("/clients/:id",{id:n}))}).catch(s=>{var u;((u=s.response)==null?void 0:u.status)===422&&(m.dismiss(),i(s.response.data))})},{changeTemplateVisible:N,setChangeTemplateVisible:P,changeTemplateResources:_}=I();return d(O,{title:b,breadcrumbs:w,onSaveClick:E,navigationTopRight:e&&t(Q,{label:l("more_actions"),resource:e,actions:y,cypressRef:"clientActionDropdown"}),afterBreadcrumbs:t(Y,{entity:"client"}),children:[S&&t(U,{}),e&&d("div",{className:"flex flex-col xl:flex-row xl:space-x-4",children:[d("div",{className:"flex flex-col w-full xl:w-1/2 space-y-4",children:[t(q,{client:e,setClient:c,setErrors:i,errors:r,page:"edit"}),t(B,{client:e,setClient:c,setErrors:i,errors:r})]}),d("div",{className:"flex flex-col w-full xl:w-1/2 space-y-4",children:[t(F,{contacts:p,setContacts:h,setErrors:i,errors:r}),t(H,{client:e,setClient:c,setErrors:i,errors:r})]}),t(K,{entity:"client",entities:_,visible:N,setVisible:P,labelFn:s=>`${l("number")}: ${s.number}`,bulkUrl:"/api/v1/clients/bulk"})]})]})}export{G as default};
cải xoăn