import{ac as k,u as A,v as F,ce as R,ck as P,aQ as w,aB as U,f8 as L,p as r,cU as O,fb as W,fa as z,E as v,j as u,ae as G,cm as H,cn as J,S as K}from"./bundle.CHKSNOJF.js";import{b as M}from"./blank-invitation-874ut05T.js";import{a as V}from"./queries-B-4Pq9fP.js";function N(){const{documentTitle:h}=k("new_quote"),[l]=A(),S=[{name:l("quotes"),href:"/quotes"},{name:l("new_quote"),href:"/quotes/create"}],q=[{name:l("create"),href:"/quotes/create"},{name:l("documents"),href:"/quotes/create/documents"},{name:l("settings"),href:"/quotes/create/settings"}],n=F(),[o]=R(),[a,f]=P(w),[y]=U(L),[d,j]=r.useState(),[C,E]=r.useState(),[g,$]=r.useState(!1),[x,D]=r.useState(!1),[p,T]=r.useState(!1),b=O(),{data:m,isLoading:B}=V({enabled:typeof a>"u"}),I=W({setErrors:E,isDefaultFooter:p,isDefaultTerms:x,isFormBusy:g,setIsFormBusy:$}),{handleChange:c,calculateInvoiceSum:Q}=z({client:d}),_=(t,e)=>t?.settings?.[`tax_name${e}`]?{name:t.settings[`tax_name${e}`],rate:t.settings[`tax_rate${e}`]}:t?.group_settings?.settings?.[`tax_name${e}`]?{name:t?.group_settings?.settings[`tax_name${e}`],rate:t?.group_settings?.settings[`tax_rate${e}`]}:{name:n?.settings[`tax_name${e}`],rate:n?.settings[`tax_rate${e}`]};return r.useEffect(()=>(f(t=>{let e=t;if(o.get("action")!=="clone"&&(e=void 0),typeof m<"u"&&typeof e>"u"&&o.get("action")!=="clone"){const s=v.cloneDeep(m);return typeof s.line_items=="string"&&(s.line_items=[]),o.get("client")&&(s.client_id=o.get("client")),s.uses_inclusive_taxes=n?.settings?.inclusive_taxes??!1,e=s}return e}),()=>{o.get("action")!=="clone"&&f(void 0)}),[m]),r.useEffect(()=>{a&&a.client_id.length>1&&b.find(a.client_id).then(t=>{j(t);const e=[];if(t.contacts.map(s=>{if(s.send_email){const i=v.cloneDeep(M);i.client_contact_id=s.id,i.can_sign=s.can_sign,e.push(i)}}),c("invitations",e),!t.is_tax_exempt){if(n&&n.enabled_tax_rates>0&&o.get("action")!=="clone"){const{name:s,rate:i}=_(t,"1");c("tax_name1",s),c("tax_rate1",i)}if(n&&n.enabled_tax_rates>1&&o.get("action")!=="clone"){const{name:s,rate:i}=_(t,"2");c("tax_name2",s),c("tax_rate2",i)}if(n&&n.enabled_tax_rates>2&&o.get("action")!=="clone"){const{name:s,rate:i}=_(t,"3");c("tax_name3",s),c("tax_rate3",i)}}})},[a?.client_id]),r.useEffect(()=>{a&&Q(a)},[a]),u.jsx(G,{title:h,breadcrumbs:S,onSaveClick:()=>I(a),disableSaveButton:a?.client_id.length===0||g,children:B?u.jsx("div",{className:"flex justify-center items-center",children:u.jsx(K,{})}):u.jsxs("div",{className:"space-y-4",children:[u.jsx(H,{tabs:q}),u.jsx(J,{context:{quote:a,setQuote:f,errors:C,isDefaultTerms:x,setIsDefaultTerms:D,isDefaultFooter:p,setIsDefaultFooter:T,client:d,invoiceSum:y}})]})})}export{N as default};
