1import{g as w,r as l,Y as m,v as x,j as e,l as d,ar as n,h8 as k,aU as C,aI as v,aJ as g,t as A,fq as j,aL as N,bX as S,s as I,aT as q}from"./index-DXwXIAv0.js";import{A as T}from"./AdminPageHeader-BGdyM-je.js";import{I as z}from"./info-CftMfzUI.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const E=w("Webhook",[["path",{d:"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2",key:"q3hayz"}],["path",{d:"m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06",key:"1go1hn"}],["path",{d:"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8",key:"qlwsc0"}]]),b={critical:{icon:N,cls:"text-destructive",badge:"bg-destructive/10 text-destructive border-destructive/20"},warning:{icon:S,cls:"text-amber-600",badge:"bg-amber-500/10 text-amber-700 border-amber-500/20"},info:{icon:z,cls:"text-blue-600",badge:"bg-blue-500/10 text-blue-700 border-blue-500/20"}},D=r=>r==="webhook_error"?E:r.startsWith("email_")?I:N,F=()=>{const[r,u]=l.useState([]),[o,h]=l.useState(!0),[i,f]=l.useState("unresolved"),c=l.useCallback(async()=>{h(!0);let s=m.from("system_alerts").select("*").order("created_at",{ascending:!1}).limit(200);i==="unresolved"&&(s=s.eq("is_resolved",!1));const{data:t,error:a}=await s;a?x.error("Failed to load alerts",{description:a.message}):u(t??[]),h(!1)},[i]);l.useEffect(()=>{c()},[c]),l.useEffect(()=>{const s=r.filter(t=>!t.is_read).map(t=>t.id);s.length!==0&&m.from("system_alerts").update({is_read:!0}).in("id",s).then(()=>{u(t=>t.map(a=>s.includes(a.id)?{...a,is_read:!0}:a))})},[r.length]);const _=async s=>{const{error:t}=await m.from("system_alerts").update({is_resolved:!0,resolved_at:new Date().toISOString()}).eq("id",s);if(t){x.error("Could not mark resolved",{description:t.message});return}x.success("Alert resolved"),c()},p=r.filter(s=>!s.is_resolved).length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-heading text-lg font-semibold",children:"System Alerts"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Email delivery failures, webhook errors, and other infrastructure incidents."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex rounded-md border bg-muted/30 p-0.5",children:[e.jsxs(d,{size:"sm",variant:i==="unresolved"?"default":"ghost",className:"h-7 text-xs",onClick:()=>f("unresolved"),children:["Unresolved ",p>0&&e.jsx(n,{variant:"destructive",className:"ml-1.5 h-4 px-1 text-[10px]",children:p})]}),e.jsx(d,{size:"sm",variant:i==="all"?"default":"ghost",className:"h-7 text-xs",onClick:()=>f("all"),children:"All"})]}),e.jsx(d,{size:"sm",variant:"outline",onClick:c,disabled:o,children:e.jsx(k,{className:`h-3.5 w-3.5 ${o?"animate-spin":""}`})})]})]}),o?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx(C,{className:"h-24 w-full"},s))}):r.length===0?e.jsx(v,{children:e.jsxs(g,{className:"py-12 text-center",children:[e.jsx(A,{className:"mx-auto mb-3 h-10 w-10 text-emerald-500"}),e.jsxs("p",{className:"font-medium",children:["No ",i==="unresolved"?"unresolved ":"","alerts"]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"The platform is running smoothly."})]})}):e.jsx("div",{className:"space-y-2",children:r.map(s=>{const t=b[s.severity]??b.warning,a=t.icon,y=D(s.alert_type);return e.jsx(v,{className:s.is_resolved?"opacity-60":"",children:e.jsxs(g,{className:"flex flex-col gap-3 p-4 sm:flex-row sm:items-start",children:[e.jsx("div",{className:`mt-0.5 ${t.cls}`,children:e.jsx(a,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.title}),e.jsx(n,{variant:"outline",className:`text-[10px] uppercase ${t.badge}`,children:s.severity}),e.jsxs(n,{variant:"outline",className:"gap-1 text-[10px]",children:[e.jsx(y,{className:"h-3 w-3"}
6),s.alert_type.replace(/_/g," ")]}),s.is_resolved&&e.jsx(n,{variant:"outline",className:"text-[10px] text-emerald-600 border-emerald-500/30",children:"Resolved"}),(s.occurrence_count??1)>1&&e.jsxs(n,{variant:"outline",className:"text-[10px] bg-muted/40",children:["Ã",s.occurrence_count," occurrences"]})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s.message}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:["First seen ",j(new Date(s.created_at),{addSuffix:!0}),s.last_occurred_at&&s.last_occurred_at!==s.created_at&&e.jsxs(e.Fragment,{children:[" · last ",j(new Date(s.last_occurred_at),{addSuffix:!0})]})]})]}),!s.is_resolved&&e.jsx(d,{size:"sm",variant:"outline",onClick:()=>_(s.id),children:"Mark resolved"})]})},s.id)})})]})},R=()=>e.jsxs(q,{children:[e.jsx(T,{title:"Alerts",description:"Unresolved system alerts requiring attention."}),e.jsx(F,{})]});export{R 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.