import{u as P,a as w,ce as D,cV as F,y as N,j as e,C as R,c1 as U,cX as u,cd as s,S as C}from"./bundle.CHKSNOJF.js";import{C as V}from"./ClientSelector-BbBNOaqF.js";import{I as B,a as E}from"./InvoiceFooter-CSR6gT30.js";import{u as G,I as M,a as O}from"./useProductColumns-DDQWs8XU.js";import{u as W,T as X}from"./TasksTabLabel-DmAIy7nE.js";import{u as $}from"./useInvoiceUtilities-D6VXthvk.js";import"./UserUnsubscribedTooltip-CmrNR5P-.js";import"./ClientActionButtons-q9eajqVG.js";import"./PaymentTermsTooltip-BYtyFn5d.js";import"./InvoiceViewer-DkbHIsNq.js";function te(){const[r]=P(),h=w(),[i]=D(),p=F(),{invoice:a,errors:o,client:x,invoiceSum:g,isDefaultFooter:I,isDefaultTerms:_,setIsDefaultFooter:v,setIsDefaultTerms:j}=p,f=W(),y=N(),T=G(),{handleChange:t,handleInvitationChange:b,handleContactCanSignChange:k,handleLineItemChange:l,handleLineItemPropertyChange:c,handleCreateLineItem:m,handleDeleteLineItem:d}=$({client:x}),L=()=>(t("client_id",""),t("location_id",""),t("tax_name1",""),t("tax_rate1",0),t("tax_name2",""),t("tax_rate2",0),t("tax_name3",""),t("tax_rate3",0),!0);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-12 gap-4",children:[e.jsx(R,{className:"col-span-12 xl:col-span-4 h-max shadow-sm",withContainer:!0,style:{borderColor:h.$24},children:e.jsx(V,{resource:a,onChange:n=>t("client_id",n),onLocationChange:n=>t("location_id",n),onClearButtonClick:L,onContactCheckboxChange:b,onContactCanSignCheckboxChange:k,readonly:i.get("project")==="true",errorMessage:o?.errors.client_id,disableWithSpinner:i.get("action")==="create"})}),e.jsx(B,{invoice:a,handleChange:t,errors:o}),e.jsx("div",{className:"col-span-12",children:e.jsxs(U,{tabs:[r("products"),r("tasks")],defaultTabIndex:i.get("table")==="tasks"?1:0,formatTabLabel:n=>{if(n===1)return e.jsx(X,{lineItems:a?.line_items||[]})},children:[e.jsx("div",{children:a?e.jsx(u,{type:"product",resource:a,shouldCreateInitialLineItem:i.get("table")!=="tasks",items:a.line_items.filter(n=>[s.Product,s.UnpaidFee,s.PaidFee,s.LateFee].includes(n.type_id)),columns:T,relationType:"client_id",onLineItemChange:l,onSort:n=>t("line_items",n),onLineItemPropertyChange:c,onCreateItemClick:()=>m(s.Product),onDeleteRowClick:d}):e.jsx(C,{})}),e.jsx("div",{children:a?e.jsx(u,{type:"task",resource:a,shouldCreateInitialLineItem:i.get("table")==="tasks",items:a.line_items.filter(n=>n.type_id===s.Task),columns:f,relationType:"client_id",onLineItemChange:l,onSort:n=>t("line_items",n),onLineItemPropertyChange:c,onCreateItemClick:()=>m(s.Task),onDeleteRowClick:d}):e.jsx(C,{})})]})}),e.jsx(E,{invoice:a,handleChange:t,errors:o,isDefaultFooter:I,isDefaultTerms:_,setIsDefaultFooter:v,setIsDefaultTerms:j}),a&&e.jsx(M,{relationType:"client_id",resource:a,invoiceSum:g,onChange:(n,S)=>t(n,S)})]}),y?.show_pdf_preview&&e.jsx("div",{className:"my-4",children:a&&e.jsx(O,{for:"create",resource:a,entity:"invoice",relationType:"client_id",endpoint:"/api/v1/live_preview?entity=:entity",observable:!0,initiallyVisible:!1})})]})}export{te as default};
