import{aB as I,aN as v,ct as C,v as f,cu as g,cv as y,cw as p,cx as L}from"./bundle.CHKSNOJF.js";function q(u){const[a,o]=I(v),[,_]=I(C),d=f(),h=g(),r=(t,e)=>{o(n=>n&&{...n,[t]:e})};return{handleChange:r,handleInvitationChange:(t,e)=>{let n=[...a.invitations];const i=n?.find(s=>s.client_contact_id===t)||-1;if(i!==-1&&e===!1&&(n=n.filter(s=>s.client_contact_id!==t)),i===-1){const s={client_contact_id:t};n.push(s)}r("invitations",n)},handleContactCanSignChange:(t,e)=>{const n=a?.client?.contacts||u.client?.contacts;if(!n)return;const i=n.find(c=>c.id===t);if(!i||!(a?.invitations?.some(c=>c.client_contact_id===i.id)||!1))return;const l=[...a?.invitations||[]],m=l.findIndex(c=>c.client_contact_id===i.id);m>=0&&(l[m]={...l[m],can_sign:e}),o(c=>c&&{...c,invitations:l})},calculateInvoiceSum:t=>{const e=h(u.client?.settings.currency_id||d?.settings.currency_id);if(e&&t){const n=d?.settings.e_invoice_type,i=t.uses_inclusive_taxes?new p(t,e,n).build():new L(t,e,n).build();_(i)}},handleLineItemChange:(t,e)=>{const n=a?.line_items||[];n[t]=e,o(i=>i&&{...i,line_items:n})},handleLineItemPropertyChange:(t,e,n)=>{const i=a?.line_items||[];i[n][t]!==e&&(i[n][t]=e,o(s=>s&&{...s,line_items:i}))},handleCreateLineItem:t=>{o(e=>e&&{...e,line_items:[...e.line_items,{...y(),type_id:t,quantity:1}]})},handleDeleteLineItem:t=>{const e=a?.line_items||[];e.splice(t,1),o(n=>n&&{...n,line_items:e})}}}export{q as u};
