(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,27173,e=>{"use strict";var t=e.i(90795),s=e.i(12283),r=e.i(59369);function l(){let{hasMail:e,mailApiUrl:l}=(0,s.useDevState)(),[a,n]=(0,r.useState)([]),[o,i]=(0,r.useState)(null),[c,d]=(0,r.useState)(null),[m,x]=(0,r.useState)("html"),u=(0,r.useRef)(null),f=(0,r.useCallback)(async()=>{if(l)try{let e=await fetch(`${l}/api/emails`);e.ok&&n(await e.json())}catch{}},[l]),h=(0,r.useCallback)(async()=>{if(l)try{await fetch(`${l}/api/emails`,{method:"DELETE"}),n([]),i(null),d(null)}catch{}},[l]);return((0,r.useEffect)(()=>{f();let e=setInterval(f,2e3);return()=>clearInterval(e)},[f]),(0,r.useEffect)(()=>{o&&l?async function(){try{let e=await fetch(`${l}/api/emails/${o}`);if(e.ok){let t=await e.json();d(t)}}catch{}}():d(null)},[o,l]),(0,r.useEffect)(()=>{if(u.current&&c?.html&&"html"===m){let e=u.current.contentDocument;e&&(e.open(),e.write(c.html),e.close())}},[c,m]),e)?(0,t.jsxs)("main",{className:"flex-1 overflow-hidden flex",children:[(0,t.jsxs)("div",{className:"w-80 border-r border-border flex flex-col overflow-hidden",children:[(0,t.jsxs)("div",{className:"p-3 border-b border-border flex items-center justify-between",children:[(0,t.jsxs)("span",{className:"text-sm font-medium text-muted-foreground",children:[a.length," ",1===a.length?"email":"emails"]}),a.length>0&&(0,t.jsx)("button",{onClick:h,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"Clear all"})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===a.length?(0,t.jsx)("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No emails captured yet. Send an email via SMTP to see it here."}):a.map(e=>(0,t.jsxs)("button",{onClick:()=>i(e.id),className:`w-full text-left p-3 border-b border-border hover:bg-accent transition-colors cursor-pointer ${o===e.id?"bg-accent":""}`,children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"text-sm font-medium truncate",children:e.from||"(no sender)"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date(e.date).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}),(0,t.jsx)("div",{className:"text-sm truncate mt-0.5",children:e.subject||"(no subject)"}),(0,t.jsxs)("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:["To: ",e.to.join(", ")]})]},e.id))})]}),(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden",children:c?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"p-4 border-b border-border",children:[(0,t.jsx)("h2",{className:"text-lg font-semibold",children:c.subject||"(no subject)"}),(0,t.jsxs)("div",{className:"mt-2 text-sm text-muted-foreground space-y-0.5",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:"From:"})," ",c.from]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:"To:"})," ",c.to.join(", ")]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:"Date:"})," ",new Date(c.date).toLocaleString()]})]}),c.html&&c.text&&(0,t.jsxs)("div",{className:"mt-3 flex gap-1",children:[(0,t.jsx)("button",{onClick:()=>x("html"),className:`px-2 py-1 text-xs rounded ${"html"===m?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,children:"HTML"}),(0,t.jsx)("button",{onClick:()=>x("text"),className:`px-2 py-1 text-xs rounded ${"text"===m?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,children:"Plain Text"})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-auto",children:"html"===m&&c.html?(0,t.jsx)("iframe",{ref:u,className:"w-full h-full border-0 bg-white",sandbox:"allow-same-origin",title:"Email content"}):(0,t.jsx)("pre",{className:"p-4 text-sm whitespace-pre-wrap font-mono",children:c.text||"(no content)"})})]}):(0,t.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:a.length>0?"Select an email to view":"Waiting for emails..."})})]}):(0,t.jsx)("main",{className:"flex-1 overflow-hidden",children:(0,t.jsx)("div",{className:"p-6",children:(0,t.jsxs)("div",{className:"p-6 rounded-lg bg-card border border-border text-center",children:[(0,t.jsx)("p",{className:"text-muted-foreground",children:"No mail service configured."}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Add a mail block to your specific.hcl to capture emails."})]})})})}function a(){return(0,t.jsx)(l,{})}e.s(["default",()=>a],27173)}]);