1import{u as l,j as e,r as i,S as d,B as m,F as r,b0 as x,b1 as u}from"./elements-5kxJS_4j.js";import{u as y}from"./useRedesign-xeayEwR4.js";import{A as j,p as h,Y as N,a8 as p,a2 as f,B as b,P as v}from"./index-CtCeyryw.js";import{E as w}from"./react-error-boundary.esm-DcHtxTCg.js";import"./grids-DGmfp9GI.js";import"./startOfDay-AazlW55I.js";const R=({associationId:t,documentId:s})=>{const{t:n}=l(),[a]=j(),o=a.get("name")??"",{data:c}=h({queryKey:["attachment",s],queryFn:()=>b.getDocument(t,s)});return e.jsx(w,{fallbackRender:()=>e.jsxs("div",{className:"p-6 text-center flex flex-col items-center justify-center gap-8 w-screen h-screen",children:[e.jsx("h1",{className:"text-2xl font-bold",children:n("An error occurred")}),e.jsx("p",{className:"text-lg",children:n("documents.attachments.errorMessage")}),e.jsx(m,{onClick:()=>window.location.reload(),children:n("documents.attachments.errorTryAgain")})]}),children:e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"p-6 text-center flex flex-col items-center justify-center gap-8 w-screen h-screen",children:e.jsx(d,{})}),children:e.jsx(N,{resolve:c,children:c&&e.jsx(L,{file:c,fileName:o})})})})};function L({file:t,fileName:s}){const{t:n}=l();return e.jsxs("div",{className:"h-screen w-screen flex flex-col",children:[e.jsx("div",{className:"flex items-end justify-center p-4 gap-4",children:e.jsxs("button",{className:"p-2",title:"Download",onClick:()=>{const a=()=>{const o=URL.createObjectURL(t.blob),c=document.createElement("a");c.href=o,c.download=s,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(o)};p(t.blob).then(o=>{f({content:o,contentType:t.contentType,fileName:s},a)}).catch(()=>{a()})},children:[e.jsx("span",{className:"sr-only",children:n("documents.attachments.download")}),e.jsx(r,{icon:x,className:"text-base-fg text-base"})]})}),t.contentType==="application/pdf"&&e.jsx(U,{fileName:s,file:t}),t.contentType.startsWith("image/")&&e.jsx(k,{fileName:s,file:t}),!["application/pdf","image/"].some(a=>t.contentType.startsWith(a))&&e.jsx("div",{className:"flex-grow flex items-center justify-center",children:e.jsxs("p",{className:"space-x-2",children:[e.jsx(r,{icon:u,className:"text-yellow-500"}),e.jsx("span",{children:n("documents.attachments.noPreview")})]})})]})}function U({fileName:t,file:s}){const n=URL.createObjectURL(s.blob);return e.jsx("iframe",{className:"flex-grow overflow-auto",title:t,src:n})}function k({fileName:t,file:s}){const n=URL.createObjectURL(s.blob);return e.jsx("div",{className:"flex-grow overflow-auto flex items-center justify-center",children:e.jsx("img",{onLoad:()=>URL.revokeObjectURL(n),className:"max-w-[calc(100%-50px)] max-h-[calc(100%-50px)] object-contain",src:n,alt:t})})}const D=({associationId:t,documentId:s})=>{const{t:n}=l(),[a]=j(),o=a.get("name")??"",{data:c,isLoading:g}=h({queryKey:["attachment",s],queryFn:()=>b.getDocument(t,s)});return e.jsx(w,{fallbackRender:()=>e.jsxs("div",{className:"p-6 text-center flex flex-col items-center justify-center gap-8 w-screen h-screen",children:[e.jsx("h1",{className:"text-2xl font-bold",children:n("An error occurred")}),e.jsx("p",{className:"text-lg",children:n("documents.attachments.errorMessage")}),e.jsx(m,{onClick:()=>window.location.reload(),children:n("documents.attachments.errorTryAgain")})]}),children:g?e.jsx("div",{className:"p-6 text-center flex flex-col items-center justify-center gap-8 w-screen h-screen",children:e.jsx(d,{})}):c?e.jsx(I,{file:c,fileName:o}):null})};function I({file:t,fileName:s}){const{t:n}=l();return e.jsxs("div",{className:"h-screen w-screen flex flex-col",children:[e.jsx("div",{className:"flex items-end justify-center p-4 gap-4",children:e.jsxs("button",{className:"p-2",title:"Download",onClick:()=>{const a=()=>{const o=URL.createObjectURL(t.blob),c=document.createElement("a");c.href=o,c.download=s,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(o)};p(t.blob).then(o=>{f({content:o,contentType:t.contentType,fileName:s},a)}).catch(()=>{a()})},children:[e.jsx("span",{className:"sr-only",children:n("documents.attachments.download")}),e.jsx(r,{icon:x,className:"text-base-fg text-base"})]})}),t.contentType==="application/pdf"&&e.jsx(T,{fileName:s,file:t}),t.contentType.startsWith("image/")&&e.jsx(A,{fileName:s,file:t}),!["application/pdf","image/"].some(a=>t.contentType.startsWith(a))&&e.jsx("div",{className:"flex-grow flex items-center justify-center",children:e.jsxs("p",{className:"space-x-2",children:[e.jsx(r,{icon:u,className:"text-yellow-500"}),e.jsx("span",{children:n("documents.attachments.noPreview")})]})})]})}function T({fileName:t,file:s}){const n=i.useMemo(()=>URL.createObjectURL(s.blob),[s.blob]);return i.useEffect(()=>()=>URL.revokeObjectURL(n),[n]),e.jsx("iframe",{className:"flex-grow overflow-auto",title:t,src:n})}function A({fileName:t,file:s}){const n=URL.createObjectURL(s.blob);return e.jsx("div",{className:"flex-grow overflow-auto flex items-center justify-center",children:e.jsx("img",{onLoad:()=>URL.revokeObjectURL(n),className:"max-w-[calc(100%-50px)] max-h-[calc(100%-50px)] object-contain",src:n,alt:t})})}function F({params:t}){const s=t.associationId?parseInt(t.associationId):null,n=t.documentId?parseInt(t.documentId):null;if(s===null||isNaN(s))throw new Error("Invalid ID");if(!n)throw new Error("Invalid File Name");return{associationId:s,documentId:n}}function q(){const{associationId:t,documentId:s}=v();return y()?e.jsx(D,{associationId:t,documentId:s}):e.jsx(R,{associationId:t,documentId:s})}export{q as Component,F as loader};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.