import{i as e}from"./uiIdentityOverlay-Ba7GNj7m.js";import{t}from"./jsx-runtime-CyI9ICYU.js";import{s as n}from"./lib--QVjyxmL.js";import{_ as r,b as i,f as a,v as o,x as s}from"./index-CxCnkDVM.js";import{t as c}from"./lib-B6rgJiZ9.js";var l={html:`html`,htm:`html`,svg:`svg`,mmd:`mermaid`,mermaid:`mermaid`,d2:`d2`,pug:`pug`},u=new Set([`md`,`markdown`,`mdx`]),d=new Set([`ts`,`tsx`,`js`,`jsx`,`json`,`css`,`scss`,`xml`,`sh`,`bash`,`zsh`,`py`,`rs`,`go`,`java`,`rb`,`php`,`yml`,`yaml`,`sql`]),f=new Set(`png.jpg.jpeg.gif.webp.avif.ico.bmp.tiff.pdf.zip.gz.tar.rar.7z.woff.woff2.ttf.otf.eot.mp4.mov.webm.mp3.wav.ogg.flac.exe.dll.so.dylib.bin.wasm.class.jar`.split(`.`));function p(e){let t=e.split(`/`).pop()??``;return t.includes(`.`)?t.split(`.`).pop()?.toLowerCase()??``:``}function m(e){let t=p(e);if(u.has(t))return{kind:`markdown`};let n=l[t];return n?{kind:`embed`,format:n}:f.has(t)?{kind:`unsupported`}:{kind:`code`,language:d.has(t)?t:null}}var h=t(),g=e({id:`content-preview.dialog`,c3ComponentId:`c3-111`,c3ComponentLabel:`messages`});function _(e){let t=e.split(`/`).pop()?.split(`.`).pop()?.toLowerCase()??``;switch(t){case`ts`:case`tsx`:case`js`:case`jsx`:case`json`:case`css`:case`scss`:case`html`:case`xml`:case`svg`:case`sh`:case`bash`:case`zsh`:case`py`:case`rs`:case`go`:case`java`:case`rb`:case`php`:case`yml`:case`yaml`:case`sql`:return t;default:return null}}function v(e,t){return`\`\`\`${_(e)??``}\n${t}\n\`\`\``}function y(e){return/[├└│─]/.test(e)}function b(e){return/^\S.*\/\s*$/.test(e)}function x(e){return/^\s*(```|~~~)/.test(e)}function S(e){let t=e.split(`
`),n=[],r=0,i=!1;for(;r<t.length;){let e=t[r]??``;if(x(e)){i=!i,n.push(e),r+=1;continue}if(!i&&y(e)){let e=[],i=n[n.length-1];for(i!==void 0&&b(i)&&(n.pop(),e.push(i));r<t.length&&y(t[r]??``);)e.push(t[r]??``),r+=1;if(e.length>1){let i=n[n.length-1];i!==void 0&&i.trim()!==``&&n.push(``),n.push("```text",...e,"```"),(t[r]??``).trim()!==``&&n.push(``);continue}n.push(...e);continue}n.push(e),r+=1}return n.join(`
`)}function C(e,t){let n=s(e.path,t);return e.line?e.column?`${n}:${e.line}:${e.column}`:`${n}:${e.line}`:n}function w(e){let t=m(e);return t.kind===`markdown`?`markdown`:t.kind===`embed`?`embed`:`code`}function T({preview:e,onOpenLocalLink:t}){let i=m(e.path);if(i.kind===`markdown`){let i=S(e.content);return(0,h.jsx)(`div`,{className:`text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-full space-y-4`,children:(0,h.jsx)(c,{remarkPlugins:[n],components:r({onOpenLocalLink:t,renderRichContentBlocks:!1}),children:i})})}return i.kind===`embed`?(0,h.jsx)(`div`,{className:`w-full max-w-full`,children:(0,h.jsx)(o,{format:i.format,source:e.content,fillHeight:!0})}):i.kind===`unsupported`?(0,h.jsx)(`div`,{className:`px-1 py-10 text-center text-sm text-muted-foreground`,children:`Preview unavailable for this file type.`}):(0,h.jsx)(`div`,{className:`text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-full space-y-4`,children:(0,h.jsx)(c,{remarkPlugins:[n,a],components:r({onOpenLocalLink:t,renderRichContentBlocks:!1}),children:v(e.path,e.content)})})}function E({preview:e,workspacePath:t,onClose:n,onOpenLocalLink:r}){return(0,h.jsx)(i,{open:e!==null,onOpenChange:e=>{e||n()},title:e?C(e,t):`File preview`,type:e?w(e.path):`code`,rawContent:e?.content,rootUiId:g,children:e?(0,h.jsx)(T,{preview:e,onOpenLocalLink:r}):null})}export{E as LocalFilePreviewDialog};