1import{s as L,r as l,a as f,j as e,C as y,J as N,G as H,B as c,L as D,at as g,ar as b,o as v,aM as P,aO as E,af as B}from"./index-D1gByzCh.js";import{S as $,a as G,b as O,c as _,d as q}from"./sheet-CZ4IqoKW.js";import{A as z}from"./arrow-left-C06HTsOD.js";const o=50,S={sent:"Sent",failed:"Failed",skipped:"Skipped",data_error:"Data Error",pending:"Pending"};function w(r){switch(r){case"sent":return"default";case"failed":case"data_error":return"destructive";case"skipped":return"secondary";default:return"outline"}}function K(){const{user:r,isAuthenticated:C}=L(),[n,m]=l.useState(0),[x,k]=l.useState(null),[h,u]=l.useState(!1),{data:a,isLoading:A}=f({queryKey:[`/api/admin/hourly-reports?limit=${o}&offset=${n*o}`]}),{data:t,isLoading:M}=f({queryKey:[`/api/admin/hourly-reports/${x}`],enabled:!!x&&h});if(!C||!(r!=null&&r.isAdmin))return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(y,{children:e.jsx(N,{className:"pt-6",children:e.jsx("p",{children:"Admin access required."})})})});const p=(a==null?void 0:a.reports)??[],j=(a==null?void 0:a.total)??0,d=Math.ceil(j/o);return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b bg-background/95 backdrop-blur",children:e.jsx("div",{className:"container mx-auto px-4 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(H,{className:"h-6 w-6"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Hourly Reports"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Persisted hourly scraping reports â readable even when the email fails"})]})]}),e.jsx(c,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(D,{href:"/admin",children:[e.jsx(z,{className:"h-4 w-4 mr-2"}),"Admin Dashboard"]})})]})})}),e.jsxs("main",{className:"container mx-auto px-4 py-8 space-y-6",children:[A?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(g,{className:"h-6 w-6 animate-spin"})}):p.length===0?e.jsx(y,{children:e.jsx(N,{className:"pt-6 text-center text-muted-foreground",children:"No report records yet â records appear after the next hourly report cycle."})}):e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-4 py-2 font-medium",children:"Generated"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Subject"}),e.jsx("th",{className:"px-4 py-2 font-medium hidden md:table-cell",children:"Detail"})]})}),e.jsx("tbody",{children:p.map(s=>{const i=s.sendStatus==="sent"||s.sendStatus==="failed"||s.sendStatus==="pending";return e.jsxs("tr",{"data-testid":`row-report-${s.id}`,className:`border-t ${i?"cursor-pointer hover:bg-muted/30":""}`,onClick:()=>{i&&(k(s.id),u(!0))},children:[e.jsx("td",{className:"px-4 py-2 whitespace-nowrap",children:b(new Date(s.generatedAt),"MMM d, HH:mm")}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(v,{variant:w(s.sendStatus),children:S[s.sendStatus]||s.sendStatus})}),e.jsx("td",{className:"px-4 py-2 max-w-md truncate",children:s.subject}),e.jsx("td",{className:"px-4 py-2 hidden md:table-cell text-xs text-muted-foreground max-w-sm truncate",children:s.errorMessage||(i?"Click to view report":"")})]},s.id)})})]})}),d>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Page ",n+1," of ",d," â ",j.toLocaleString()," records"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",disabled:n===0,onClick:()=>m(s=>s-1),children:[e.jsx(P,{className:"h-4 w-4"})," Prev"]}),e.jsxs(c,{variant:"outline",size:"sm",disabled:n+1>=d,onClick:()=>m(s=>s+1),children:["Next ",e.jsx(E,{className:"h-4 w-4"})]})]})]})]}),e.jsx($,{open:h,onOpenChange:u,children:e.jsxs(G,{className:"w-full sm:max-w-3xl overflow-y-auto",children:[e.jsxs(O,{children:[e.jsx(_,{children:(t==null?void 0:t.subject)??"Hourly Report"}),e.jsx(q,{children:t&&e.jsxs(e.Fragment,{children:["Generated ",b(new Date(t.generatedAt),"MMM d, yyyy HH:mm")," â ",e.jsx(v,{variant:w(t.sendStatus),children:S[t.sendStatus]||t.sendStatus}),t.errorMessage&&e.jsx("span",{className:"block mt-1 text-destructive",children:t.errorMessage})]})})]}),e.jsx("div",{className:"mt-4",children:M?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(g,{className:"h-6 w-6 animate-spin"})}):t!=null&&t.html?e.jsx("iframe",{title:"Hourly report",sandbox:"",srcDoc:t.html,className:"w-full min-h-[70vh] border rounded bg-white"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No report body stored for this cycle."})})]})}),e.jsx(B,{})]})}
1export{K as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.