import{u as h,ac as C,ah as T,ce as j,cf as B,h as p,p as n,dx as E,j as c,ae as w,dy as k,cm as F,cn as P,E as N,F as l,r as O,e as q,ak as A}from"./bundle.CHKSNOJF.js";function D(){const[e]=h();return[{name:e("create"),href:"/clients/create"},{name:e("settings"),href:"/clients/create/settings"},{name:e("documents"),href:"/clients/create/documents"},{name:e("locations"),href:"/clients/create/locations"}]}function I(){const{documentTitle:e}=C("new_client"),[s]=h(),x=T(),[g]=j(),y=B(),v=[{name:s("clients"),href:"/clients"},{name:s("new_client"),href:p("/clients/create")}],[t,r]=n.useState(),[m,d]=n.useState(!1),[a,f]=n.useState(),[o,S]=n.useState([{first_name:"",last_name:"",email:"",phone:"",send_email:!1,cc_only:!1}]),b=D(),{data:u}=E({});n.useEffect(()=>{u&&f({...u.data,group_settings_id:g.get("group")||""})},[u]);const _=async()=>{if(!m){if(N.set(a,"contacts",o),l.processing(),r(void 0),!(a?.name!=""||o[0].first_name!=""||o[0].last_name!=""))return r({message:s("please_enter_a_client_or_contact_name"),errors:{name:[s("please_enter_a_client_or_contact_name")]}}),l.error(),_;d(!0),await y({excludeToasters:!0}),O("POST",q("/api/v1/clients"),a).then(i=>{l.success("created_client"),A(["clients"]),x(p("/clients/:id",{id:i.data.data.id}))}).catch(i=>{i.response?.status===422&&(r(i.response.data),l.dismiss())}).finally(()=>d(!1))}};return c.jsxs(w,{title:e,breadcrumbs:v,onSaveClick:_,disableSaveButton:m,children:[t?c.jsx(k,{errors:t,entity:"client",withoutTopMessage:!!t.errors?.id,withoutListBullets:!!t.errors?.id}):null,a&&c.jsxs("div",{className:"space-y-4",children:[c.jsx(F,{tabs:b}),c.jsx(P,{context:{errors:t,setErrors:r,client:a,setClient:f,contacts:o,setContacts:S}})]})]})}export{I as default};
