import{u as y,ah as _,aA as w,ci as N,b4 as D,p as n,j as e,a3 as S,T as p,I as j,aP as E,h as x,bf as I,e as T,aC as U,ce as k,ae as C,S as H,dc as A}from"./bundle.CHKSNOJF.js";import{I as B}from"./InvoiceViewer-DkbHIsNq.js";function G(a){const[i]=y(),t=_(),v=w(),{id:o}=N(),u=D({resource:"invoice"}),{deliveryNote:c,setDeliveryNote:s,blobUrl:h,invoice:r,onHandleDeliveryNote:l}=a,d=f=>{s(f),f?l(T("/api/v1/invoices/:id/delivery_note?per_page=999999",{id:o}),!0):l(h,!1)};return n.useEffect(()=>{d(c)},[]),e.jsxs("div",{className:"flex space-x-3",children:[e.jsx("span",{className:"inline-flex items-center",children:e.jsx(S,{label:i("delivery_note"),checked:c,onChange:d})}),v("edit_invoice")&&e.jsxs(p,{className:"flex items-center space-x-1",onClick:()=>t(x("/invoices/:id/email",{id:r.id})),children:[e.jsx(j,{element:E,color:"white"}),e.jsx("span",{children:i("email_invoice")})]}),e.jsxs(p,{className:"flex items-center space-x-1",onClick:()=>u(r,c),children:[e.jsx(j,{element:I,color:"white"}),e.jsx("span",{children:i("download")})]})]})}function L(){const{id:a}=N(),{data:i}=U({id:a}),[t]=y(),[v,o]=n.useState(),[u,c]=n.useState(""),[s,h]=n.useState(),[r,l]=n.useState(!1),[d]=k(),f=A({resourceType:"invoice"});n.useEffect(()=>{i&&(h(i),d.has("delivery_note")&&l(!0))},[i]),n.useEffect(()=>{s&&!d.has("delivery_note")&&o(f(s))},[s]);const g=m=>c(m),P=[{name:t("invoices"),href:"/invoices"},{name:t("edit_invoice"),href:x("/invoices/:id/edit",{id:a})},{name:t("pdf"),href:x("/invoices/:id/pdf",{id:a})}];return e.jsx(C,{breadcrumbs:P,title:t("view_pdf"),navigationTopRight:s&&e.jsx(G,{invoice:s,blobUrl:u,deliveryNote:r,setDeliveryNote:l,onHandleDeliveryNote:(m,b=r)=>o(b?m:f(s))}),children:v?e.jsx(B,{onLink:g,link:v,method:"GET"}):e.jsx("div",{className:"flex justify-center items-center",style:{height:1500},children:e.jsx(H,{})})})}export{L as default};
