import{u as C,a as g,aB as x,eL as y,eM as j,j as t,C as E,eN as P,ac as _,ah as k,v as B,eO as w,ce as F,p as i,E as T,ae as q,eG as D,S as N,r as $,e as A,ak as O,F as h,h as G}from"./bundle.CHKSNOJF.js";function H(r){const[o]=C(),n=g(),[a,s]=x(y),c=j({setErrors:r.setErrors,setProduct:s});return t.jsx(E,{title:o("new_product"),className:"shadow-sm",style:{borderColor:n.$24},headerStyle:{borderColor:n.$20},children:a&&t.jsx(P,{errors:r.errors,handleChange:c,product:a})})}function L(){const{documentTitle:r}=_("new_product"),[o]=C(),n=k(),a=B(),[s,c]=x(y),{data:u}=w({enabled:typeof s>"u"}),S=[{name:o("products"),href:"/products"},{name:o("new_product"),href:"/products/create"}],[l]=F(),[b,p]=i.useState(),[f,m]=i.useState(!1),v=d=>{d.preventDefault(),f||(m(!0),$("POST",A("/api/v1/products"),s).then(e=>{O(["products"]),h.success("created_product"),n(G("/products/:id/edit",{id:e.data.data.id}))}).catch(e=>{e.response?.status===422&&(p(e.response.data),h.dismiss())}).finally(()=>m(!1)))};return i.useEffect(()=>{c(d=>{let e=d;return l.get("action")!=="clone"&&(e=void 0),typeof u<"u"&&typeof e>"u"&&l.get("action")!=="clone"&&(e=T.cloneDeep(u),a?.quickbooks&&(e.income_account_id=a.quickbooks.settings?.income_account_id||"")),e})},[u]),t.jsx(q,{title:r,breadcrumbs:S,disableSaveButton:!s||f,onSaveClick:v,children:t.jsx(D,{breadcrumbs:[],children:s?t.jsx(H,{errors:b,setErrors:p}):t.jsx(N,{})})})}export{L as default};
