const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/docx-preview-DAkAGQCn.js","assets/jszip.min-Ck-YHtwS.js","assets/vendor-mini-lit-CpUQub-j.js","assets/vendor-lit-B2r-dKc0.js","assets/vendor-lucide-B9Yl1Gez.js","assets/vendor-marked-_iteVaMm.js"])))=>i.map(i=>d[i]);
import{_ as T}from"./app-review-C3CmcSYC.js";import{i as s,B as v,a as y}from"./vendor-mini-lit-CpUQub-j.js";import{i as C,b as o,r as w}from"./vendor-lit-B2r-dKc0.js";import"./app-session-runtime-CeFJDILJ.js";import{D as E,X as L}from"./vendor-lucide-B9Yl1Gez.js";import"./app-panel-workspace-C3XDRCgE.js";import"./app-routing-C_r2pdnC.js";import"./vendor-marked-_iteVaMm.js";import"./app-message-reducer-wATqnZGf.js";import"./vendor-sortable-B1o3v0Qs.js";import"./app-inbox-CaZD85aD.js";import"./app-pr-walkthrough-WipZACSB.js";var P=Object.defineProperty,g=(l,e,t,r)=>{for(var a=void 0,n=l.length-1,i;n>=0;n--)(i=l[n])&&(a=i(e,t,a)||a);return a&&P(e,t,a),a};let x=null;async function F(){return x||(x=T(()=>import("./pdf-D9qYOnN8.js"),[]).then(l=>(l.GlobalWorkerOptions.workerSrc=new URL("/assets/pdf.worker.min-Cpi8b8z3.mjs",import.meta.url).toString(),l))),x}let f=null;async function D(){return f||(f=T(()=>import("./docx-preview-DAkAGQCn.js"),__vite__mapDeps([0,1,2,3,4,5]))),f}const p=class k extends C{constructor(){super(...arguments),this.showExtractedText=!1,this.error=null,this.currentLoadingTask=null,this.handleBackdropClick=()=>{this.close()},this.handleDownload=()=>{if(!this.attachment)return;const e=atob(this.attachment.content),t=new Array(e.length);for(let d=0;d<e.length;d++)t[d]=e.charCodeAt(d);const r=new Uint8Array(t),a=new Blob([r],{type:this.attachment.mimeType}),n=URL.createObjectURL(a),i=document.createElement("a");i.href=n,i.download=this.attachment.fileName,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(n)}}createRenderRoot(){return this}static open(e,t){const r=new k;r.attachment=e,r.onCloseCallback=t,document.body.appendChild(r),r.setupEventListeners()}setupEventListeners(){this.boundHandleKeyDown=e=>{e.key==="Escape"&&this.close()},window.addEventListener("keydown",this.boundHandleKeyDown)}close(){this.cleanup(),this.boundHandleKeyDown&&window.removeEventListener("keydown",this.boundHandleKeyDown),this.onCloseCallback?.(),this.remove()}getFileType(){return this.attachment?this.attachment.type==="image"?"image":this.attachment.mimeType==="application/pdf"?"pdf":this.attachment.mimeType?.includes("wordprocessingml")?"docx":this.attachment.mimeType?.includes("presentationml")||this.attachment.fileName.toLowerCase().endsWith(".pptx")?"pptx":"text":"text"}getFileTypeLabel(){switch(this.getFileType()){case"pdf":return s("PDF");case"docx":return s("Document");case"pptx":return s("Presentation");default:return""}}cleanup(){this.showExtractedText=!1,this.error=null,this.currentLoadingTask&&(this.currentLoadingTask.destroy(),this.currentLoadingTask=null)}render(){return this.attachment?o`
			<!-- Full screen overlay -->
			<div class="fixed inset-0 bg-black/90 z-50 flex flex-col" @click=${this.handleBackdropClick}>
				<!-- Compact header bar -->
				<div class="bg-background/95 backdrop-blur border-b border-border" @click=${e=>e.stopPropagation()}>
					<div class="px-4 py-2 flex items-center justify-between">
						<div class="flex items-center gap-3 min-w-0">
							<span class="text-sm font-medium text-foreground truncate">${this.attachment.fileName}</span>
						</div>
						<div class="flex items-center gap-2">
							${this.renderToggle()}
							${v({variant:"ghost",size:"icon",onClick:this.handleDownload,children:y(E,"sm"),className:"h-8 w-8"})}
							${v({variant:"ghost",size:"icon",onClick:()=>this.close(),children:y(L,"sm"),className:"h-8 w-8"})}
						</div>
					</div>
				</div>

				<!-- Content container -->
				<div class="flex-1 flex items-center justify-center overflow-auto" @click=${e=>e.stopPropagation()}>
					${this.renderContent()}
				</div>
			</div>
		`:o``}renderToggle(){if(!this.attachment)return o``;const e=this.getFileType(),t=!!this.attachment.extractedText;if(!(e!=="image"&&e!=="text"&&e!=="pptx"&&t))return o``;const a=this.getFileTypeLabel();return o`
			<mode-toggle
				.modes=${[a,s("Text")]}
				.selectedIndex=${this.showExtractedText?1:0}
				@mode-change=${n=>{n.stopPropagation(),this.showExtractedText=n.detail.index===1,this.error=null}}
			></mode-toggle>
		`}renderContent(){return this.attachment?this.error?o`
				<div class="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg max-w-2xl">
					<div class="font-medium mb-1">${s("Error loading file")}</div>
					<div class="text-sm opacity-90">${this.error}</div>
				</div>
			`:this.renderFileContent():o``}renderFileContent(){if(!this.attachment)return o``;const e=this.getFileType();if(this.showExtractedText&&e!=="image")return o`
				<div class="bg-card border border-border text-foreground p-6 w-full h-full max-w-4xl overflow-auto">
					<pre class="whitespace-pre-wrap font-mono text-xs leading-relaxed">${this.attachment.extractedText||s("No text content available")}</pre>
				</div>
			`;switch(e){case"image":{const t=`data:${this.attachment.mimeType};base64,${this.attachment.content}`;return o`
					<img src="${t}" class="max-w-full max-h-full object-contain rounded-lg shadow-lg" alt="${this.attachment.fileName}" />
				`}case"pdf":return o`
					<div
						id="pdf-container"
						class="bg-card text-foreground overflow-auto shadow-lg border border-border w-full h-full max-w-[1000px]"
					></div>
				`;case"docx":return o`
					<div
						id="docx-container"
						class="bg-card text-foreground overflow-auto shadow-lg border border-border w-full h-full max-w-[1000px]"
					></div>
				`;case"pptx":return o`
					<div
						id="pptx-container"
						class="bg-card text-foreground overflow-auto shadow-lg border border-border w-full h-full max-w-[1000px]"
					></div>
				`;default:return o`
					<div class="bg-card border border-border text-foreground p-6 w-full h-full max-w-4xl overflow-auto">
						<pre class="whitespace-pre-wrap font-mono text-sm">${this.attachment.extractedText||s("No content available")}</pre>
					</div>
				`}}async updated(e){if(super.updated(e),(e.has("attachment")||e.has("showExtractedText"))&&this.attachment&&!this.showExtractedText&&!this.error)switch(this.getFileType()){case"pdf":await this.renderPdf();break;case"docx":await this.renderDocx();break;case"pptx":await this.renderExtractedText();break}}async renderPdf(){const e=this.querySelector("#pdf-container");if(!e||!this.attachment)return;let t=null;try{const r=await F(),a=this.base64ToArrayBuffer(this.attachment.content);this.currentLoadingTask&&this.currentLoadingTask.destroy(),this.currentLoadingTask=r.getDocument({data:a}),t=await this.currentLoadingTask.promise,this.currentLoadingTask=null,e.innerHTML="";const n=document.createElement("div");n.className="",e.appendChild(n);for(let i=1;i<=t.numPages;i++){const d=await t.getPage(i),h=document.createElement("div");h.className="mb-4 last:mb-0";const c=document.createElement("canvas"),m=c.getContext("2d"),u=d.getViewport({scale:1.5});if(c.height=u.height,c.width=u.width,c.className="w-full max-w-full h-auto block mx-auto bg-white rounded shadow-sm border border-border",m&&(m.fillStyle="white",m.fillRect(0,0,c.width,c.height)),await d.render({canvasContext:m,viewport:u,canvas:c}).promise,h.appendChild(c),i<t.numPages){const b=document.createElement("div");b.className="h-px bg-border my-4",h.appendChild(b)}n.appendChild(h)}}catch(r){console.error("Error rendering PDF:",r),this.error=r?.message||s("Failed to load PDF")}finally{t&&t.destroy()}}async renderDocx(){const e=this.querySelector("#docx-container");if(!(!e||!this.attachment))try{const{renderAsync:t}=await D(),r=this.base64ToArrayBuffer(this.attachment.content);e.innerHTML="";const a=document.createElement("div");a.className="docx-wrapper-custom",e.appendChild(a),await t(r,a,void 0,{className:"docx",inWrapper:!0,ignoreWidth:!0,ignoreHeight:!1,ignoreFonts:!1,breakPages:!0,ignoreLastRenderedPageBreak:!0,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!1,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0});const n=document.createElement("style");n.textContent=`
				#docx-container {
					padding: 0;
				}

				#docx-container .docx-wrapper-custom {
					max-width: 100%;
					overflow-x: auto;
				}

				#docx-container .docx-wrapper {
					max-width: 100% !important;
					margin: 0 !important;
					background: transparent !important;
					padding: 0em !important;
				}

				#docx-container .docx-wrapper > section.docx {
					box-shadow: none !important;
					border: none !important;
					border-radius: 0 !important;
					margin: 0 !important;
					padding: 2em !important;
					background: white !important;
					color: black !important;
					max-width: 100% !important;
					width: 100% !important;
					min-width: 0 !important;
					overflow-x: auto !important;
				}

				/* Fix tables and wide content */
				#docx-container table {
					max-width: 100% !important;
					width: auto !important;
					overflow-x: auto !important;
					display: block !important;
				}

				#docx-container img {
					max-width: 100% !important;
					height: auto !important;
				}

				/* Fix paragraphs and text */
				#docx-container p,
				#docx-container span,
				#docx-container div {
					max-width: 100% !important;
					word-wrap: break-word !important;
					overflow-wrap: break-word !important;
				}

				/* Hide page breaks in web view */
				#docx-container .docx-page-break {
					display: none !important;
				}
			`,e.appendChild(n)}catch(t){console.error("Error rendering DOCX:",t),this.error=t?.message||s("Failed to load document")}}base64ToArrayBuffer(e){const t=atob(e),r=new Uint8Array(t.length);for(let a=0;a<t.length;a++)r[a]=t.charCodeAt(a);return r.buffer}async renderExtractedText(){const e=this.querySelector("#pptx-container");if(!(!e||!this.attachment))try{e.innerHTML="";const t=document.createElement("div");t.className="p-6 overflow-auto";const r=document.createElement("pre");r.className="whitespace-pre-wrap text-sm text-foreground font-mono",r.textContent=this.attachment.extractedText||s("No text content available"),t.appendChild(r),e.appendChild(t)}catch(t){console.error("Error rendering extracted text:",t),this.error=t?.message||s("Failed to display text content")}}};g([w()],p.prototype,"attachment");g([w()],p.prototype,"showExtractedText");g([w()],p.prototype,"error");let _=p;customElements.get("attachment-overlay")||customElements.define("attachment-overlay",_);export{_ as AttachmentOverlay};
