import{u as x,ah as g,a as j,v as k,ac as B,p as e,j as r,ae as E,eG as F,C as w,F as c,r as $,e as A,ak as D,h as N}from"./bundle.CHKSNOJF.js";import{c as R,A as q}from"./transactions-F2lekek9.js";import{u as G}from"./useResolveCurrencySeparator-C_jvzuRW.js";import{u as H,T as I}from"./useHandleChange-Dk5XO77m.js";function J(){const[i]=x(),h=g(),u=j(),d=k(),{data:n}=R(),S=G(),{documentTitle:l}=B("new_transaction"),[p,m]=e.useState(!1),[f,y]=e.useState(),[v,o]=e.useState(),[s,C]=e.useState(),b=H({setTransaction:C,setCurrencySeparators:y,setErrors:o}),T=[{name:i("transactions"),href:"/transactions"},{name:i("new_transaction"),href:"/transactions/create"}],_=async a=>{a.preventDefault(),!p&&(c.processing(),o(void 0),m(!0),$("POST",A("/api/v1/bank_transactions"),s).then(t=>{c.success("created_transaction"),D(["bank_transactions"]),h(N("/transactions/:id/edit",{id:t.data.data.id}))}).catch(t=>{t.response?.status===422&&(o(t.response.data),c.dismiss())}).finally(()=>m(!1)))};return e.useEffect(()=>{if(!s)n&&C({...n,base_type:q.Credit,currency_id:d?.settings.currency_id});else{const a=S(s.currency_id);a&&y(a)}},[d,s,n]),r.jsx(E,{title:l,breadcrumbs:T,disableSaveButton:!s||p,onSaveClick:_,children:r.jsx(F,{breadcrumbs:[],children:r.jsx(w,{title:l,className:"shadow-sm",style:{borderColor:u.$24},headerStyle:{borderColor:u.$20},children:f&&s&&r.jsx(I,{errors:v,transaction:s,handleChange:b,currencySeparators:f})})})})}export{J as default};
