import{o as e}from"./rolldown-runtime-FhOqtrmT.js";import{b as t,x as n}from"./vendor-markdown-0Mxgxy0L.js";import{t as r}from"./file-exclamation-point-Baz81y5z.js";import{i,r as a}from"./api-client-bbJLzRVE.js";import{mt as o,wt as s}from"./index-48KAFlD7.js";var c=e(n(),1),l=t();function u({filePath:e,projectName:t}){let n=(0,c.useRef)(null),[u,d]=(0,c.useState)(!1),[f,p]=(0,c.useState)(!1),m=(0,c.useMemo)(()=>{let n=/^(\/|[A-Za-z]:[/\\])/.test(e)?`/api/fs/raw?path=${encodeURIComponent(e)}`:`${i(t)}/files/raw?path=${encodeURIComponent(e)}`,r=a();return r?`${n}&token=${encodeURIComponent(r)}`:n},[e,t]);(0,c.useEffect)(()=>{let r=r=>{let i=r.detail;if(!(i.projectName!==t||i.path!==e))try{n.current?.contentWindow?.location.reload()}catch{}};return window.addEventListener(`file:changed`,r),()=>window.removeEventListener(`file:changed`,r)},[e,t]);let h=(0,c.useCallback)(()=>{window.open(m,`_blank`)},[m]);return f?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,l.jsx)(r,{className:`size-10 text-text-subtle`}),(0,l.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!u&&(0,l.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,l.jsx)(o,{className:`size-5 animate-spin text-text-subtle`})}),(0,l.jsxs)(`div`,{className:`flex flex-col h-full ${u?``:`hidden`}`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,l.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,l.jsxs)(`button`,{onClick:h,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,l.jsx)(s,{className:`size-3`}),` Open in new tab`]})]}),(0,l.jsx)(`iframe`,{ref:n,src:m,title:e,className:`flex-1 w-full border-none`,onLoad:()=>d(!0),onError:()=>p(!0)})]})]})}export{u as PdfPreview};