import{At as e,Dt as t,J as n,Lt as r,M as i,Q as a,U as o,a as s,jt as c,kt as l,nt as u,u as d,v as f}from"./chunk.p3hCiSrt.js";var p=r(c(),1),m=e(),h=e=>new Date(e).toLocaleString(),g=e=>{let t=Date.now()-new Date(e).getTime();return t<1e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`},_=()=>{let e=l(t),[r,c]=(0,p.useState)([]),[_,v]=(0,p.useState)(null),[y,b]=(0,p.useState)(``),x=(0,p.useCallback)(async()=>{if(document.visibilityState===`visible`)try{let t=(await e.fetch(`/__devtools/api/emails`)).data;c(t?.emails??[])}catch{}},[e]);(0,p.useEffect)(()=>{x();let e=setInterval(x,1e4);return()=>clearInterval(e)},[x]);let S=r.filter(e=>{if(!y)return!0;let t=y.toLowerCase();return e.to.toLowerCase().includes(t)||e.subject.toLowerCase().includes(t)}),C=_===null?null:S[_];return(0,m.jsxs)(s,{style:{flex:1,overflow:`hidden`},direction:`column`,children:[(0,m.jsxs)(s,{px:`md`,py:`xs`,gap:`sm`,align:`center`,style:{borderBottom:`1px solid ${d.colors.border}`,flexShrink:0},children:[(0,m.jsx)(i,{size:`xs`,placeholder:`Search...`,leftSection:(0,m.jsx)(f,{size:14}),value:y,onChange:e=>b(e.currentTarget.value),style:{flex:1,minWidth:150,maxWidth:300}}),(0,m.jsxs)(o,{variant:`light`,color:`gray`,size:`sm`,children:[S.length,` emails`]})]}),(0,m.jsxs)(s,{style:{flex:1,overflow:`hidden`},children:[(0,m.jsx)(s,{direction:`column`,style:{flex:1,overflow:`hidden`},children:(0,m.jsxs)(u,{style:{flex:1},children:[S.length===0&&(0,m.jsx)(s,{align:`center`,justify:`center`,py:`xl`,c:`dimmed`,children:(0,m.jsx)(n,{fz:`sm`,children:`No emails to display`})}),S.map((e,t)=>{let r=_===t;return(0,m.jsxs)(s,{direction:`column`,px:`md`,py:`xs`,onClick:()=>v(r?null:t),style:{borderBottom:`1px solid ${d.colors.border}20`,background:r?d.colors.elevated:`transparent`,cursor:`pointer`,transition:`background 100ms`},onMouseEnter:e=>{r||(e.currentTarget.style.background=`${d.colors.elevated}80`)},onMouseLeave:e=>{r||(e.currentTarget.style.background=`transparent`)},children:[(0,m.jsxs)(s,{justify:`space-between`,align:`center`,children:[(0,m.jsx)(n,{fz:`sm`,truncate:!0,children:e.to}),(0,m.jsx)(n,{fz:11,c:`dimmed`,style:{flexShrink:0},children:g(e.sentAt)})]}),(0,m.jsx)(n,{fz:`xs`,c:`dimmed`,truncate:!0,children:e.subject})]},`${e.sentAt}-${t}`)})]})}),C&&(0,m.jsxs)(s,{w:500,direction:`column`,style:{borderLeft:`1px solid ${d.colors.border}`,flexShrink:0,overflow:`hidden`},children:[(0,m.jsxs)(s,{px:`md`,py:`xs`,align:`center`,justify:`space-between`,style:{borderBottom:`1px solid ${d.colors.border}`,flexShrink:0},children:[(0,m.jsx)(n,{fz:`xs`,fw:600,tt:`uppercase`,c:`dimmed`,lts:.5,children:`Email Detail`}),(0,m.jsx)(a,{size:`xs`,onClick:()=>v(null)})]}),(0,m.jsx)(u,{style:{flex:1},p:`md`,children:(0,m.jsxs)(s,{direction:`column`,gap:`md`,children:[(0,m.jsxs)(s,{direction:`column`,children:[(0,m.jsx)(n,{fz:10,c:`dimmed`,tt:`uppercase`,fw:600,lts:.5,mb:4,children:`To`}),(0,m.jsx)(n,{fz:`xs`,children:C.to})]}),(0,m.jsxs)(s,{direction:`column`,children:[(0,m.jsx)(n,{fz:10,c:`dimmed`,tt:`uppercase`,fw:600,lts:.5,mb:4,children:`Date`}),(0,m.jsx)(n,{fz:`xs`,children:h(C.sentAt)})]}),(0,m.jsxs)(s,{direction:`column`,children:[(0,m.jsx)(n,{fz:10,c:`dimmed`,tt:`uppercase`,fw:600,lts:.5,mb:4,children:`Subject`}),(0,m.jsx)(n,{fz:`xs`,children:C.subject})]}),(0,m.jsxs)(s,{direction:`column`,children:[(0,m.jsx)(n,{fz:10,c:`dimmed`,tt:`uppercase`,fw:600,lts:.5,mb:4,children:`Body`}),(0,m.jsx)(`div`,{style:{background:`white`,color:`#333`,border:`1px solid #ccc`,borderRadius:4,padding:12},dangerouslySetInnerHTML:{__html:C.body}})]})]})})]})]})]})};export{_ as DevEmails,_ as default};