import{u as q,aA as v,b_ as j,ci as y,h as n,j as e,cj as k,ac as V,cp as w,ck as L,aQ as O,aB as U,f8 as H,p as o,f9 as J,fa as K,aF as M,E as W,bS as z,ae as G,cm as X,cn as Y,S as Z,aJ as $,aK as ee,c7 as se}from"./bundle.CHKSNOJF.js";import{u as te}from"./queries-B-4Pq9fP.js";import{C as ie}from"./CommonActions-CCjRlVnA.js";import{P as ae}from"./PreviousNextNavigation-vVnyKojr.js";import"./Actions-Cg-_a1t3.js";import"./invoice-status-C0SI5VYC.js";import"./useShouldDisplayClientGatewaysAndAutoBill-mN5p-ZyL.js";import"./hooks-9RDJr6hd.js";import"./CreditStatus-WHg8w3rC.js";import"./useInvoiceColumns-CGbyIb88.js";import"./InvoiceStatus-1S0ZEgN9.js";function oe(m){const[t]=q(),c=v(),l=j(),{id:i}=y(),{quote:u}=m,d=c("view_quote")||c("edit_quote")||l(u);return[{name:t("edit"),href:n("/quotes/:id/edit",{id:i})},{name:t("documents"),href:n("/quotes/:id/documents",{id:i}),enabled:d,formatName:()=>e.jsx(k,{numberOfDocuments:u?.documents?.length})},{name:t("settings"),href:n("/quotes/:id/settings",{id:i})},{name:t("activity"),href:n("/quotes/:id/activity",{id:i})},{name:t("history"),href:n("/quotes/:id/history",{id:i})},{name:t("email_history"),href:n("/quotes/:id/email_history",{id:i})}]}function be(){const{documentTitle:m}=V("edit_quote"),[t]=q(),{id:c}=y(),l=w(),i=v(),u=j(),d=[{name:t("quotes"),href:"/quotes"},{name:t("edit_quote"),href:n("/quotes/:id/edit",{id:c})}],{data:r,isLoading:g}=te({id:c}),[s,f]=L(O),[S]=U(H),[p,T]=o.useState(),[A,_]=o.useState(),[h,E]=o.useState(!1),[x,D]=o.useState(!1),[b,C]=o.useState(!1),N=oe({quote:s}),P=J({setErrors:_,isDefaultFooter:b,isDefaultTerms:x,isFormBusy:h,setIsFormBusy:E}),{calculateInvoiceSum:F}=K({client:p}),{changeTemplateVisible:B,setChangeTemplateVisible:I,changeTemplateResources:Q}=M();return o.useEffect(()=>{if(r){const a=W.cloneDeep(r);a.line_items.map(R=>R._id=z()),f(a),a&&a.client&&T(a.client)}},[r]),o.useEffect(()=>{s&&F(s)},[s]),e.jsxs(G,{title:m,breadcrumbs:d,...(i("edit_quote")||u(s))&&s&&{navigationTopRight:e.jsx(se,{resource:s,actions:l,onSaveClick:()=>s&&P(s),disableSaveButton:!s||h,cypressRef:"quoteActionDropdown"})},afterBreadcrumbs:e.jsx(ae,{entity:"quote"}),children:[s?.id===c||!g?e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{tabs:N,rightSide:s&&e.jsx("div",{className:"flex items-center",children:e.jsx(ie,{resource:s,entity:"quote"})})}),e.jsx(Y,{context:{quote:s,setQuote:f,errors:A,isDefaultTerms:x,setIsDefaultTerms:D,isDefaultFooter:b,setIsDefaultFooter:C,client:p,invoiceSum:S}})]}):e.jsx("div",{className:"flex justify-center items-center",children:e.jsx(Z,{})}),e.jsx($,{entity:"quote",entities:Q,visible:B,setVisible:I,labelFn:a=>e.jsxs("div",{className:"flex flex-col space-y-1",children:[e.jsx(ee,{children:t("number")}),e.jsx("span",{children:a.number})]}),bulkUrl:"/api/v1/quotes/bulk"})]})}export{be as default};
