1import{j as e,R as h,I as u,T as i,o as m,s as p,a8 as j}from"./index-Db4qfLtJ.js";function b(){return m({queryKey:["admin","writeups-health"],queryFn:async()=>{const{data:{session:s}}=await p.auth.getSession();if(!s)throw new Error("Not authenticated");const a=await fetch(`${j}/api/superadmin/writeups-health`,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`}});if(!a.ok){const r=await a.json().catch(()=>({}));throw new Error(r.error||`HTTP ${a.status}`)}return a.json()},staleTime:3e4,refetchInterval:6e4})}function l(s){return s==null?e.jsx("span",{className:"text-slate-400",children:"â"}):e.jsxs("span",{className:"tabular-nums",children:[s,"%"]})}function n(s){if(s==null)return e.jsx("span",{className:"text-slate-400",children:"â"});if(s<60)return e.jsxs("span",{className:"tabular-nums",children:[s,"m"]});const a=Math.floor(s/60),r=s%60;return e.jsxs("span",{className:"tabular-nums",children:[a,"h ",r,"m"]})}function N(){const{data:s,isLoading:a,isError:r,error:d,refetch:c,isFetching:x}=b();return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Writeups Health"}),e.jsxs("p",{className:"text-sm text-slate-500",children:["Last 7 days. Auto-refreshes every minute. Source:"," ",e.jsx("code",{className:"font-mono text-xs",children:"/api/superadmin/writeups-health"})]})]}),e.jsxs("button",{onClick:()=>c(),className:"flex items-center gap-1.5 rounded border border-slate-200 bg-white px-2.5 py-1 text-xs text-slate-700 hover:bg-slate-50",children:[e.jsx(h,{size:12,className:x?"animate-spin":""}),"Refresh"]})]}),a&&e.jsx("div",{className:"text-sm text-slate-500",children:"Loadingâ¦"}),r&&e.jsxs("div",{className:"rounded border border-rose-200 bg-rose-50 p-3 text-sm text-rose-700",children:["Failed to load: ",u(d)]}),s&&e.jsxs(e.Fragment,{children:[s.subquery_errors&&s.subquery_errors.length>0&&e.jsxs("div",{className:"rounded border border-rose-200 bg-rose-50 p-3 text-sm text-rose-800",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold",children:[e.jsx(i,{size:16,className:"shrink-0"}),e.jsxs("span",{children:[s.subquery_errors.length," health query failed â metrics below may be incomplete"]})]}),e.jsx("ul",{className:"mt-2 space-y-1 pl-6 text-xs",children:s.subquery_errors.map((t,o)=>e.jsxs("li",{children:[e.jsx("code",{className:"font-mono",children:t.source}),": ",t.message]},o))})]}),e.jsxs("div",{className:"rounded border border-slate-200 bg-white",children:[e.jsx("div",{className:"border-b border-slate-100 px-3 py-1.5 text-xs font-semibold uppercase tracking-wide text-slate-600",children:"Queue + audit"}),e.jsx("table",{className:"w-full text-sm",children:e.jsxs("tbody",{className:"divide-y divide-slate-100",children:[e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"PDF retry queue â pending"}),e.jsxs("td",{className:"px-3 py-1.5 text-right tabular-nums",children:[e.jsx("span",{className:s.queue.pdf_jobs_pending>0?"font-semibold text-amber-600":"text-slate-700",children:s.queue.pdf_jobs_pending}),s.queue.oldest_pending_age_minutes!=null&&e.jsxs("span",{className:"ml-2 text-xs text-slate-500",children:["(oldest: ",n(s.queue.oldest_pending_age_minutes),")"]})]})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"PDF retry queue â failed (max attempts)"}),e.jsx("td",{className:"px-3 py-1.5 text-right tabular-nums",children:e.jsx("span",{className:s.queue.pdf_jobs_failed_total>0?"font-semibold text-rose-600":"text-slate-700",children:s.queue.pdf_jobs_failed_total})})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"SMS-failed audit rows (last 24h)"}),e.jsx("td",{className:"px-3 py-1.5 text-right tabular-nums",children:e.jsx("span",{className:s.audit.sms_failed_count_24h>0?"font-semibold text-rose-600":"text-slate-700",children:s.audit.sms_failed_count_24h})})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"Auto-expired writeups today"}),e.jsx("td",{className:"px-3 py-1.5 text-right tabular-nums",children:s.audit.expired_today_count})]})]})})]}),e.jsxs("div",{className:"rounded border border-slate-200 bg-white",children:[e.jsx("div",{className:"border-b border-slate-100 px-3 py-1.5 text-xs font-semibold uppercase tracking-wide text-slate-600",children:"Per company (last 7 days)"}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-xs font-medium text-slate-600",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left",children:"DSP"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Writeups"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Sent"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Sign rate"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Refusal rate"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Avg time to sign"})]})}),e.jsxs("tbody",{className:"divide-y divide-slate-100",children:[s.companies.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-3 py-4 text-center text-slate-500",children:"No companies in this account."})}),s.companies.map(t=>e.jsxs("tr",{children:[e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium text-slate-900",children:t.company_name}),t.short_code&&e.jsx("div",{className:"font-mono text-xs text-slate-500",children:t.short_code})]}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:t.writeups_7d}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:t.sent_7d}),e.jsx("td",{className:"px-3 py-2 text-right",children:l(t.sign_rate_pct)}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:t.refusal_rate_pct!=null&&t.refusal_rate_pct>20?"font-semibold text-amber-600":"",children:l(t.refusal_rate_pct)})}),e.jsx("td",{className:"px-3 py-2 text-right",children:n(t.avg_minutes_to_sign)})]},t.company_id))]})]})]}),s.audit.audit_gaps_24h!=null&&s.audit.audit_gaps_24h>0&&e.jsxs("div",{className:"flex items-start gap-2 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-sm text-rose-800",children:[e.jsx(i,{size:16,className:"mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("strong",{children:s.audit.audit_gaps_24h})," audit gaps detected in the last 24h. Investigate: writeup status changed without a matching audit row. The writeup_transition_with_audit RPC should make this impossible â a non-zero count suggests a direct UPDATE bypassing the state machine."]})]})]})]})}export{N 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.