1import{c as R,r,q as j,aq as p,j as e,T as c}from"./app-PfWi3kO6.js";import{T as v,a as b,b as o,c as i,d as T,e as a}from"./table-DAl7Yr1a.js";import{B as x}from"./badge-Dj4w2ajA.js";import{T as q,a as E,b as w,c as k}from"./tabs-OYERxJAa.js";const u=d=>d?new Date(d).toLocaleString("en-GB"):"â",$=()=>{R("Monitoring & Schedules");const[d,_]=r.useState([]),[h,C]=r.useState([]),[y,f]=r.useState(!0),[n,g]=r.useState(null),m=r.useCallback(async()=>{f(!0);const[s,l]=await Promise.all([j.fetch("/api/admin/monitored-sites",{method:"GET"}),j.fetch("/api/admin/tool-schedules",{method:"GET"})]);!s.error&&s.data&&_(s.data.monitoredSites),!l.error&&l.data&&C(l.data.schedules),(s.error||l.error)&&p.error("Failed to load monitoring data"),f(!1)},[]);r.useEffect(()=>{m()},[m]);const t=async(s,l,S,P)=>{g(s);const{error:N}=await j.fetch(l,{method:S,body:P});N?p.error(N.message||"Action failed"):(p.success("Done"),await m()),g(null)};return e.jsxs("div",{className:"container mx-auto px-0 py-4 sm:px-6 sm:py-10 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Monitoring & Schedules"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:'Recurring quick checks, monthly Full audits and per-tool schedules across all orgs. The org credit balance is inline so "went quiet because the pool is empty" is one row. "Run now" sets the next run to now so the cron picks it up on its next tick.'})]}),y?e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loadingâ¦"}):e.jsxs(q,{defaultValue:"monitored",children:[e.jsxs(E,{children:[e.jsxs(w,{value:"monitored",children:["Monitored sites (",d.length,")"]}),e.jsxs(w,{value:"schedules",children:["Tool schedules (",h.length,")"]})]}),e.jsx(k,{value:"monitored",children:d.length===0?e.jsx("div",{className:"text-sm text-muted-foreground",children:"No monitored sites."}):e.jsx("div",{className:"-mx-2 overflow-x-auto sm:mx-0",children:e.jsxs(v,{className:"min-w-[960px]",children:[e.jsx(b,{children:e.jsxs(o,{children:[e.jsx(i,{children:"Domain"}),e.jsx(i,{children:"Org"}),e.jsx(i,{children:"Cadence"}),e.jsx(i,{children:"Credits"}),e.jsx(i,{children:"Next quick"}),e.jsx(i,{children:"Next full"}),e.jsx(i,{children:"Actions"})]})}),e.jsx(T,{children:d.map(s=>e.jsxs(o,{className:s.paused?"opacity-60":"",children:[e.jsx(a,{className:"font-medium",title:s.url,children:s.domain}),e.jsx(a,{className:"text-sm",children:s.org_name??s.owner_email??"â"}),e.jsxs(a,{children:[e.jsx(x,{variant:"outline",children:s.cadence}),s.paused&&e.jsx(x,{variant:"secondary",className:"ml-1",children:"paused"})]}),e.jsx(a,{className:s.credits_remaining===0?"text-red-600 font-medium":"",children:s.credits_remaining}),e.jsx(a,{className:"text-xs text-muted-foreground",children:u(s.next_quick_check_at)}),e.jsx(a,{className:"text-xs text-muted-foreground",children:u(s.next_full_audit_at)}),e.jsx(a,{children:e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[e.jsx(c,{size:"sm",variant:"outline",disabled:n===s.id,onClick:()=>t(s.id,`/api/admin/monitored-sites/${s.id}`,"PATCH",{paused:!s.paused}),children:s.paused?"Resume":"Pause"}),e.jsx(c,{size:"sm",variant:"ghost",disabled:n===s.id,onClick:()=>t(s.id,`/api/admin/monitored-sites/${s.id}/run-now`,"POST",{kind:"quick"}),children:"Run quick"}),e.jsx(c,{size:"sm",variant:"ghost",disabled:n===s.id,onClick:()=>t(s.id,`/api/admin/monitored-sites/${s.id}/run-now`,"POST",{kind:"full"}),children:"Run full"})]})})]},s.id))})]})})}),e.jsx(k,{value:"schedules",children:h.length===0?e.jsx("div",{className:"text-sm text-muted-foreground",children:"No tool schedules."}):e.jsx("div",{className:"-mx-2 overflow-x-auto sm:mx-0",children:e.jsxs(v,{className:"min-w-[900px]",children:[e.jsx(b,{children:e.jsxs(o,{children:[e.jsx(i,{children:"Site"}),e.jsx(i,{children:"Tool"}),e.jsx(i,{children:"Cadence"}),e.jsx(i,{children:"Credits"}),e.jsx(i,{children:"Next run"}),e.jsx(i,{children:"Last run"}),e.jsx(i,{children:"Actions"})]})}),e.jsx(T,{children:h.map(s=>e.jsxs(o,{className:s.paused?"opacity-60":"",children:[e.jsx(a,{className:"font-medium",children:s.domain??"â"}),e.jsx(a,{children:e.jsx(x,{variant:"outline",children:s.tool_id})}),e.jsxs(a,{children:[s.cadence,s.paused&&e.jsx(x,{variant:"secondary",className:"ml-1",children:"paused"})]}),e.jsx(a,{className:s.credits_remaining===0?"text-red-600 font-medium":"",children:s.credits_remaining}),e.jsx(a,{className:"text-xs text-muted-foreground",children:u(s.next_run_at)}),e.jsx(a,{className:"text-xs text-muted-foreground",children:u(s.last_run_at)}),e.jsx(a,{children:e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[e.jsx(c,{size:"sm",variant:"outline",disabled:n===s.id,onClick:()=>t(s.id,`/api/admin/tool-schedules/${s.id}`,"PATCH",{paused:!s.paused}),children:s.paused?"Resume":"Pause"}),e.jsx(c,{size:"sm",variant:"ghost",disabled:n===s.id,onClick:()=>t(s.id,`/api/admin/tool-schedules/${s.id}/run-now`,"POST"),children:"Run now"}),e.jsx(c,{size:"sm",variant:"destructive",disabled:n===s.id,onClick:()=>t(s.id,`/api/admin/tool-schedules/${s.id}`,"DELETE"),children:"Delete"})]})})]},s.id))})]})})})]})]})};export{$ 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.