PageSourceSearch

https://zorganicsinstitute.edu/assets/ComplianceReminderPanel-DkB5k_py.js

js zorganicsinstitute.edu collected 2026-09-30 15:11:37 UTC 223,047 bytes, 17 lines download raw bytes

1import{at as ys,r,s as D,j as e,c as Ye,L as X,aH as Se,ac as Nt,au as Rs,av as ce,Y as le,bg as je,a2 as _t,cB as js,c7 as zs,d as tt,f as ke,k as Ee,cC as Ts,X as Ie,c5 as $s,b3 as qt,bf as Re,aK as Rt,ax as Ds,aM as As,a6 as st,b1 as Le,an as Fe,b4 as We,aU as Es,bo as Kt,aB as Ms,bc as Qt,U as es,v as Ls,bm as zt,aE as Ns,ao as et,A as Fs,bq as Ht,bH as Gt,g as dt,cD as vs,y as Wt,b0 as Yt,a8 as Zt,ba as vt,c0 as Is,z as Vt,c8 as ts,C as Bs,aC as ss,cE as Tt,cF as ut,ar as Ps,az as ws,cG as gt,a_ as wt,a3 as as,aS as _s,cH as Us,F as ks,aY as Os,bZ as rs,bU as Hs,aG as ls,c3 as ns}from"./index-D6t_VXza.js";import{m as Gs,l as Ws}from"./useDatabase-8-2EZMfa.js";import{C as Ys}from"./circle-dot-D5bIyGR5.js";import{S as qs}from"./shield-x-DKUGRuUX.js";import{K as Ks}from"./key-BdKZFs0F.js";import{W as is}from"./wifi-off-Dm92qTLj.js";import{W as Zs}from"./wifi-CA28wzmN.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 os=ys("Link2Off",[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Vs=ys("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);function Ve(n){const v=[];let f=0,t=1;for(;f<n;){const N=Math.min(f+450,n);if(v.push({period:t,startHours:f,endHours:N,label:`Period ${t}: ${f}–${N}h`}),f=N,t++,N>=n)break}return v}const $t={lateFeeAmount:2500,nsfFeeAmount:3500,paymentDueDay:10,lateFeeDay:11,interestRate:0,maxLoanTerm:24},nt={paymentReminders:[1,8,11]},Js=[{key:"instructor",name:"Instructor Training",totalHours:600,theoryHours:390,practicalHours:210,textbook:"Milady Master Educator",textbookEdition:"4th Edition",textbookISBN:"978-1337786843",paymentPeriods:Ve(600),milestones:[{hours:120,label:"Phase 1 Foundations Complete",type:"academic",emailTemplate:"phase1_complete",description:"Completed foundational teaching theory modules (Ch 1–4)"},{hours:300,label:"50% Milestone",type:"academic",emailTemplate:"halfway",description:"Halfway through Instructor Training program"},{hours:390,label:"Theory Complete (390h)",type:"compliance",emailTemplate:"theory_complete_instructor",description:"All 390 theory hours completed — transition to practicum"},{hours:600,label:"Graduation",type:"graduation",emailTemplate:"graduation",description:"Instructor Training program complete — eligible for WA Instructor License"}],defaultTuition:75e4,defaultKitFee:5e4,defaultRegistration:15e3,programColor:"#7c3aed",description:"Milady CIMA 600-Hour Instructor Training — 390h Theory / 210h Practical"},{key:"cosmetology",name:"Cosmetology",totalHours:1600,theoryHours:560,practicalHours:1040,textbook:"Milady Standard Cosmetology",textbookEdition:"14th Edition",textbookISBN:"978-0357871492",hb1874Required:!0,paymentPeriods:Ve(1600),milestones:[{hours:160,label:"Phase 1 Foundations Complete",type:"academic",emailTemplate:"phase1_complete",description:"Completed foundational theory and safety modules"},{hours:450,label:"Payment Period 1 Complete",type:"compliance",emailTemplate:"payment_period",description:"First 450h payment period complete — Title IV disbursement trigger"},{hours:800,label:"50% Milestone",type:"academic",emailTemplate:"halfway",description:"Halfway through Cosmetology program"},{hours:900,label:"Payment Period 2 Complete",type:"compliance",emailTemplate:"payment_period",description:"Second 450h payment period complete"},{hours:1e3,label:"Floor Ready (1,000h)",type:"clinical",emailTemplate:"floor_ready_cosmetology",description:"HB 1874 Textured Hair milestones complete — Full floor privileges"},{hours:1250,label:"Payment Period 3 Complete",type:"compliance",emailTemplate:"payment_period",description:"Third payment period complete"},{hours:1600,label:"Graduation",type:"graduation",emailTemplate:"graduation",description:"Cosmetology program complete — eligible for WA Cosmetology License"}],defaultTuition:18e5,defaultKitFee:15e4,defaultRegistration:15e3,programColor:"#800020",description:"Milady Standard Cosmetology 14e — Includes HB 1874 Textured Hair milestones"},{key:"esthetics",name:"Basic Esthetics",totalHours:750,theoryHours:263,practicalHours:487,textbook:"Milady Standard Esthetics: Fundamentals",textbookEdition:"12th Edition",textbookISBN:"978-0357263747",paymentPeriods:Ve(750),milestones:[{hours:113,label:"Phase 1 Foundations Complete",type:"academic",emailTemplate:"phase1_complete",description:"Completed foundational theory modules"},{hours:375,label:"50% Milestone",type:"academic",emailTemplate:"halfway",description:"Halfway through Basic Esthetics program"},{hours:450,label:"Payment Period 1 Complete",type:"compliance",emailTemplate:"payment_period",description:"First 450h payment period complete"},{hours:750,label:"Graduation",type:"graduation",emailTemplate:"graduation",description:"Basic Esthetics program complete — eligible for WA Esthetics License"}],defaultTuition:105e4,defaultKitFee:1e5,defaultRegistration:15e3,programColor:"#D4AF37",description:"Milady Standard Esthetics: Fundamentals 12e — WA 750-Hour Program"},{key:"master-esthetics",name:"Master Esthetics Bridge",totalHours:450,theoryHours:135,practicalHours:315,textbook:"Milady Standard Esthetics: Advanced",textbookEdition:"3rd Edition",textbookISBN:"978-0357263754",clinicalGoldTheme:!0,paymentPeriods:Ve(450),milestones:[{hours:54,label:"Phase 1 Foundations Complete",type:"academic",emailTemplate:"phase1_complete",description:"Completed advanced theory foundations"},{hours:225,label:"50% Milestone",type:"academic",emailTemplate:"halfway",description:"Halfway through Master Esthetics Bridge"},{hours:450,label:"Graduation",type:"graduation",emailTemplate:"graduation",description:"Master Esthetics Bridge complete — eligible for WA Master Esthetics License"}],defaultTuition:65e4,defaultKitFee:75e3,defaultRegistration:15e3,programColor:"#B8860B",description:"Milady Standard Esthetics: Advanced 3e — Clinical Gold Theme — 450h Bridge Program"},{key:"manicuring",name:"Manicuring",totalHours:600,theoryHours:240,practicalHours:360,textbook:"Milady Standard Nail Technology",textbookEdition:"8th Edition",textbookISBN:"978-0357446836",paymentPeriods:Ve(600),milestones:[{hours:120,label:"Phase 1 Foundations Complete",type:"academic",emailTemplate:"phase1_complete",description:"Completed foundational nail theory modules"},{hours:300,label:"50% Milestone",type:"academic",emailTemplate:"halfway",description:"Halfway through Manicuring program"},{hours:450,label:"Payment Period 1 Complete",type:"compliance",emailTemplate:"payment_period",description:"First 450h payment period complete"},{hours:600,label:"Graduation",type:"graduation",emailTemplate:"graduation",description:"Manicuring program complete — eligible for WA Manicurist License"}],defaultTuition:65e4,defaultKitFee:8e4,defaultRegistration:15e3,programColor:"#2D5A27",description:"Milady Standard Nail Technology 8e — WA 600-Hour Program"},{key:"combined-master-esthetics",name:"Combined Master Esthetics",totalHours:1200,theoryHours:398,practicalHours:802,textbook:"Milady Standard Esthetics: Fundamentals 12e + Advanced 3e",textbookEdition:"Combined 12th/3rd Edition",textbookISBN:"978-0357263747 / 978-0357263754",hb1874Required:!0,paymentPeriods:Ve(1200),milestones:[{hours:113,label:"Phase 1 Foundations Complete",type:"academic",emailTemplate:"phase1_complete",description:"Completed foundational theory modules — Milady Fundamentals"}
11,{hours:375,label:"25% Milestone (375h)",type:"academic",emailTemplate:"quarter",description:"Quarter-way through Combined Master Esthetics program"},{hours:450,label:"Payment Period 1 Complete",type:"compliance",emailTemplate:"payment_period",description:"First 450h payment period complete — Title IV disbursement trigger"},{hours:600,label:"50% Milestone (600h)",type:"academic",emailTemplate:"halfway",description:"Halfway through Combined Master Esthetics program"},{hours:750,label:"Foundation Complete — Entering Clinical Master Phase",type:"clinical",emailTemplate:"foundation_to_master_transition",description:"Congratulations on completing your Foundation! You are now entering the Clinical Master Phase. Theme transitions from Zorganics Burgundy (Holistic) to Clinical Gold (Master)."},{hours:900,label:"Payment Period 2 Complete",type:"compliance",emailTemplate:"payment_period",description:"Second 450h payment period complete — Title IV disbursement trigger"},{hours:1e3,label:"Clinical Mastery (1,000h)",type:"clinical",emailTemplate:"clinical_mastery",description:"Advanced clinical competency achieved — Dermaplaning, Hydrodermabrasion, Radiofrequency"},{hours:1200,label:"WA State Master Esthetics License Eligible",type:"graduation",emailTemplate:"graduation_master_esthetics",description:"You have met the requirements for the WA State Master Esthetics License. Congratulations!"}],defaultTuition:165e4,defaultKitFee:15e4,defaultRegistration:15e3,clinicalGoldTheme:!1,programColor:"#6B1D3A",description:"Combined 1,200h Master Esthetics — Burgundy Holistic (0–750h) → Clinical Gold Master (750–1,200h). Includes both Esthetics Student Clinic and Master Esthetics Student Clinic access."},{key:"eyelash",name:"Eyelash Specialist",totalHours:80,theoryHours:24,practicalHours:56,textbook:"Zorganics Eyelash Extension Manual",textbookEdition:"1st Edition (Proprietary)",eyelashModule:!0,paymentPeriods:[{period:1,startHours:0,endHours:80,label:"Full Program"}],milestones:[{hours:24,label:"Theory Complete",type:"academic",emailTemplate:"theory_complete",description:"Eyelash theory and safety modules complete"},{hours:80,label:"Certification",type:"graduation",emailTemplate:"eyelash_certification",description:"Eyelash Specialist certification complete"}],defaultTuition:15e4,defaultKitFee:35e3,defaultRegistration:5e3,programColor:"#ec4899",description:"Standalone 2–3 Week Eyelash Extension Module — Reduced Fee"}];function Ta(n){const v=n.toLowerCase();return Js.find(m=>m.name.toLowerCase().includes(v)||m.key.toLowerCase().includes(v))}function $a(n,v,m){const f=n>0,t=v>=m;return{locked:f,hoursComplete:t,certificationBlocked:f,hoursExportBlocked:f,reason:f?`Outstanding balance of $${(n/100).toFixed(2)}
11 must be paid before certification and hours export.`:t?"All requirements met — eligible for graduation.":`${m-v} hours remaining.`}}function Da(n,v,m,f){const t=n-v,N=Math.max(0,t),S=m>=f;return{creditBalance:N,canRefund:S&&N>0,refundAmount:S?N:0,holdReason:S?N>0?"Program complete — credit balance eligible for refund.":"No credit balance.":"Credit held — will auto-apply to next payment period. Final refund issued only after 100% program completion."}}const be="#6B1D3A",Ge="#4A1228",Ce="#C5A572",Dt=new Set(["unknown_shape","mailgun_public_validation_key","paste_error_basic_prefix","paste_error_bearer_prefix"]),ds=n=>{const v=new Date(n).getTime(),m=Date.now(),f=Math.max(0,Math.floor((m-v)/1e3));return f<60?`${f}s ago`:f<3600?`${Math.floor(f/60)}m ago`:f<86400?`${Math.floor(f/3600)}h ago`:`${Math.floor(f/86400)}d ago`},Xs=n=>n.replace(/_/g," "),Qs=()=>{const[n,v]=r.useState([]),[m,f]=r.useState(!0),[t,N]=r.useState(!1),[S,z]=r.useState(null),[l,A]=r.useState(null),o=r.useCallback(async()=>{f(!0);try{const{data:x,error:w}=await D.from("mailgun_health_log").select("*").order("probed_at",{ascending:!1}).limit(30);w?(console.error("Failed to fetch mailgun_health_log:",w),v([])):v(x||[])}catch(x){console.error("Mailgun health fetch exception:",x),v([])}f(!1)},[]);r.useEffect(()=>{o()},[o]);const y=async()=>{N(!0),z(null),A(null);try{const{data:x,error:w}=await D.functions.invoke("cron-mailgun-health-check",{body:{trigger_source:"manual"}});w?z(w.message||"Probe invocation failed"):(x==null?void 0:x.ok)===!1&&(x!=null&&x.error)?z(x.error):A({ok:(x==null?void 0:x.ok)!==!1,isCritical:!!(x!=null&&x.isCritical),probedAt:x==null?void 0:x.probedAt}),await o()}catch(x){z((x==null?void 0:x.message)||"Unexpected probe error")}N(!1)},a=n[0]||null,d=r.useMemo(()=>[...n].reverse(),[n]),k=r.useMemo(()=>n.filter(x=>x.is_critical===!0).length,[n]),B=r.useMemo(()=>n.filter(x=>x.http_status===200&&!x.is_critical).length,[n]),_=a!=null&&a.sha256?a.sha256.slice(0,8):null,P=(a==null?void 0:a.shape)||"unknown",J=(a==null?void 0:a.interpretation)||(a?"NO_INTERPRETATION":"—"),Y=!!(a!=null&&a.is_critical),i=(a==null?void 0:a.http_status)??null,Q=!!(a!=null&&a.has_leading_whitespace)||!!(a!=null&&a.has_trailing_whitespace)||!!(a!=null&&a.has_internal_whitespace),g=Dt.has(P);return e.jsxs("div",{className:"bg-white rounded-xl border shadow-sm overflow-hidden",style:{borderColor:`${be}25`},children:[e.jsx("div",{className:"h-1",style:{background:`linear-gradient(90deg, ${be}, ${Ce}, ${be})`}}),e.jsxs("div",{className:"px-6 py-4 border-b flex flex-col md:flex-row items-start md:items-center justify-between gap-3",style:{borderColor:`${be}15`,background:`linear-gradient(90deg, ${be}05, ${Ce}08)`},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center shadow-sm",style:{background:`linear-gradient(135deg, ${be}, ${Ge})`},children:e.jsx(Ye,{size:18,className:"text-white"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold flex items-center gap-2",style:{color:Ge},children:["Mailgun Auth Health",e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[9px] font-bold uppercase tracking-wider",style:{background:`${Ce}25`,color:Ge,border:`1px solid ${Ce}55`},children:"Daily 06:00 UTC"})]}),e.jsx("p",{className:"text-[10px] text-gray-500 mt-0.5",children:"Read-only auth probe — detects silent revocation, wrong-shape rotation, whitespace contamination"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:o,disabled:m,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-semibold border transition-all disabled:opacity-50",style:{borderColor:`${be}30`,color:be,background:"#fff"},children:[m?e.jsx(X,{size:11,className:"animate-spin"}):e.jsx(Se,{size:11}),"Refresh"]}),e.jsxs("button",{onClick:y,disabled:t,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-lg text-[11px] font-bold text-white shadow-sm transition-all disabled:opacity-50 hover:opacity-90",style:{background:`linear-gradient(135deg, ${be}, ${Ge})`},children:[t?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Nt,{size:12}),"Run Probe Now"]})]})]}),(S||l)&&e.jsxs("div",{className:`px-6 py-3 border-b text-xs flex items-center gap-2 ${S?"bg-red-50 border-red-100 text-red-800":l!=null&&l.isCritical?"bg-amber-50 border-amber-100 text-amber-800":"bg-emerald-50 border-emerald-100 text-emerald-800"}`,children:[S?e.jsx(Rs,{size:14}):l!=null&&l.isCritical?e.jsx(ce,{size:14}):e.jsx(le,{size:14}),e.jsx("span",{className:"font-semibold",children:S?`Probe failed: ${S}`:l!=null&&l.isCritical?"Probe completed — critical issue detected, see banner below":"Probe completed successfully"}),(l==null?void 0:l.probedAt)&&!S&&e.jsx("span",{className:"font-mono text-[10px] opacity-70 ml-1",children:new Date(l.probedAt).toLocaleStr
11ing()})]}),a&&Y&&e.jsx("div",{className:"px-6 py-3 bg-red-50 border-b border-red-200",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-red-100 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(je,{size:16,className:"text-red-700"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-red-900",children:"CRITICAL — Mailgun authentication is failing"}),e.jsxs("p",{className:"text-[10px] text-red-700 mt-0.5",children:["Last probed ",ds(a.probed_at)," • HTTP ",a.http_status??"—",a.http_status_text?` ${a.http_status_text}`:""," • shape"," ",e.jsx("span",{className:"font-mono",children:a.shape||"unknown"})]}),a.alert_reasons&&a.alert_reasons.length>0&&e.jsx("ul",{className:"mt-2 space-y-0.5",children:a.alert_reasons.map((x,w)=>e.jsxs("li",{className:"text-[10px] font-mono text-red-800 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-red-500"}),x]},w))}),e.jsx("p",{className:"text-[10px] text-red-600 mt-2 italic",children:"Every production email path (recruitment, payment reminders, tour confirmations, etc.) is affected until this is resolved. Check the Mailgun secret in the project settings."})]})]})}),a&&!Y&&(g||Q)&&e.jsxs("div",{className:"px-6 py-2 bg-amber-50 border-b border-amber-100 flex items-center gap-2",children:[e.jsx(ce,{size:12,className:"text-amber-600"}),e.jsxs("span",{className:"text-[10px] font-semibold text-amber-800",children:["Heads up: latest probe succeeded but"," ",g&&`shape "${P}" is suspicious`,g&&Q&&" and ",Q&&"whitespace was detected in the secret","."]})]}),m&&n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(X,{size:24,className:"animate-spin mb-2",style:{color:Ce}}),e.jsx("p",{className:"text-[10px] text-gray-500 font-medium",children:"Loading Mailgun health log..."})]}):a?e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-lg border p-3",style:{borderColor:i===200?"#bbf7d0":"#fecaca",background:i===200?"#f0fdf4":"#fef2f2"},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(_t,{size:11,className:i===200?"text-emerald-600":"text-red-600"}),e.jsx("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-500",children:"HTTP Status"})]}),e.jsx("p",{className:"font-mono text-lg font-bold",style:{color:i===200?"#15803d":"#b91c1c"},children:i??"—"}),e.jsx("p",{className:"text-[9px] text-gray-500 mt-0.5 truncate",children:a.http_status_text||(a.elapsed_ms?`${a.elapsed_ms}ms`:"—")})]}),e.jsxs("div",{className:"rounded-lg border p-3",style:{borderColor:g?"#fecaca":`${Ce}55`,background:g?"#fef2f2":`${Ce}10`},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(js,{size:11,style:{color:g?"#b91c1c":be}}),e.jsx("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-500",children:"Key Shape"})]}),e.jsx("p",{className:"font-mono text-[11px] font-bold leading-tight",style:{color:g?"#b91c1c":Ge},title:P,children:Xs(P)}),e.jsxs("p",{className:"text-[9px] text-gray-500 mt-0.5",children:[a.key_length?`${a.key_length} chars`:"—",a.first4&&a.last4?` • ${a.first4}…${a.last4}`:""]})]}),e.jsxs("div",{className:"rounded-lg border p-3",style:{borderColor:`${be}25`,background:"#fff"},children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(zs,{size:11,style:{color:be}}),e.jsx("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-500",children:"SHA-256 (first 8)"})]}),e.jsx("p",{className:"font-mono text-sm font-bold",style:{color:Ge},title:a.sha256||"",children:_||"—"}),e.jsx("p",{className:"text-[9px] text-gray-500 mt-0.5",children:Q?e.jsx("span",{className:"text-red-600 font-semibold",children:"⚠ whitespace detected"}):"no whitespace"})]}),e.jsxs("div",{className:"rounded-lg border p-3",style:{borderColor:Y?"#fecaca":"#bbf7d0",background:Y?"#fef2f2":"#f0fdf4"}
11,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[Y?e.jsx(je,{size:11,className:"text-red-600"}):e.jsx(tt,{size:11,className:"text-emerald-600"}),e.jsx("span",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-500",children:"Interpretation"})]}),e.jsx("p",{className:"font-mono text-[11px] font-bold leading-tight",style:{color:Y?"#b91c1c":"#15803d"},title:J,children:J}),e.jsxs("p",{className:"text-[9px] text-gray-500 mt-0.5 flex items-center gap-1",children:[e.jsx(ke,{size:9}),ds(a.probed_at)]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",style:{color:Ge},children:"Last 30 Probes"}),e.jsx("span",{className:"text-[9px] text-gray-400",children:"(oldest → newest)"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[9px]",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-sm bg-emerald-500"}),e.jsxs("span",{className:"text-gray-500",children:["200 OK (",B,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-sm bg-red-500"}),e.jsxs("span",{className:"text-gray-500",children:["Fail (",k,")"]})]})]})]}),e.jsx("div",{className:"rounded-lg border p-3",style:{borderColor:`${be}20`,background:`${Ce}05`},children:d.length===0?e.jsx("p",{className:"text-[10px] text-gray-400 text-center py-4",children:"No probe history yet"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end gap-1",style:{height:64},children:d.map((x,w)=>{const M=x.http_status===200&&!x.is_critical&&!Dt.has(x.shape||""),T=x.http_status===200&&(Dt.has(x.shape||"")||x.has_leading_whitespace||x.has_trailing_whitespace||x.has_internal_whitespace),L=M?"#22c55e":T?"#f59e0b":"#ef4444",I=x.elapsed_ms??500,h=Math.min(100,Math.max(40,40+I/2e3*60));return e.jsxs("div",{className:"flex-1 group relative flex items-end",style:{minWidth:0,height:"100%"},children:[e.jsx("div",{className:"w-full rounded-sm transition-all hover:opacity-80 cursor-pointer",style:{height:`${h}%`,backgroundColor:L,minHeight:4}}),e.jsxs("div",{className:"absolute bottom-full mb-1 left-1/2 -translate-x-1/2 bg-gray-900 text-white px-2 py-1 rounded text-[9px] font-mono whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10",children:[e.jsx("div",{className:"font-bold",children:new Date(x.probed_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsxs("div",{children:["HTTP ",x.http_status??"—"," •"," ",x.elapsed_ms?`${x.elapsed_ms}ms`:"—"]}),e.jsx("div",{className:"opacity-70",children:x.shape||"unknown"}),x.trigger_source&&e.jsxs("div",{className:"opacity-50",children:["trigger: ",x.trigger_source]})]})]},x.id)})}),e.jsxs("div",{className:"flex justify-between mt-1.5 text-[9px] font-mono text-gray-400",children:[e.jsx("span",{children:d[0]?new Date(d[0].probed_at).toLocaleDateString("en-US",{month:"short",day:"numeric"}):"—"}),e.jsxs("span",{className:"text-gray-500",children:[d.length," probe",d.length===1?"":"s"]}),e.jsx("span",{children:d[d.length-1]?new Date(d[d.length-1].probed_at).toLocaleDateString("en-US",{month:"short",day:"numeric"}):"—"})]})]})})]}),e.jsxs("div",{className:"flex items-start gap-2 text-[10px] text-gray-500 p-3 rounded-lg",style:{background:`${Ce}08`,border:`1px solid ${Ce}25`},children:[e.jsx(Ee,{size:11,className:"flex-shrink-0 mt-0.5",style:{color:be}}),e.jsxs("p",{children:["This panel reads from ",e.jsx("span",{className:"font-mono font-semibold",children:"public.mailgun_health_log"}),". The daily 06:00 UTC ",e.jsx("span",{className:"font-mono font-semibold",children:"cron-mailgun-health-check"})," ","job invokes the read-only ",e.jsx("span",{className:"font-mono font-semibold",children:"mailgun-auth-probe"})," ","edge function — no email is sent, no Mailgun charge is incurred. A critical alert is dispatched to the notifications table if HTTP ≠ 200, the key shape is unknown / a public-validation key, or whitespace is detected in the stored secret."]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-gray-400",children:[e.jsx(Ye,{size:32,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No probe results yet"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:'The daily 06:00 UTC cron will populate this — or click "Run Probe Now"'})]})]})},cs="#6B1D3A",ea="#4A1228",xs="#C5A572",ms=[{job_name:"cron-mailgun-health-check-daily",function_slug:"cron-mailgun-health-check",schedule:"0 6 * * *"},{job_name:"sap-nightly-audit-daily",function_slug:"sap-nightly-audit",schedule:"0 2 * * *"},{job_name:"auto-student-alerts-nightly",function_slug:"auto-student-alerts",schedule:"0 3 * * *"},{job_name:"sap-auto-rule-engine-daily",function_slug:"sap-auto-rule-engine",schedule:"0 4 * * *"},{job_name:"cron-report-cards-daily",function_slug:"cron-report-cards",schedule:"0 6 * * *"},{job_name:"cron-rls-audit-weekly",function_slug:"cron-rls-audit",schedule:"0 9 * * 1"}];function ta(){const[n,v]=r.useState(!0),[m,f]=r.useState(!1),[t,N]=r.useState([]),[S,z]=r.useState(null),[l,A]=r.useState(null),o=r.useCallback(async()=>{var _,P,J,Y;v(!0),z(null);try{const{data:i,error:Q}=await D.from("cron_invocation_log").select("*").order("start_time",{ascending:!1}).limit(200);if(Q)throw Q;const g=i||[],x=new Map;for(const T of g)x.has(T.job_name)||x.set(T.job_name,[]),x.get(T.job_name).push(T);const w=new Set([...ms.map(T=>T.job_name),...x.keys()]),M=[];for(const T of w){const L=(x.get(T)||[]).slice(0,5),I=ms.find(h=>h.job_name===T);M.push({job_name:T,function_slug:((_=L[0])==null?void 0:_.function_slug)||(I==null?void 0:I.function_slug)||null,schedule:((P=L[0])==null?void 0:P.schedule)||(I==null?void 0:I.schedule)||null,last5:L,all401:L.length>=5&&L.every(h=>h.http_status===401),any401:L.some(h=>h.http_status===401),latestStatus:((J=L[0])==null?void 0:J.http_status)??null,latestStart:((Y=L[0])==null?void 0:Y.start_time)??null,hasData:L.length>0})}M.sort((T,L)=>{const I=h=>h.all401?0:h.any401?1:h.hasData?3:2;return I(T)-I(L)}),N(M)}catch(i){z((i==null?void 0:i.message)||"Failed to load cron_invocation_log")}finally{v(!1)}},[]);r.useEffect(()=>{o()},[o]);const y=async()=>{f(!0),A(null);try{const{data:_,error:P}=await D.functions.invoke("cron-invocation-log-sync",{body:{lookback_hours:168}});P?A(`Sync failed: ${P.message}`):_!=null&&_.success?A(`Synced ${_.inserted??0} new row(s) (considered ${_.considered??0}, auth failures: ${_.auth_failures_in_batch??0})`):A(`Sync limitation: ${(_==null?void 0:_.error)||"unknown"}. Logs will populate as crons self-report.`),await o()}catch(_){A(`Sync error: ${(_==null?void 0:_.message)||"unknown"}`)}finally{f(!1)}},a=t.filter(_=>_.all401),d=t.filter(_=>!_.all401&&_.any401),k=t.filter(_=>!_.hasData),B=t.filter(_=>_.hasData&&!_.any401);return e.jsxs("div",{className:"rounded-xl border-2 bg-white shadow-md",style:{borderColor:cs},children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 rounded-t-xl",style:{background:`linear-gradient(135deg, ${cs} 0%, ${ea} 100%)`},children:[e.jsxs("div",{className:"flex items-center gap-3 text-white",children:[e.jsx(js,{size:22,style:{color:xs}}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Cron Auth Health"}),e.jsx("p",{className:"text-xs opacity-80",children:"Red = last 5 invocations all returned HTTP 401 (X-Cron-Secret misconfiguration)"})]})]}),e.jsxs("button",{onClick:y,disabled:m,className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-white border transition-opacity disabled:opacity-50",style:{borderColor:xs,backgroundColor:"rgba(197,165,114,0.15)"},children:[m?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14}),m?"Syncing…":"Sync Now"]})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[l&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-stone-50 border border-stone-200 text-sm text-stone-700",children:[e.jsx(Ee,{size:14,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:l})]}),S&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md border text-sm",style:{borderColor:"#fca5a5",backgroundColor:"#fef2f2",color:"#991b1b"},children:[e.jsx(ce,{size:14,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:S})]}),a.length>0&&e.jsx("div",{className:"rounded-lg border-2 p-4",style:{borderColor:"#dc2626",backgroundColor:"#fef2f2"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(je,{size:22,className:"flex-shrink-0 mt-0.5",style:{color:"#dc2626"}}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h4",{className:"font-semibold text-red-800 mb
11-1",children:[a.length," cron job",a.length>1?"s":""," stuck on HTTP 401"]}),e.jsx("p",{className:"text-sm text-red-700 mb-2",children:"Last 5 consecutive invocations all returned 401 — the X-Cron-Secret header is either missing, invalid, or not being forwarded by the cron infrastructure. Production scheduled work (SAP audits, report cards, student alerts) is silently not running."}),e.jsx("ul",{className:"text-sm text-red-700 list-disc ml-5",children:a.map(_=>e.jsxs("li",{children:[e.jsx("span",{className:"font-mono",children:_.job_name}),_.schedule&&e.jsxs("span",{className:"opacity-75",children:[" · ",_.schedule," UTC"]})]},_.job_name))})]})]})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(bt,{label:"Critical (5×401)",value:a.length,color:a.length>0?"#dc2626":"#64748b"}),e.jsx(bt,{label:"Warning (some 401)",value:d.length,color:d.length>0?"#d97706":"#64748b"}),e.jsx(bt,{label:"No data yet",value:k.length,color:"#64748b"}),e.jsx(bt,{label:"Healthy",value:B.length,color:"#16a34a"})]}),n?e.jsxs("div",{className:"flex items-center justify-center py-10 text-stone-500",children:[e.jsx(X,{className:"animate-spin mr-2",size:18}),"Loading invocation log…"]}):t.length===0?e.jsxs("div",{className:"text-center py-10 text-stone-500 text-sm",children:[e.jsx(ke,{className:"mx-auto mb-2 opacity-50",size:28}),e.jsxs("p",{children:["No cron invocations logged yet. Click ",e.jsx("strong",{children:"Sync Now"})," to backfill from cron.job_run_details,"]}),e.jsx("p",{children:"or wait for the next scheduled cron tick to self-report."})]}):e.jsx("div",{className:"border rounded-lg divide-y",style:{borderColor:"#e7e5e4"},children:t.map(_=>e.jsx(sa,{s:_},_.job_name))})]})]})}function bt({label:n,value:v,color:m}){return e.jsxs("div",{className:"rounded-lg border bg-white p-3",style:{borderColor:m},children:[e.jsx("div",{className:"text-2xl font-bold",style:{color:m},children:v}),e.jsx("div",{className:"text-xs text-stone-600 mt-0.5",children:n})]})}function sa({s:n}){const v=N=>N.http_status===401?"#dc2626":N.http_status&&N.http_status>=200&&N.http_status<300?"#16a34a":N.http_status?"#d97706":"#94a3b8";let m,f,t;return n.all401?(m="CRITICAL — all 5 = 401",f="#dc2626",t=je):n.any401?(m="Warning — recent 401s",f="#d97706",t=ce):n.hasData?(m=`Healthy — HTTP ${n.latestStatus??"—"}`,f="#16a34a",t=tt):(m="No invocations logged",f="#64748b",t=ke),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-3 px-4 py-3 hover:bg-stone-50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t,{size:16,style:{color:f}}),e.jsx("span",{className:"font-mono text-sm font-medium text-stone-900 truncate",children:n.job_name})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-stone-500",children:[n.function_slug&&e.jsxs("span",{children:["fn: ",e.jsx("code",{className:"font-mono",children:n.function_slug})]}),n.schedule&&e.jsxs("span",{children:["cron: ",e.jsx("code",{className:"font-mono",children:n.schedule})," UTC"]}),n.latestStart&&e.jsxs("span",{children:["last: ",new Date(n.latestStart).toLocaleString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1",title:"Last 5 invocations (oldest left → newest right)",children:[[...n.last5].reverse().map((N,S)=>e.jsx("span",{className:"inline-block w-3 h-3 rounded-full",style:{backgroundColor:v(N)},title:`${new Date(N.start_time).toLocaleString()} · HTTP ${N.http_status??"?"}${N.duration_ms?` · ${N.duration_ms}ms`:""}`},N.id??S)),Array.from({length:Math.max(0,5-n.last5.length)}).map((N,S)=>e.jsx("span",{className:"inline-block w-3 h-3 rounded-full border border-stone-200 bg-stone-50",title:"No invocation yet"},`empty-${S}`))]}),e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-medium border whitespace-nowrap",style:{borderColor:f,color:f,backgroundColor:`${f}10`},children:m})]})]})}const Qe="#6B1D3A",aa="#C5A572",At={1:{color:Qe,label:"Upcoming",bgColor:`${Qe}10`},8:{color:"#d97706",label:"Warning",bgColor:"#fffbeb"},11:{color:"#dc2626",label:"Final Notice",bgColor:"#fef2f2"}},it={success:{bg:"#f0fdf4",text:"#15803d",border:"#bbf7d0",dot:"#22c55e"},partial:{bg:"#fffbeb",text:"#a16207",border:"#fde68a",dot:"#f59e0b"},failed:{bg:"#fef2f2",text:"#b91c1c",border:"#fecaca",dot:"#ef4444"}
11,missed:{bg:"#faf5ff",text:"#7e22ce",border:"#e9d5ff",dot:"#a855f7"},pending:{bg:"#f9fafb",text:"#6b7280",border:"#e5e7eb",dot:"#9ca3af"}},ra=()=>{var Z,ie,se;const[n,v]=r.useState(!0),[m,f]=r.useState([]),[t,N]=r.useState([]),[S,z]=r.useState([]),[l,A]=r.useState(null),[o,y]=r.useState([]),[a,d]=r.useState(null),[k,B]=r.useState(!1),[_,P]=r.useState(""),[J,Y]=r.useState(!0),[i,Q]=r.useState(!0),[g,x]=r.useState(!1),[w,M]=r.useState(!1),[T,L]=r.useState(null),[I,h]=r.useState(null),O=r.useCallback(async()=>{var c,R,G;v(!0);try{const{data:F,error:C}=await D.functions.invoke("cron-health-check",{body:{action:"get-health-data"}});!C&&(F!=null&&F.success)&&(f(F.healthRecords||[]),N(F.cronLogs||[]),z(F.missedRuns||[]),A(F.stats||null),y(F.monthlyStats||[]),d(F.config||null),(c=F.config)!=null&&c.adminAlertEmail&&P(F.config.adminAlertEmail),((R=F.config)==null?void 0:R.alertOnMissedRun)!==void 0&&Y(F.config.alertOnMissedRun),((G=F.config)==null?void 0:G.alertOnFailure)!==void 0&&Q(F.config.alertOnFailure))}catch(F){console.error("Failed to fetch health data:",F)}v(!1)},[]);r.useEffect(()=>{O()},[O]);const q=async()=>{M(!0),L(null);try{const{data:c,error:R}=await D.functions.invoke("cron-health-check",{body:{action:"check-missed"}});R||L(c),O()}catch(c){L({success:!1,error:c.message})}M(!1)},ue=async()=>{x(!0);try{await D.functions.invoke("cron-health-check",{body:{action:"update-alert-config",adminEmail:_,alertOnMissedRun:J,alertOnFailure:i}}),O()}catch(c){console.error("Failed to save alert config:",c)}x(!1)},U=r.useMemo(()=>t.filter(c=>c.action_taken==="executed"&&c.response_time_ms>0).sort((c,R)=>new Date(c.created_at).getTime()-new Date(R.created_at).getTime()),[t]),b=r.useMemo(()=>U.map(c=>({date:new Date(c.created_at),ms:c.response_time_ms,day:c.trigger_day,batchId:c.batch_id})),[U]),$=r.useMemo(()=>b.length===0?1e3:Math.max(...b.map(c=>c.ms),1e3),[b]),H=r.useMemo(()=>{const c={};return m.forEach(R=>{const G=R.check_date.substring(0,7);c[G]||(c[G]=[]),c[G].push(R)}),Object.entries(c).sort(([R],[G])=>R.localeCompare(G))},[m]),ne=r.useMemo(()=>I?m.filter(c=>c.check_date.startsWith(I)).sort((c,R)=>c.check_date.localeCompare(R.check_date)):[],[I,m]);if(n)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(X,{size:32,className:"animate-spin mb-3",style:{color:aa}}),e.jsx("p",{className:"text-sm text-gray-500 font-medium",children:"Loading health monitoring data..."})]});const ae=((l==null?void 0:l.uptime)||0)>=95?"#059669":((l==null?void 0:l.uptime)||0)>=80?"#d97706":"#dc2626",re=((l==null?void 0:l.avgResponseTime)||0)<5e3?"#059669":((l==null?void 0:l.avgResponseTime)||0)<15e3?"#d97706":"#dc2626";return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden shadow-md",style:{background:"linear-gradient(135deg, #1e1b4b, #312e81)"},children:[e.jsx("div",{className:"h-1",style:{background:"linear-gradient(90deg, #818cf8, #c084fc, #818cf8)"}}),e.jsxs("div",{className:"px-6 py-5 flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center shadow-lg",style:{background:"linear-gradient(135deg, #818cf8, #6366f1)"},children:e.jsx(Ts,{size:24,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:"Cron Health Monitor"}),e.jsx("p",{className:"text-sm text-indigo-300",children:"Response times, success rates & missed run detection — 6 month history"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:q,disabled:w,className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-semibold bg-white/10 text-white border border-white/20 hover:bg-white/20 transition-all disabled:opacity-50",children:[w?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(je,{size:14}),"Check Missed Runs"]}),e.jsxs("button",{onClick:O,className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-semibold bg-white/10 text-white border border-white/20 hover:bg-white/20 transition-all",children:[e.jsx(Se,{size:12})," Refresh"]})]})]})]}),T&&e.jsxs("div",{className:`p-4 rounded-xl border-2 flex items-start justify-between ${T.action==="missed-run-detected"?"bg-purple-50 border-purple-200":T.action==="all-good"?"bg-emerald-50 border-emerald-200":"bg-gray-50 border-gray-200"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[T.action==="missed-run-detected"?e.jsx(je,{size:20,className:"text-purple-600"}):T.action==="all-good"?e.jsx(tt,{size:20,className:"text-emerald-600"}):e.jsx(Ee,{size:20,className:"text-gray-500"}),e.jsxs("div",{children:[e.jsx("p",{className:`text-sm font-bold ${T.action==="missed-run-detected"?"text-purple-800":T.action==="all-good"?"text-emerald-800":"text-gray-700"}`,children:T.action==="missed-run-detected"?`Missed Run Detected — Day ${T.missedDay}${T.alertSent?" (Alert email sent)":""}`:T.reason}),T.executionTime&&e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:["Last execution: ",new Date(T.executionTime).toLocaleStr
11ing()]})]})]}),e.jsx("button",{onClick:()=>L(null),className:"p-1 rounded hover:bg-white/50",children:e.jsx(Ie,{size:14,className:"text-gray-400"})})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-6 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{backgroundColor:`${ae}12`,color:ae},children:e.jsx($s,{size:14})}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:"Uptime"})]}),e.jsxs("p",{className:"font-mono text-2xl font-bold",style:{color:ae},children:[((Z=l==null?void 0:l.uptime)==null?void 0:Z.toFixed(1))||"100.0","%"]}),e.jsxs("p",{className:"text-[9px] text-gray-400 mt-0.5",children:[(l==null?void 0:l.totalScheduled)||0," scheduled runs"]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{backgroundColor:`${re}12`,color:re},children:e.jsx(qt,{size:14})}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:"Avg Response"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold",style:{color:re},children:l!=null&&l.avgResponseTime?`${(l.avgResponseTime/1e3).toFixed(1)}s`:"—"}),e.jsxs("p",{className:"text-[9px] text-gray-400 mt-0.5",children:["P95: ",l!=null&&l.p95ResponseTime?`${(l.p95ResponseTime/1e3).toFixed(1)}s`:"—"]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center bg-emerald-50 text-emerald-600",children:e.jsx(le,{size:14})}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:"Success"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold text-emerald-700",children:(l==null?void 0:l.successCount)||0}),e.jsxs("p",{className:"text-[9px] text-gray-400 mt-0.5",children:[(l==null?void 0:l.executedCalls)||0," total calls"]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center bg-red-50 text-red-600",children:e.jsx(Re,{size:14})}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:"Failed"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold text-red-700",children:(l==null?void 0:l.failedCount)||0}),e.jsx("p",{className:"text-[9px] text-gray-400 mt-0.5",children:"errors during execution"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center bg-purple-50 text-purple-600",children:e.jsx(ce,{size:14})}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:"Missed"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold text-purple-700",children:(l==null?void 0:l.missedCount)||0}),e.jsx("p",{className:"text-[9px] text-gray-400 mt-0.5",children:"scheduled but not run"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center bg-blue-50 text-blue-600",children:e.jsx(Rt,{size:14})}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:"Range"})]}),e.jsxs("p",{className:"font-mono text-lg font-bold text-blue-700",children:[l!=null&&l.minResponseTime?`${(l.minResponseTime/1e3).toFixed(1)}s`:"—",e.jsx("span",{className:"text-gray-400 mx-1",children:"—"}),l!=null&&l.maxResponseTime?`${(l.maxResponseTime/1e3).toFixed(1)}s`:"—"]}),e.jsx("p",{className:"text-[9px] text-gray-400 mt-0.5",children:"min — max response"})]})]}),e.jsx(Qs,{}),e.jsx(ta,{}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center bg-indigo-50",children:e.jsx(Ds,{size:18,className:"text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Response Time Trend"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Webhook execution duration per 
11cron call (ms)"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:Qe}}),e.jsx("span",{className:"text-gray-500",children:"1st"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-500"}),e.jsx("span",{className:"text-gray-500",children:"8th"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500"}),e.jsx("span",{className:"text-gray-500",children:"11th"})]})]})]}),e.jsx("div",{className:"p-6",children:b.length===0?e.jsxs("div",{className:"flex flex-col items-center py-12 text-gray-400",children:[e.jsx(Rt,{size:32,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No execution data yet"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:"Response times will appear after cron executions"})]}):e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"absolute left-0 top-0 bottom-6 w-12 flex flex-col justify-between text-[9px] font-mono text-gray-400",children:[e.jsxs("span",{children:[($/1e3).toFixed(1),"s"]}),e.jsxs("span",{children:[($/2e3).toFixed(1),"s"]}),e.jsx("span",{children:"0s"})]}),e.jsxs("div",{className:"ml-14 relative",style:{height:200},children:[e.jsx("div",{className:"absolute inset-0 flex flex-col justify-between pointer-events-none",children:[0,1,2,3,4].map(c=>e.jsx("div",{className:"border-b border-gray-100 w-full"},c))}),e.jsx("div",{className:"absolute inset-0 flex items-end gap-1 px-1",children:b.map((c,R)=>{const G=Math.max(c.ms/$*100,2),F=c.day===1?Qe:c.day===8?"#f59e0b":"#ef4444";return e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-end group relative",style:{minWidth:0},children:[e.jsx("div",{className:"w-full rounded-t-sm transition-all hover:opacity-80 cursor-pointer",style:{height:`${G}%`,backgroundColor:F,minHeight:3,maxWidth:24},title:`${c.date.toLocaleDateString()} — ${c.ms}ms (Day ${c.day})`}),e.jsxs("div",{className:"absolute bottom-full mb-2 left-1/2 -translate-x-1/2 bg-gray-900 text-white px-2 py-1 rounded text-[9px] font-mono whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10",children:[c.date.toLocaleDateString("en-US",{month:"short",day:"numeric"})," — ",(c.ms/1e3).toFixed(2),"s"]})]},R)})})]}),e.jsxs("div",{className:"ml-14 flex justify-between mt-1 text-[9px] font-mono text-gray-400",children:[e.jsx("span",{children:(ie=b[0])==null?void 0:ie.date.toLocaleDateString("en-US",{month:"short",day:"numeric"})}),b.length>1&&e.jsx("span",{children:(se=b[b.length-1])==null?void 0:se.date.toLocaleDateString("en-US",{month:"short",day:"numeric"})})]})]})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center bg-emerald-50",children:e.jsx(As,{size:18,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Monthly Success Rate"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Success / Failed / Missed breakdown per month"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-sm bg-emerald-500"}),e.jsx("span",{className:"text-gray-500",children:"Success"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-sm bg-red-500"}),e.jsx("span",{className:"text-gray-500",children:"Failed"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-sm bg-purple-500"}),e.jsx("span",{className:"text-gray-500",children:"Missed"})]})]})]}),e.jsx("div",{className:"p-6",children:o.length===0?e.jsxs("div",{className:"flex flex-col items-center py-12 text-gray-400",children:[e.jsx(Rt,{size:32,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No monthly data available"})]}):e.jsx("div",{className:"space-y-3",children:o.map(c=>{const R=c.success+c.failed+c.missed,G=R>0?c.success/R*100:0,F=R>0?c.failed/R*100:0,C=R>0?c.missed/R*100:0,de=new Date(c.month+"-01").toLocaleDateString("en-US",{month:"short",year:"numeric"});return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-20 text-right",children:e.jsx("span",{className:"text-xs font-semibold text-gray-600",children:de})}),e.jsxs("div",{className:"flex-1 flex h-7 rounded-lg overflow-hidden bg-gray-100",children:[c.success>0&&e.jsx("div",{className:"bg-emerald-500 flex items-center justify-center transition-all",style:{width:`${G}%`},title:`${c.success} success`,children:G>15&&e.jsx("span",{className:"text-[9px] font-bold text-white",children:c.success})}),c.failed>0&&e.jsx("div",{className:"bg-red-500 flex items-center justify-center transition-all",style:{width:`${F}%`},title:`${c.failed} failed`,children:F>15&&e.jsx("span",{className:"text-[9px] font-bold text-white",children:c.failed})}),c.missed>0&&e.jsx("div",{className:"bg-purple-500 flex items-center justify-center transition-all",style:{width:`${C}%`},title:`${c.missed} missed`,children:C>15&&e.jsx("span",{className:"text-[9px] font-bold text-white",children:c.missed})})]}),e.jsx("div",{className:"w-16 text-right",children:e.jsxs("span",{className:"text-[10px] font-mono font-semibold",style:{color:G===100?"#059669":G>=67?"#d97706":"#dc2626"},children:[G.toFixed(0),"%"]})}),e.jsx("div",{className:"w-14 text-right",children:e.jsx("span",{className:"text-[9px] font-mono text-gray-400",children:c.avgResponseMs>
110?`${(c.avgResponseMs/1e3).toFixed(1)}s`:"—"})})]},c.month)})})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{backgroundColor:`${Qe}10`},children:e.jsx(st,{size:18,style:{color:Qe}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Execution Timeline"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"All scheduled runs over the past 6 months — click a month for details"})]})]}),e.jsx("div",{className:"flex items-center gap-2 text-[10px]",children:Object.entries(it).map(([c,R])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:R.dot}}),e.jsx("span",{className:"text-gray-500 capitalize",children:c})]},c))})]}),e.jsx("div",{className:"p-6",children:H.length===0?e.jsxs("div",{className:"flex flex-col items-center py-12 text-gray-400",children:[e.jsx(st,{size:32,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No timeline data available"})]}):e.jsx("div",{className:"space-y-3",children:H.map(([c,R])=>{const G=new Date(c+"-01").toLocaleDateString("en-US",{month:"long",year:"numeric"}),F=I===c;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>h(F?null:c),className:`w-full flex items-center gap-4 p-3 rounded-xl border-2 transition-all hover:shadow-sm ${F?"border-indigo-300 bg-indigo-50/30":"border-gray-100 hover:border-gray-200"}`,children:[e.jsxs("div",{className:"w-24 text-left",children:[e.jsx("span",{className:"text-xs font-bold text-gray-700",children:G.split(" ")[0]}),e.jsx("span",{className:"text-[10px] text-gray-400 ml-1",children:G.split(" ")[1]})]}),e.jsx("div",{className:"flex-1 flex items-center gap-2",children:R.sort((C,de)=>C.check_date.localeCompare(de.check_date)).map((C,de)=>{const ge=it[C.status]||it.pending;return At[C.expected_day],e.jsxs("div",{className:"flex flex-col items-center gap-1",title:`${C.check_date} — Day ${C.expected_day} — ${C.status}`,children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center border-2 text-[10px] font-bold transition-all",style:{backgroundColor:ge.bg,borderColor:ge.border,color:ge.text},children:C.expected_day}),e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:ge.dot}})]},de)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[R.filter(C=>C.status==="success"||C.status==="partial").length>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-emerald-50 text-emerald-700",children:[R.filter(C=>C.status==="success"||C.status==="partial").length," ok"]}),R.filter(C=>C.status==="missed").length>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-purple-50 text-purple-700",children:[R.filter(C=>C.status==="missed").length," missed"]}),R.filter(C=>C.status==="failed").length>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-red-50 text-red-700",children:[R.filter(C=>C.status==="failed").length," fail"]}),R.filter(C=>C.status==="pending").length>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-gray-100 text-gray-500",children:[R.filter(C=>C.status==="pending").length," pending"]}),F?e.jsx(Le,{size:14,className:"text-gray-400"}):e.jsx(Fe,{size:14,className:"text-gray-400"})]})]}),F&&ne.length>0&&e.jsx("div",{className:"mt-2 ml-4 mr-4 rounded-lg border border-indigo-100 bg-indigo-50/20 overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-indigo-50/50 border-b border-indigo-100",children:[e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-indigo-700",children:"Date"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-indigo-700",children:"Day"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-indigo-700",children:"Status"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-indigo-700",children:"Response"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-indigo-700",children:"Sent"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-indigo-700",children:"Failed"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-indigo-700",children:"Late Fees"}),e.jsx("th",{className:"px-4 py-2 text-center font-semibold text-indigo-700",children:"Alert"})]})}),e.jsx("tbody",{className:"divide-y divide-indigo-50",children:ne.map(C=>{var ge;const de=it[C.status]||it.pending;return e.jsxs("tr",{className:"hover:bg-white/50",children:[e.jsx("td",{className:"px-4 py-2.5 font-mono text-gray-700",children:new Date(C.check_date+"T12:00:00").toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold text-white",style:{backgroundColor:((ge=At[C.expected_day])==null?void 0:ge.color)||"#6b7280"},children:C.expected_day===1?"1st":C.expected_day===8?"8th":"11th"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold",style:{backgroundColor:de.bg,color:de.text},children:[e.jsx(Ys,{size:8,style:{color:de.dot}}),C.status]})}),e.jsx("td",{className:"px-3 py-2.5 text-center font-mono text-gray-600",children:C.response_time_ms>0?`${(C.response_time_ms/1e3).toFixed(2)}s`:"—"}),e.jsx("td",{className:"px-3 py-2.5 text-center font-mono text-emerald-600 font-bold",children:C.sent_count||0}),e.jsx("td",{className:"px-3 py-2.5 text-center font-mono text-red-600 font-bold",children:C.failed_count||0}),e.jsx("td",{className:"px-3 py-2.5 text-center font-mono text-amber-600 font-bold",children:C.late_fee_count||0}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:C.alert_sent?e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-bold bg-red-50 text-red-700",children:[e.jsx(We,{size:8})," Sent"]}):e.jsx(Es,{size:12,className:"inline text-gray-300"})})]},C.id)})})]})})]},c)})})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center bg-purple-50",children:e.jsx(je,{size:18,className:"text-purple-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Missed Run Detector"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Expected vs actual execution dates — highlights gaps in automation"})]})]}),e.jsx("span",{className:`px-3 py-1 rounded-full text-[10px] font-bold ${S.length===0?"bg-emerald-50 text-emerald-700":"bg-purple-50 text-purple-700"}`,children:S.length===0?"All Clear":`${S.length} Missed`})]}),e.jsx("div",{className:"p-6",children:S.length===0?e.jsxs("div",{className:"flex flex-col items-center py-8 text-gray-400",children:[e.jsx(tt,{size:40,className:"mb-3 text-emerald-300"}),e.jsx("p",{className:"text-sm font-semibold text-emerald-600",children:"No Missed Runs Detected"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"All scheduled cron executions have been completed on time"})]}):e.jsxs("div",{className:"space-y-2",children:[S.slice(0,20).map((c,R)=>{const G=At[c.expected_day];return e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg border border-purple-100 bg-purple-50/30",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center border-2 border-purple-200 bg-purple-50",children:e.jsx("span",{className:"text-sm font-bold text-purple-700",children:c.expected_day})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-xs font-bold text-purple-800",children:new Date(c.check_date+"T12:00:00").toLocaleDateString("en-US",{weekday:"short",month:"long",day:"numeric",year:"numeric"})}),e.jsxs("p",{className:"text-[10px] text-purple-600 mt-0.5",children:["Expected: ",(G==null?void 0:G.label)||"Reminder"," at 8:00 AM PST — ",e.jsx("span",{className:"font-bold",children:"Never executed"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c.alert_sent&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-red-50 text-red-700 flex items-center gap-1",children:[e.jsx(We,{size:8})," Alert sent"]}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[9px] font-bold bg-purple-100 text-purple-700",children:"MISSED"})]})]},c.id||R)}),S.length>20&&e.jsxs("p",{className:"text-center text-[10px] text-gray-400 pt-2",children:["Showing 20 of ",S.length," missed runs"]})]})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center bg-amber-50",children:e.jsx(We,{size:18,className:"text-amber-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Alert Configuration"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Email alerts when cron jobs fail or miss scheduled runs"})]})]}),e.jsxs("button",{onClick:()=>B(!k),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-amber-200 text-amber-700 hover:bg-amber-50 transition-colors",children:[e.jsx(Kt,{size:12}),k?"Hide Settings":"Configure Alerts"]})]}),e.jsx("div",{className:"px-6 py-3 bg-gradient-to-r from-amber-50/50 to-orange-50/50 border-b border-gray-100",children:e.jsxs("div",{className:"flex items-center gap-4 flex-wrap text-[10px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:10,
11className:"text-amber-600"}),e.jsx("span",{className:"text-gray-600",children:"Admin Email:"}),e.jsx("span",{className:"font-semibold text-gray-800",children:(a==null?void 0:a.adminAlertEmail)||"Not configured"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${a!=null&&a.alertOnMissedRun?"bg-emerald-500":"bg-gray-300"}`}),e.jsxs("span",{className:"text-gray-600",children:["Missed Run Alerts: ",e.jsx("span",{className:"font-semibold",children:a!=null&&a.alertOnMissedRun?"ON":"OFF"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${a!=null&&a.alertOnFailure?"bg-emerald-500":"bg-gray-300"}`}),e.jsxs("span",{className:"text-gray-600",children:["Failure Alerts: ",e.jsx("span",{className:"font-semibold",children:a!=null&&a.alertOnFailure?"ON":"OFF"})]})]})]})}),k&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-gray-700 mb-1.5 block",children:"Admin Alert Email"}),e.jsx("input",{type:"email",value:_,onChange:c=>P(c.target.value),placeholder:"[email protected]",className:"w-full px-4 py-2.5 rounded-lg border border-gray-200 text-sm focus:border-indigo-400 focus:ring-2 focus:ring-indigo-100 outline-none transition-all"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:"Alert emails will be sent to this address when issues are detected"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:`p-4 rounded-xl border-2 cursor-pointer transition-all ${J?"border-emerald-300 bg-emerald-50/30":"border-gray-200 bg-gray-50"}`,onClick:()=>Y(!J),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{size:16,className:J?"text-emerald-600":"text-gray-400"}),e.jsx("span",{className:`text-xs font-bold ${J?"text-emerald-700":"text-gray-500"}`,children:"Missed Run Alerts"})]}),e.jsx("div",{className:`w-10 h-5 rounded-full flex items-center transition-all ${J?"bg-emerald-500 justify-end":"bg-gray-300 justify-start"}`,children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white shadow mx-0.5"})})]}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Send alert if cron hasn't run by noon PST on a scheduled day"})]}),e.jsxs("div",{className:`p-4 rounded-xl border-2 cursor-pointer transition-all ${i?"border-emerald-300 bg-emerald-50/30":"border-gray-200 bg-gray-50"}`,onClick:()=>Q(!i),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Re,{size:16,className:i?"text-emerald-600":"text-gray-400"}),e.jsx("span",{className:`text-xs font-bold ${i?"text-emerald-700":"text-gray-500"}`,children:"Failure Alerts"})]}),e.jsx("div",{className:`w-10 h-5 rounded-full flex items-center transition-all ${i?"bg-emerald-500 justify-end":"bg-gray-300 justify-start"}`,children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white shadow mx-0.5"})})]}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Send alert when cron execution encounters errors"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:ue,disabled:g,className:"flex items-center gap-2 px-6 py-2.5 rounded-lg text-sm font-bold text-white transition-all disabled:opacity-50 hover:opacity-90",style:{background:"linear-gradient(135deg, #4f46e5, #4338ca)"},children:[g?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Ms,{size:14}),"Save Alert Settings"]})})]})]})]})},ft="#6B1D3A";function Et(n){return"$"+(n/100).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}const la=()=>{const[n,v]=r.useState(!1),[m,f]=r.useState("Retry Test Student"),[t,N]=r.useState("[email protected]"),[S,z]=r.useState("cosmetology"),[l,A]=r.useState(25e4),[o,y]=r.useState(1),[a,d]=r.useState("idle"),[k,B]=r.useState(""),[_,P]=r.useState(null),[J,Y]=r.useState(null),[i,Q]=r.useState(null),[g,x]=r.useState(null),[w,M]=r.useState(null),[T,L]=r.useState(0),[I,h]=r.useState(!1),O=r.useCallback(async()=>{d("idle"),Q(null),x(null),M(null),P(null),Y(null),L(0);const b=Date.now(),$=`retry-test-${Date.now()}`;try{d("inserting-student"),B("Inserting test student with invali
11d email...");const{error:H}=await D.from("students").insert({id:$,name:m,email:t,phone:"000-000-0000",program_id:S,enroll_date:new Date().toISOString().split("T")[0],status:"active",hours_completed:0,theory_hours:0,practical_hours:0,gpa:0});if(H)throw new Error(`Failed to insert student: ${H.message}`);P($),d("inserting-ledger"),B("Creating financial ledger entry with outstanding balance...");const{data:ne,error:ae}=await D.from("financial_ledger").insert({student_id:$,program_id:S,total_tuition:l,kit_fee:0,registration_fee:0,funding_source:"self-pay",notes:`[RETRY TEST] Auto-created for retry mechanism testing at ${new Date().toISOString()}`}).select("id").single();if(ae)throw new Error(`Failed to insert ledger: ${ae.message}`);Y((ne==null?void 0:ne.id)||null),d("running-function"),B("Invoking auto-compliance-reminders with force + testStudentId... (retries may take ~15s)");const{data:re,error:Z}=await D.functions.invoke("auto-compliance-reminders",{body:{force:!0,overrideDay:o,triggerType:"retry-test-panel",testStudentId:$}});if(Z){const R=typeof Z=="string"?Z:(Z==null?void 0:Z.message)||JSON.stringify(Z);throw new Error(`Edge function error: ${R}`)}if(typeof re=="string")throw new Error(`Edge function returned non-JSON: ${re.slice(0,300)}`);x(re),d("polling-results"),B("Fetching compliance_email_log result...");let ie=null,se=0;const c=10;for(;!ie&&se<c;){se++;const{data:R}=await D.from("compliance_email_log").select("*").eq("student_id",$).order("created_at",{ascending:!1}).limit(1);R&&R.length>0?ie=R[0]:await new Promise(G=>setTimeout(G,1e3))}if(!ie)throw new Error("No compliance_email_log entry found after polling. The edge function may not have processed this student.");Q(ie),L(Date.now()-b),d("complete"),B("Test complete!")}catch(H){L(Date.now()-b),d("error"),M(H.message||"Unknown error")}},[m,t,S,l,o]),q=r.useCallback(async()=>{h(!0);try{await D.from("compliance_email_log").delete().like("student_id","retry-test-%"),await D.from("compliance_cron_log").delete().eq("trigger_type","targeted-test"),await D.from("financial_ledger").delete().like("student_id","retry-test-%"),await D.from("students").delete().like("id","retry-test-%"),Q(null),x(null),P(null),Y(null),d("idle"),B(""),M(null)}catch(b){console.error("Cleanup error:",b)}h(!1)},[]),ue=(b,$,H)=>b==="sent"&&$===0?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold bg-emerald-50 text-emerald-700 border border-emerald-200",children:[e.jsx(le,{size:14})," Sent (First Attempt)"]}):b==="sent"&&$>0?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold bg-cyan-50 text-cyan-700 border border-cyan-200",children:[e.jsx(Gt,{size:14})," Sent After ",$," Retry(ies)"]}):b==="failed_after_retries"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold bg-orange-50 text-orange-800 border-2 border-orange-300",children:[e.jsx(je,{size:14})," Failed After All Retries (",$,"/",H,")"]}):b==="failed"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold bg-red-50 text-red-700 border border-red-200",children:[e.jsx(Re,{size:14})," Failed"]}):b==="skipped"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold bg-gray-100 text-gray-600 border border-gray-200",children:[e.jsx(dt,{size:14})," Skipped"]}):e.jsx("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-bold bg-gray-100 text-gray-500",children:b}),U=a!=="idle"&&a!=="complete"&&a!=="error";return e.jsxs("div",{className:"bg-white rounded-xl border-2 border-dashed shadow-sm overflow-hidden",style:{borderColor:"#7c3aed40"},children:[e.jsxs("button",{onClick:()=>v(!n),className:"w-full px-6 py-4 flex items-center justify-between hover:bg-purple-50/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center shadow-sm",style:{background:"linear-gradient(135deg, #7c3aed, #6d28d9)"},children:e.jsx(Qt,{size:20,className:"text-white"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("h3",{className:"text-sm font-bold text-gray-900 flex items-center gap-2",children:["Retry Test Panel",e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[9px] font-bold bg-purple-100 text-purple-700 uppercase tracking-wider",children:"E2E Test"})]}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Insert test student with invali
11d email, trigger Force Run, verify retry mechanism end-to-end"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsxs("span",{className:`px-2 py-0.5 rounded text-[9px] font-bold ${i.email_status==="failed_after_retries"?"bg-orange-100 text-orange-800":i.email_status==="sent"?"bg-emerald-100 text-emerald-700":"bg-red-100 text-red-700"}`,children:["Last: ",i.email_status]}),n?e.jsx(Le,{size:16,className:"text-gray-400"}):e.jsx(Fe,{size:16,className:"text-gray-400"})]})]}),n&&e.jsxs("div",{className:"border-t border-purple-100",children:[e.jsxs("div",{className:"p-6 bg-gradient-to-br from-purple-50/30 to-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ee,{size:14,className:"text-purple-600"}),e.jsxs("p",{className:"text-xs text-gray-600",children:["This panel creates a temporary test student with an ",e.jsx("strong",{children:"intentionally invalid email"}),", triggers the compliance reminder edge function, and verifies that the retry mechanism (initial + 3 retries with exponential backoff) works correctly end-to-end."]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-5",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-1.5",children:[e.jsx(es,{size:10})," Student Name"]}),e.jsx("input",{type:"text",value:m,onChange:b=>f(b.target.value),disabled:U,className:"w-full px-3 py-2 rounded-lg border border-gray-200 text-sm font-medium text-gray-800 bg-white focus:outline-none focus:ring-2 focus:ring-purple-300 focus:border-purple-400 disabled:opacity-50 disabled:bg-gray-50"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-1.5",children:[e.jsx(Ye,{size:10})," Email (Invalid)"]}),e.jsx("input",{type:"text",value:t,onChange:b=>N(b.target.value),disabled:U,className:"w-full px-3 py-2 rounded-lg border border-red-200 text-sm font-mono text-red-700 bg-red-50/50 focus:outline-none focus:ring-2 focus:ring-red-300 focus:border-red-400 disabled:opacity-50"}),e.jsx("p",{className:"text-[9px] text-red-500 mt-1 font-medium",children:"Intentionally invalid — will trigger retry failures"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-1.5",children:[e.jsx(Ls,{size:10})," Program ID"]}),e.jsxs("select",{value:S,onChange:b=>z(b.target.value),disabled:U,className:"w-full px-3 py-2 rounded-lg border border-gray-200 text-sm font-medium text-gray-800 bg-white focus:outline-none focus:ring-2 focus:ring-purple-300 disabled:opacity-50",children:[e.jsx("option",{value:"cosmetology",children:"Cosmetology"}),e.jsx("option",{value:"massage",children:"Massage Therapy"}),e.jsx("option",{value:"esthetics-750",children:"Master Esthetics"}),e.jsx("option",{value:"esthetics-450",children:"Basic Esthetics"}),e.jsx("option",{value:"nails",children:"Nail Technology"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-1.5",children:[e.jsx(zt,{size:10})," Outstanding Balance (cents)"]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"number",value:l,onChange:b=>A(parseInt(b.target.value)||0),disabled:U,className:"w-full px-3 py-2 rounded-lg border border-gray-200 text-sm font-mono text-gray-800 bg-white focus:outline-none focus:ring-2 focus:ring-purple-300 disabled:opacity-50"}),e.jsxs("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-[10px] font-semibold text-gray-400",children:["= ",Et(l)]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] font-bold text-gray-500 uppercase tracking-wider mb-1.5",children:[e.jsx(ke,{size:10})," Reminder Day Override"]}),e.jsx("div",{className:"flex gap-2",children:[1,8,11].map(b=>e.jsx("button",{onClick:()=>y(b),disabled:U,className:`flex-1 px-3 py-2 rounded-lg text-sm font-bold border-2 transition-all disabled:opacity-50 ${o===b?"text-white border-transparent":"border-gray-200 text-gray-500 hover:border-gray-300 bg-white"}`,style:o===b?{backgroundColor:b===11?"#dc2626":b===8?"#d97706":ft,borderColor:b===11?"#dc2626":b===8?"#d97706":ft}:{},children:b===1?"1st":b===8?"8th":"11th"},b))})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:O,disabled:U||!m||!t,className:"flex items-center gap-2 px-6 py-3 rounded-xl text-sm font-bold text-white shadow-lg transition-all hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed",style:{background:"linear-gradient(135deg, #7c3aed, #6d28d9)"},children:[U?e.jsx(X,{size:16,className:"animate-spin"}):e.jsx(Nt,{size:16}),U?"Running Test...":"Insert Test Student & Force Run"]}),e.jsxs("button",{onClick:q,disabled:U||I,className:"flex items-center gap-2 px-4 py-3 rounded-xl text-sm font-semibold border-2 border-gray-200 text-gray-600 hover:bg-gray-50 hover:border-gray-300 transition-all disabled:opacity-50",children:[I?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Ns,{size:14}),"Clean Up All Test Data"]})]})]}),a!=="idle"&&e.jsxs("div",{className:"px-6 py-4 border-t border-purple-100 bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(et,{size:14,className:"text-purple-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-700",children:"Execution Progress"}),T>0&&e.jsxs("span",{className:"text-[10px] font-mono text-gray-400 ml-auto",children:[(T/1e3).toFixed(1),"s elapsed"]})]}),e.jsx("div",{className:"space-y-2",children:[{key:"inserting-student",label:"Insert test student into students table",icon:es},{key:"inserting-ledger",label:"Create financial_ledger entry with outstanding balance",icon:zt}
11,{key:"running-function",label:"Invoke auto-compliance-reminders (Force Run + testStudentId)",icon:et},{key:"polling-results",label:"Fetch compliance_email_log result",icon:Se}].map((b,$)=>{const H=["inserting-student","inserting-ledger","running-function","polling-results"],ne=H.indexOf(a),ae=H.indexOf(b.key),re=a===b.key,Z=a==="complete"||a==="error"?ae<=ne:ae<ne,ie=a==="error"&&ae===ne;return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-lg transition-all ${re?"bg-purple-50 border border-purple-200":Z?"bg-emerald-50/50":ie?"bg-red-50 border border-red-200":"bg-gray-50/50"}`,children:[e.jsx("div",{className:`w-6 h-6 rounded-full flex items-center justify-center shrink-0 ${re?"bg-purple-100":Z&&!ie?"bg-emerald-100":ie?"bg-red-100":"bg-gray-100"}`,children:re?e.jsx(X,{size:12,className:"animate-spin text-purple-600"}):Z&&!ie?e.jsx(le,{size:12,className:"text-emerald-600"}):ie?e.jsx(Re,{size:12,className:"text-red-600"}):e.jsx("span",{className:"text-[10px] font-bold text-gray-400",children:$+1})}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:`text-xs font-medium ${re?"text-purple-700":Z?"text-emerald-700":ie?"text-red-700":"text-gray-400"}`,children:b.label})}),re&&e.jsx("span",{className:"text-[9px] font-mono text-purple-500 animate-pulse",children:"Processing..."})]},b.key)})}),a==="running-function"&&e.jsx("div",{className:"mt-3 px-3 py-2 rounded-lg bg-amber-50 border border-amber-200",children:e.jsxs("p",{className:"text-[10px] text-amber-700 font-medium flex items-center gap-1.5",children:[e.jsx(ce,{size:11}),"Retry mechanism in progress: initial attempt + up to 3 retries with exponential backoff (1s, 3s, 9s). This may take ~15 seconds."]})})]}),a==="error"&&w&&e.jsx("div",{className:"px-6 py-4 border-t border-red-100 bg-red-50/30",children:e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-red-50 border-2 border-red-200",children:[e.jsx(Re,{size:18,className:"text-red-600 shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-bold text-red-800 mb-1",children:"Test Failed"}),e.jsx("p",{className:"text-xs text-red-700 font-mono break-all",children:w}),e.jsxs("button",{onClick:O,className:"mt-3 flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-bold bg-red-100 text-red-700 hover:bg-red-200 transition-colors",children:[e.jsx(Se,{size:10})," Retry Test"]})]})]})}),g&&a==="complete"&&e.jsxs("div",{className:"px-6 py-4 border-t border-purple-100 bg-purple-50/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(et,{size:14,className:"text-purple-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-700",children:"Edge Function Response"})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-2",children:[{label:"Action",value:g.action,color:"#7c3aed"},{label:"Targets",value:g.targets,color:"#6b7280"},{label:"Sent",value:g.sent,color:"#059669"},{label:"Failed",value:g.failed,color:"#dc2626"},{label:"Exhausted",value:g.failedAfterRetries,color:"#7c2d12"},{label:"Total Retries",value:g.totalRetries,color:"#7c3aed"},{label:"Duration",value:`${g.durationMs}ms`,color:"#0891b2"}].map((b,$)=>e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white border border-gray-100",children:[e.jsx("p",{className:"font-mono text-sm font-bold",style:{color:b.color},children:b.value}),e.jsx("p",{className:"text-[8px] text-gray-400 font-semibold uppercase",children:b.label})]},$))})]}),i&&a==="complete"&&e.jsxs("div",{className:"px-6 py-5 border-t border-purple-100 bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{size:16,className:"text-purple-600"}),e.jsx("span",{className:"text-sm font-bold text-gray-900",children:"compliance_email_log Result"})]}),e.jsx("div",{className:"flex items-center gap-2",children:ue(i.email_status,i.retry_count,i.max_retries)})]}),e.jsxs("div",{className:"rounded-xl border-2 overflow-hidden",style:{borderColor:i.email_status==="failed_after_retries"?"#f97316":i.email_status==="sent"?"#059669":i.email_status==="failed"?"#dc2626":"#e5e7eb"},children:[e.jsxs("div",{className:"px-5 py-3 flex items-center justify-between",style:{backgroundColor:i.email_status==="failed_after_retries"?"#fff7ed":i.email_status==="sent"?"#f0fdf4":i.email_status==="failed"?"#fef2f2":"#f9fafb"},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-bold text-gray-700",children:"Student:"}),e.jsx("span",{className:"text-xs font-semibold text-gray-900",children:i.student_name})]}),e.jsx(Fs,{size:12,className:"text-gray-300"}),e.jsx("span",{className:"text-xs font-mono text-gray-500",children:i.student_email})]}),e.jsx("span",{className:"text-[9px] font-mono text-gray-400",children:new Date(i.created_at).toLocaleStr
11ing()})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-px bg-gray-100",children:[e.jsxs("div",{className:"bg-white p-4 text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 mb-1",children:[e.jsx(Ht,{size:14,className:"text-purple-600"}),e.jsx("span",{className:"text-[9px] font-bold text-gray-400 uppercase tracking-wider",children:"retry_count"})]}),e.jsx("p",{className:"font-mono text-3xl font-black text-purple-700",children:i.retry_count}),e.jsxs("p",{className:"text-[9px] text-gray-400 mt-0.5",children:["of ",i.max_retries," max"]})]}),e.jsxs("div",{className:"bg-white p-4 text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 mb-1",children:[e.jsx(Ye,{size:14,className:i.email_status==="failed_after_retries"?"text-orange-600":i.email_status==="sent"?"text-emerald-600":"text-red-600"}),e.jsx("span",{className:"text-[9px] font-bold text-gray-400 uppercase tracking-wider",children:"email_status"})]}),e.jsx("p",{className:`font-mono text-sm font-black break-all ${i.email_status==="failed_after_retries"?"text-orange-700":i.email_status==="sent"?"text-emerald-700":"text-red-700"}`,children:i.email_status})]}),e.jsxs("div",{className:"bg-white p-4 text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 mb-1",children:[e.jsx(zt,{size:14,className:"text-red-600"}),e.jsx("span",{className:"text-[9px] font-bold text-gray-400 uppercase tracking-wider",children:"Balance"})]}),e.jsx("p",{className:"font-mono text-2xl font-black text-red-700",children:Et(i.outstanding_balance)})]}),e.jsxs("div",{className:"bg-white p-4 text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 mb-1",children:[e.jsx(ce,{size:14,style:{color:i.urgency_level==="final-notice"?"#dc2626":i.urgency_level==="warning"?"#d97706":ft}}),e.jsx("span",{className:"text-[9px] font-bold text-gray-400 uppercase tracking-wider",children:"Urgency"})]}),e.jsx("p",{className:"font-mono text-sm font-black",style:{color:i.urgency_level==="final-notice"?"#dc2626":i.urgency_level==="warning"?"#d97706":ft},children:i.urgency_level}),e.jsxs("p",{className:"text-[9px] text-gray-400 mt-0.5",children:["Day ",i.reminder_day]})]})]}),e.jsxs("div",{className:"border-t border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(je,{size:14,className:"text-orange-600"}),e.jsxs("span",{className:"text-xs font-bold text-gray-800",children:["retry_errors ",e.jsxs("span",{className:"font-mono text-gray-400",children:["(",(i.retry_errors||[]).length," entries)"]})]})]}),i.retry_errors&&i.retry_errors.length>0?e.jsx("div",{className:"space-y-2",children:i.retry_errors.map((b,$)=>{const H=b.startsWith("Initial:"),ne=b.match(/^Retry (\d+):/),ae=H?0:ne?parseInt(ne[1]):$;return e.jsxs("div",{className:`flex items-start gap-3 px-4 py-3 rounded-lg border ${H?"bg-red-50/50 border-red-200":"bg-orange-50/50 border-orange-200"}`,children:[e.jsx("div",{className:`w-7 h-7 rounded-full flex items-center justify-center shrink-0 text-[10px] font-black text-white ${H?"bg-red-500":"bg-orange-500"}`,children:H?"0":ae}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${H?"text-red-600":"text-orange-600"}`,children:H?"Initial Attempt":`Retry #${ae}`}),!H&&e.jsxs("span",{className:"text-[9px] font-mono text-gray-400",children:["+",ae===1?"1s":ae===2?"3s":"9s"," backoff"]})]}),e.jsx("p",{className:"text-[11px] font-mono text-gray-700 break-all leading-relaxed",children:b})]})]},$)})}):e.jsx("div",{className:"px-4 py-3 rounded-lg bg-gray-50 border border-gray-200 text-center",children:e.jsx("p",{className:"text-xs text-gray-500",children:"No retry errors recorded"})})]}),e.jsx("div",{className:"border-t border-gray-100 px-5 py-4 bg-gray-50/50",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-[10px]",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"batch_id"}),e.jsx("span",{className:"font-mono text-gray-700 break-all",children:i.batch_id||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"source"}),e.jsx("span",{className:"font-mono text-gray-700",children:i.source})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"last_retry_at"}),e.jsx("span",{className:"font-mono text-gray-700",children:i.last_retry_at?new Date(i.last_retry_at).toLocaleStr
11ing():"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"error_message"}),e.jsx("span",{className:"font-mono text-gray-700 break-all text-[9px]",children:i.error_message?i.error_message.slice(0,120)+(i.error_message.length>120?"...":""):"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"program_name"}),e.jsx("span",{className:"font-mono text-gray-700",children:i.program_name||"—"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"email_type"}),e.jsx("span",{className:"font-mono text-gray-700",children:i.email_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"late_fee_applied"}),e.jsx("span",{className:"font-mono text-gray-700",children:i.late_fee_applied?`Yes (${Et(i.late_fee_amount)})`:"No"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-gray-400 uppercase tracking-wider block mb-0.5",children:"student_id"}),e.jsx("span",{className:"font-mono text-gray-700 break-all text-[9px]",children:i.student_id})]})]})}),e.jsxs("div",{className:"border-t border-gray-100 px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(le,{size:14,className:"text-emerald-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"End-to-End Verification"})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[{check:i.retry_count===3,label:"retry_count = 3",detail:`Actual: ${i.retry_count}`},{check:i.email_status==="failed_after_retries",label:"email_status = 'failed_after_retries'",detail:`Actual: ${i.email_status}`},{check:(i.retry_errors||[]).length===4,label:"retry_errors has 4 entries (initial + 3 retries)",detail:`Actual: ${(i.retry_errors||[]).length} entries`},{check:i.max_retries===3,label:"max_retries = 3",detail:`Actual: ${i.max_retries}`},{check:!!i.last_retry_at,label:"last_retry_at is populated",detail:i.last_retry_at?new Date(i.last_retry_at).toLocaleTimeString():"null"},{check:!!i.error_message,label:"error_message is populated",detail:i.error_message?"Yes":"null"}].map((b,$)=>e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg border ${b.check?"bg-emerald-50 border-emerald-200":"bg-red-50 border-red-200"}`,children:[b.check?e.jsx(le,{size:14,className:"text-emerald-600 shrink-0"}):e.jsx(Ie,{size:14,className:"text-red-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-[10px] font-bold ${b.check?"text-emerald-700":"text-red-700"}`,children:b.label}),e.jsx("p",{className:"text-[9px] font-mono text-gray-500",children:b.detail})]}),e.jsx("span",{className:`text-[9px] font-bold px-1.5 py-0.5 rounded ${b.check?"bg-emerald-100 text-emerald-700":"bg-red-100 text-red-700"}`,children:b.check?"PASS":"FAIL"})]},$))}),(()=>{const b=i.retry_count===3&&i.email_status==="failed_after_retries"&&(i.retry_errors||[]).length===4&&i.max_retries===3&&!!i.last_retry_at&&!!i.error_message;return e.jsx("div",{className:`mt-3 p-4 rounded-xl border-2 text-center ${b?"bg-emerald-50 border-emerald-300":"bg-amber-50 border-amber-300"}`,children:b?e.jsxs(e.Fragment,{children:[e.jsx(le,{size:24,className:"text-emerald-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm font-bold text-emerald-800",children:"All Checks Passed"}),e.jsx("p",{className:"text-[10px] text-emerald-600 mt-1",children:"Retry mechanism verified end-to-e
11nd: initial + 3 retries with exponential backoff, status correctly set to failed_after_retries, all 4 attempt errors captured in retry_errors array. Admin retry failure alert email sent via Mailgun."})]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{size:24,className:"text-amber-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm font-bold text-amber-800",children:"Some Checks Did Not Pass"}),e.jsx("p",{className:"text-[10px] text-amber-600 mt-1",children:"Review the results above. If the email was delivered (e.g., Mailgun accepted the invalid domain), the retry mechanism may have succeeded on a retry attempt."})]})})})()]})]})]})]})]})},$e="#6B1D3A",na="#C5A572",De="mail.zorganicsinstitute.edu",ps=["permanent_fail","temporary_fail","complained","unsubscribed","delivered","opened","clicked"],hs={permanent_fail:{label:"Permanent Failure",tab:"Bounces",description:"Hard bounces — invalid recipient, blocked domain, mailbox does not exist",severity:"critical"},temporary_fail:{label:"Temporary Failure",tab:"Bounces",description:"Soft bounces — temporary issue, full mailbox, greylisting, will retry",severity:"reputation"},complained:{label:"Spam Complaints",tab:"Spam Complaints",description:"Recipient marked the email as spam (most damaging to .edu reputation)",severity:"critical"},unsubscribed:{label:"Unsubscribes",tab:"Unsubscribes",description:"Recipient clicked Mailgun unsubscribe link",severity:"reputation"},delivered:{label:"Delivered Messages",tab:"Delivered Messages",description:"Successful SMTP delivery (250 OK from recipient MX)",severity:"engagement"},opened:{label:"Opens",tab:"Opens",description:"Tracking pixel loaded (requires open tracking enabled on the domain)",severity:"engagement"},clicked:{label:"Clicks",tab:"Clicks",description:"Tracked link clicked (requires click tracking enabled on the domain)",severity:"engagement"}};function ia(){var t;const n=(t=D)==null?void 0:t.supabaseUrl;let v="tojqzezdtojnxquphifh";try{n&&(v=new URL(n).host.split(".")[0])}catch{}const m=`${n||`https://${v}.databasepad.com`}/functions/v1/mailgun-webhook`,f=`https://${v}.supabase.co/functions/v1/mailgun-webhook`;return{primary:m,canonical:f,projectRef:v}}const oa=({open:n,onClose:v})=>{const{primary:m,canonical:f,projectRef:t}=r.useMemo(ia,[]),[N,S]=r.useState([]),[z,l]=r.useState(!0),[A,o]=r.useState(!1),[y,a]=r.useState(null),[d,k]=r.useState(!1),[B,_]=r.useState(null),P=r.useCallback(async()=>{l(!0);const g=new Date(Date.now()-24*60*60*1e3).toISOString(),{data:x,error:w}=await D.from("mailgun_events").select("event_type, created_at").eq("sending_domain",De).gte("created_at",g);if(!w&&x){const M={};for(const L of x){const I=L.event_type;M[I]=(M[I]||0)+1}const T=Object.entries(M).map(([L,I])=>({event_type:L,count:I}
11)).sort((L,I)=>I.count-L.count);S(T)}else S([]);l(!1)},[]);r.useEffect(()=>{n&&P()},[n,P]);const J=async()=>{o(!0),a(null),k(!1);try{const{data:g,error:x}=await D.functions.invoke("mailgun-webhook-test-signature",{body:{webhookUrl:m,sendingDomain:De,senderAddress:`info@${De}`,recipient:"[email protected]",eventType:"delivered"}});a(x?{success:!1,stage:"invoke_error",error:x.message}:g)}catch(g){a({success:!1,stage:"exception",error:(g==null?void 0:g.message)||"Unknown error"})}finally{o(!1),setTimeout(()=>P(),600)}},Y=(g,x)=>{navigator.clipboard.writeText(g).then(()=>{_(x),setTimeout(()=>_(null),1800)})};if(!n)return null;const i=N.reduce((g,x)=>g+x.count,0),Q=g=>g==="verified"?"emerald":g==="signature_invalid"||g==="http_error"?"red":g==="event_not_persisted"||g==="config"?"amber":g==="network"?"red":"gray";return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl max-w-5xl w-full max-h-[92vh] overflow-y-auto my-4",children:[e.jsxs("div",{className:"sticky top-0 z-10 px-6 py-4 border-b border-gray-200 bg-white flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center",style:{background:`linear-gradient(135deg, ${$e}, ${$e}cc)`},children:e.jsx(vs,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-black text-gray-900 flex items-center gap-2",children:["Mailgun Webhook Setup Wizard",e.jsx("span",{className:"text-[9px] font-mono font-bold uppercase tracking-wider px-2 py-0.5 rounded-full",style:{backgroundColor:`${na}33`,color:$e},children:"One-Time Setup"})]}),e.jsxs("p",{className:"text-[11px] text-gray-500",children:["Wire ",e.jsx("span",{className:"font-mono font-bold text-gray-700",children:De})," events into the existing mailgun-webhook function and verify HMAC delivery end-to-end"]})]})]}),e.jsx("button",{onClick:v,className:"p-2 rounded-lg hover:bg-gray-100 transition-colors",children:e.jsx(Ie,{size:18,className:"text-gray-400"})})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"rounded-2xl border-2 border-indigo-100 bg-gradient-to-br from-indigo-50/70 via-white to-violet-50/40 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3 flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-indigo-100 flex items-center justify-center",children:e.jsx(_t,{size:16,className:"text-indigo-700"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Last 24h Event Count"}),e.jsxs("p",{className:"text-[10px] text-gray-500",children:["Live read from ",e.jsx("code",{className:"font-mono text-indigo-700",children:"mailgun_events"})," WHERE sending_domain=",e.jsxs("code",{className:"font-mono",children:["'",De,"'"]})," GROUP BY event_type"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`px-3 py-1 rounded-lg text-[11px] font-mono font-black ${i>0?"bg-emerald-100 text-emerald-700":"bg-gray-100 text-gray-500"}`,children:z?e.jsx(X,{size:11,className:"animate-spin"}):`${i} TOTAL`}),e.jsxs("button",{onClick:P,disabled:z,className:"flex items-center gap-1 px-2.5 py-1 rounded-lg text-[10px] font-semibold border border-indigo-200 text-indigo-700 hover:bg-indigo-50 disabled:opacity-40",children:[e.jsx(Se,{size:10,className:z?"animate-spin":""})," Refresh"]})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-7 gap-2",children:ps.map(g=>{const x=N.find(I=>I.event_type===g),w=(x==null?void 0:x.count)||0,M=hs[g],T=(M==null?void 0:M.severity)||"engagement",L=g==="delivered"?"bg-emerald-50 border-emerald-200 text-emerald-700":g==="permanent_fail"?"bg-red-50 border-red-200 text-red-700":g==="temporary_fail"?"bg-amber-50 border-amber-200 text-amber-700":g==="complained"?"bg-purple-50 border-purple-200 text-purple-700":g==="unsubscribed"?"bg-gray-100 border-gray-200 text-gray-700":g==="opened"?"bg-blue-50 border-blue-200 text-blue-700":"bg-indigo-50 border-indigo-200 text-indigo-700";return e.jsxs("div",{className:`rounded-lg border p-2 text-center ${L}`,children:[e.jsx("p",{className:"font-mono text-lg font-black",children:w}),e.jsx("p",{className:"text-[8px] font-bold uppercase tracking-wide truncate",children:g}),e.jsx("p",{className:"text-[7px] opacity-70 mt-0.5",children:T})]},g)})}),!z&&i===0&&e.jsxs("div",{className:"mt-3 rounded-lg bg-amber-50 border border-amber-200 p-2.5 flex items-start gap-2",children:[e.jsx(Ee,{size:12,className:"text-amber-600 shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-[10px] text-amber-800",children:["No events received in the last 24 hours for ",e.jsx("strong",{children:De}),". This is expected before the Mailgun webhook is wired up. Run the ",e.jsx("strong",{children:"Test Signature"}
11)," probe below to verify the pipeline end-to-end."]})]})]}),e.jsxs("div",{className:"rounded-2xl border-2 border-gray-200 bg-white p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-white text-xs font-black",style:{backgroundColor:$e},children:"1"}),e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Webhook URL (copy this into Mailgun)"})]}),e.jsxs("p",{className:"text-[11px] text-gray-600 mb-3",children:["This is the live endpoint of the ",e.jsx("code",{className:"font-mono bg-gray-100 px-1 rounded",children:"mailgun-webhook"})," edge function on this project (ref ",e.jsx("code",{className:"font-mono bg-gray-100 px-1 rounded",children:t}),"). Paste it verbatim into each webhook event row in the Mailgun control panel."]}),e.jsxs("div",{className:"rounded-lg border border-gray-300 bg-gray-50 p-3 flex items-center justify-between gap-3",children:[e.jsx("code",{className:"font-mono text-[11px] text-gray-800 break-all flex-1",children:m}),e.jsxs("button",{onClick:()=>Y(m,"primary-url"),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-[10px] font-semibold text-white shrink-0",style:{backgroundColor:$e},children:[B==="primary-url"?e.jsx(Wt,{size:11}):e.jsx(Yt,{size:11}),B==="primary-url"?"Copied":"Copy URL"]})]}),e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"text-[10px] text-gray-500 cursor-pointer hover:text-gray-700",children:"Canonical supabase.co alias (same function, different host)"}),e.jsxs("div",{className:"mt-2 rounded-lg border border-gray-200 bg-gray-50/50 p-3 flex items-center justify-between gap-3",children:[e.jsx("code",{className:"font-mono text-[10px] text-gray-600 break-all flex-1",children:f}),e.jsxs("button",{onClick:()=>Y(f,"canonical-url"),className:"flex items-center gap-1 px-2 py-1 rounded text-[9px] font-semibold border border-gray-300 text-gray-600 hover:bg-gray-100 shrink-0",children:[B==="canonical-url"?e.jsx(Wt,{size:9}):e.jsx(Yt,{size:9}),B==="canonical-url"?"Copied":"Copy"]})]})]})]}),e.jsxs("div",{className:"rounded-2xl border-2 border-gray-200 bg-white p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-white text-xs font-black",style:{backgroundColor:$e},children:"2"}),e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Wire 7 Events in the Mailgun Control Panel"})]}),e.jsx("div",{className:"rounded-lg bg-indigo-50 border border-indigo-200 p-3 mb-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Zt,{size:14,className:"text-indigo-700 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-[11px] text-indigo-900",children:[e.jsx("p",{className:"font-bold mb-1",children:"Navigate path (US region, Mailgun v5 UI):"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-0.5 text-indigo-800",children:[e.jsxs("li",{children:["Log into ",e.jsxs("a",{href:"https://app.mailgun.com/",target:"_blank",rel:"noopener noreferrer",className:"underline font-semibold inline-flex items-center gap-0.5",children:["app.mailgun.com ",e.jsx(vt,{size:9})]})," with the Zorganics admin account"]}),e.jsxs("li",{children:["Top-left dropdown → confirm region is set to ",e.jsx("strong",{children:"US"})]}),e.jsxs("li",{children:["Left sidebar → ",e.jsx("strong",{children:"Send"})," → ",e.jsx("strong",{children:"Sending"})," → ",e.jsx("strong",{children:"Webhooks"})]}),e.jsxs("li",{children:["In the domain selector at the top of the Webhooks page, choose ",e.jsx("code",{className:"font-mono bg-white px-1 rounded font-bold",children:De})]})]})]})]})}),e.jsxs("p",{className:"text-[11px] text-gray-600 mb-2 font-semibold",children:["For each row below, click the ",e.jsx("strong",{children:"+ Add webhook"})," (or pencil edit icon) and paste the webhook URL from Step 1:"]}),e.jsx("div",{className:"rounded-lg border border-gray-200 overflow-hidden",children:e.jsxs("table",{className:"w-full text-[11px]",children:[e.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-bold text-gray-600",children:"#"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold text-gray-600",children:"Event Type (Mailgun ID)"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold text-gray-600",children:"UI Row Label"}),e.jsx("th",{className:"px-3 py-2 text-left font-bold text-gray-600",children:"What it captures"}),e.jsx("th",{className:"px-3 py-2 text-center font-bold text-gray-600",children:"Priority"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:ps.map((g,x)=>{const w=hs[g],M=w.severity==="critical"?"bg-red-50 text-red-700 border-red-200":w.severity==="reputation"?"bg-amber-50 text-amber-700 border-amber-200":"bg-blue-50 text-blue-700 border-blue-200";return e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-3 py-2 text-gray-400 font-mono",children:x+1}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("code",{className:"font-mono font-bold text-gray-900",children:g})}),e.jsx("td",{className:"px-3 py-2 text-gray-700",children:w.label}),e.jsx("td",{className:"px-3 py-2 text-gray-500 text-[10px]",children:w.description}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`inline-block px-1.5 py-0.5 rounded text-[9px] font-bold border ${M}`,children:w.severity==="critical"?"CRITICAL":w.severity==="reputation"?"REP":"ENG"})})]},g)})})]})}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 md:grid-cols-2 gap-3 text-[10px]",children:[e.jsxs("div",{className:"rounded-lg bg-emerald-50 border border-emerald-200 p-3",children:[e.jsxs("p",{className:"font-bold text-emerald-900 mb-1 flex items-center gap-1",children:[e.jsx(le,{size:11})," Per row, enter:"]}
11),e.jsxs("ul",{className:"space-y-0.5 text-emerald-800 list-disc list-inside",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"URL:"})," paste webhook URL from Step 1"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"HTTP method:"})," POST"]}),e.jsxs("li",{children:["Click ",e.jsx("strong",{children:"Save webhook"})]})]})]}),e.jsxs("div",{className:"rounded-lg bg-amber-50 border border-amber-200 p-3",children:[e.jsxs("p",{className:"font-bold text-amber-900 mb-1 flex items-center gap-1",children:[e.jsx(Is,{size:11})," Important toggles:"]}),e.jsxs("ul",{className:"space-y-0.5 text-amber-800 list-disc list-inside",children:[e.jsxs("li",{children:["Domain settings → ",e.jsx("strong",{children:"Tracking"}),": enable ",e.jsx("em",{children:"Open tracking"})," + ",e.jsx("em",{children:"Click tracking"})," (required for opens/clicks)"]}),e.jsxs("li",{children:["Verify ",e.jsx("strong",{children:"HTTP webhook signing key"})," matches the ",e.jsx("code",{className:"font-mono",children:"MAILGUN_WEBHOOK_SIGNING_KEY"})," stored in Famous Secrets"]})]})]})]})]}),e.jsxs("div",{className:"rounded-2xl border-2 border-gray-200 bg-white p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center text-white text-xs font-black",style:{backgroundColor:$e},children:"3"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Test Signature (end-to-end HMAC verification)"}),e.jsxs("p",{className:"text-[10px] text-gray-500",children:["POSTs a synthetic event signed with ",e.jsx("code",{className:"font-mono",children:"MAILGUN_WEBHOOK_SIGNING_KEY"})," (HMAC-SHA-256 of ",e.jsx("code",{className:"font-mono",children:"timestamp + token"}),") and confirms ",e.jsx("code",{className:"font-mono",children:"signatureValid: true"})]})]})]}),e.jsxs("button",{onClick:J,disabled:A,className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold text-white shadow-sm transition-all disabled:opacity-50",style:{background:`linear-gradient(135deg, ${$e}, ${$e}dd)`},children:[A?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(et,{size:12}),A?"Sending signed probe…":"Run Test Signature"]})]}),!y&&!A&&e.jsxs("div",{className:"rounded-lg border border-dashed border-gray-300 bg-gray-50 p-4 text-center",children:[e.jsx(Vt,{size:24,className:"mx-auto mb-2 text-gray-300"}),e.jsx("p",{className:"text-[11px] text-gray-500 font-medium",children:"No test run yet"}),e.jsxs("p",{className:"text-[10px] text-gray-400 mt-0.5",children:["Click ",e.jsx("strong",{children:"Run Test Signature"})," to send a signed payload through the same code path Mailgun uses"]})]}),y&&(()=>{const g=Q(y.stage),x=y.success?tt:y.stage==="signature_invalid"?qs:je;return e.jsxs("div",{className:`rounded-xl border-2 p-4 ${g==="emerald"?"border-emerald-300 bg-emerald-50/60":g==="red"?"border-red-300 bg-red-50/60":g==="amber"?"border-amber-300 bg-amber-50/60":"border-gray-300 bg-gray-50/60"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(x,{size:20,className:g==="emerald"?"text-emerald-600":g==="red"?"text-red-600":g==="amber"?"text-amber-600":"text-gray-500"}),e.jsxs("div",{children:[e.jsx("p",{className:`text-sm font-black ${g==="emerald"?"text-emerald-900":g==="red"?"text-red-900":g==="amber"?"text-amber-900":"text-gray-800"}`,children:y.success?"PASS — HMAC verified, event persisted":y.stage==="signature_invalid"?"FAIL — HMAC signature rejected":y.stage==="event_not_persisted"?"PARTIAL — Signature OK but event not written":y.stage==="http_error"?`FAIL — HTTP ${y.httpStatus} from webhook`:y.stage==="config"?"BLOCKED — Server config issue":y.stage==="network"?"FAIL — Network error reaching webhook":`FAIL — stage: ${y.stage}`}),y.error&&e.jsx("p",{className:`text-[11px] mt-0.5 ${g==="red"?"text-red-700":"text-gray-700"}`,children:y.error}),y.remediation&&e.jsxs("p",{className:"text-[10px] text-amber-700 mt-1 font-semibold",children:["→ ",y.remediation]})]})]}),e.jsxs("button",{onClick:()=>k(!d),className:"flex items-center gap-1 px-2 py-1 rounded text-[10px] font-semibold bg-white border border-gray-200 text-gray-600 hover:bg-gray-50",children:[d?e.jsx(Le,{size:10}):e.jsx(Fe,{size:10}),d?"Hide":"Show"," details"]}
11)]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 text-[10px]",children:[e.jsxs("div",{className:"rounded bg-white border border-gray-100 p-2",children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase text-[8px]",children:"HMAC Verification"}),e.jsx("p",{className:`font-mono font-bold ${y.signatureValid?"text-emerald-700":"text-red-700"}`,children:y.signatureValid?"VALID ✓":"REJECTED ✗"})]}),e.jsxs("div",{className:"rounded bg-white border border-gray-100 p-2",children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase text-[8px]",children:"Event Persisted"}),e.jsx("p",{className:`font-mono font-bold ${y.mailgunEventStored?"text-emerald-700":"text-red-700"}`,children:y.mailgunEventStored?"YES ✓":"NO ✗"})]}),e.jsxs("div",{className:"rounded bg-white border border-gray-100 p-2",children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase text-[8px]",children:"HTTP Status"}),e.jsx("p",{className:`font-mono font-bold ${y.httpStatus&&y.httpStatus>=200&&y.httpStatus<300?"text-emerald-700":"text-red-700"}`,children:y.httpStatus??"—"})]}),e.jsxs("div",{className:"rounded bg-white border border-gray-100 p-2",children:[e.jsx("p",{className:"font-semibold text-gray-400 uppercase text-[8px]",children:"Round Trip"}),e.jsx("p",{className:"font-mono font-bold text-gray-700",children:y.durationMs!=null?`${y.durationMs}ms`:"—"})]})]}),d&&e.jsxs("div",{className:"mt-3 space-y-2",children:[y.sentPayload&&e.jsxs("div",{className:"rounded bg-gray-900 text-emerald-300 font-mono text-[9px] p-3 overflow-x-auto",children:[e.jsx("p",{className:"text-gray-400 mb-1",children:"// Signed payload sent"}),e.jsx("pre",{children:JSON.stringify(y.sentPayload,null,2)})]}),y.diagnostics&&e.jsxs("div",{className:"rounded bg-gray-900 text-cyan-300 font-mono text-[9px] p-3 overflow-x-auto",children:[e.jsx("p",{className:"text-gray-400 mb-1",children:"// Diagnostics"}),e.jsx("pre",{children:JSON.stringify(y.diagnostics,null,2)})]}),y.webhookResponse&&e.jsxs("div",{className:"rounded bg-gray-900 text-amber-200 font-mono text-[9px] p-3 overflow-x-auto",children:[e.jsx("p",{className:"text-gray-400 mb-1",children:"// Response from mailgun-webhook"}),e.jsx("pre",{children:JSON.stringify(y.webhookResponse,null,2)})]}),y.messageId&&e.jsxs("div",{className:"rounded bg-indigo-50 border border-indigo-200 p-2",children:[e.jsxs("p",{className:"text-[10px] text-indigo-800",children:["Synthetic ",e.jsx("code",{className:"font-mono",children:"message_id"}),": ",e.jsx("code",{className:"font-mono font-bold",children:y.messageId})]}),e.jsxs("p",{className:"text-[9px] text-indigo-600 mt-0.5",children:["This row is now in ",e.jsx("code",{className:"font-mono",children:"mailgun_events"})," with ",e.jsxs("code",{className:"font-mono",children:["sending_domain='",De,"'"]})," — visible in the Last 24h badge above."]})]})]})]})})()]}),e.jsx("div",{className:"rounded-xl border border-gray-200 bg-gray-50 p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Kt,{size:12,className:"text-gray-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-[10px] text-gray-600",children:[e.jsx("p",{className:"font-bold mb-1",children:"Why this is one-time:"}),e.jsxs("p",{children:["Once Mailgun is wired up (Step 2) and the Test Signature probe (Step 3) returns ",e.jsx("strong",{children:"PASS"}),", every real webhook delivery for ",e.jsx("code",{className:"font-mono",children:De})," will be HMAC-verified, written to",e.jsx("code",{className:"font-mono",children:" mailgun_events"}),", and surfaced on the ",e.jsx("strong",{children:".EDU Sending Domain Reputation"})," widget on the Bounce Rate Monitor — automatically and forever, with no further wiring needed."]})]})]})})]})]})})};function da({open:n,onClose:v}){const[m,f]=r.useState([]),[t,N]=r.useState([]),[S,z]=r.useState(!1),[l,A]=r.useState(""),[o,y]=r.useState("all"),[a,d]=r.useState("all"),[k,B]=r.useState(""),[_,P]=r.useState("Manually suppressed by admin"),[J,Y]=r.useState(null),[i,Q]=r.useState(null),g=async()=>{z(!0);const[{data:h},{data:O}]=await Promise.all([D.from("mailgun_suppressions").select("recipient, reason, suppressed_at, source, sending_domain, event_type, notes").order("suppressed_at",{ascending:!1}).limit(2e3),D.from("mailgun_suppression_skips").select("id, recipient, send_function, email_type, suppression_reason, skipped_at").order("skipped_at",{ascending:!1}).limit(50)]);f(h||[]),N(O||[]),z(!1)};r.useEffect(()=>{n&&g()},[n]);const x=(h,O)=>{Q({kind:h,msg:O}),setTimeout(()=>Q(null),4e3)},w=r.useMemo(()=>{const h=l.trim().toLowerCase();return m.filter(O=>!(o!=="all"&&O.source!==o||a!=="all"&&O.event_type!==a||h&&!O.recipient.toLowerCase().includes(h)&&!(O.reason||"").toLowerCase().includes(h)))},[m,l,o,a]),M=r.useMemo(()=>{const h=m.length,O=m.filter(U=>U.event_type==="permanent_fail").length,q=m.filter(U=>U.event_type==="complained").length,ue=m.filter(U=>U.source==="manual").length;return{total:h,hard:O,complaints:q,manual:ue}},[m]),T=async h=>{if(!window.confirm(`Remove ${h} from the suppression list? Future sends to this address will go through Mailgun again.`))return;Y(h);const{error:O}=await D.from("mailgun_suppressions").delete().eq("recipient",h);Y(null),O?x("err",`Unsuppress failed: ${O.message}`):(x("ok",`Unsuppressed ${h}.`),f(q=>q.filter(ue=>ue.recipient!==h)))},L=async()=>{const h=k.trim().toLowerCase();if(!h||!h.includes("@")){x("err","Enter a valid email.");return}Y("add");const{error:O}=await D.from("mailgun_suppressions").insert({recipient:h,reason:_||"Manually suppressed by admin",source:"manual",event_type:null,notes:"Added via Suppression List Manager UI"});Y(null),O?x("err",`Add failed: ${O.message}`):(x("ok",`Added ${h} to suppression list.`),B(""),g())},I=()=>{const h=["recipient","reason","event_type","source","sending_domain","suppressed_at","notes"],O=$=>{if($==null)return"";const H=String($).replace(/"/g,'""');return/[",\n]/.test(H)?`"${H}"`:H},q=[h.join(",")];
11w.forEach($=>{q.push([$.recipient,$.reason,$.event_type,$.source,$.sending_domain,$.suppressed_at,$.notes].map(O).join(","))});const ue=new Blob([q.join(`
12`)],{type:"text/csv;charset=utf-8"}),U=URL.createObjectURL(ue),b=document.createElement("a");b.href=U,b.download=`mailgun-suppressions-${new Date().toISOString().split("T")[0]}.csv`,document.body.appendChild(b),b.click(),document.body.removeChild(b),URL.revokeObjectURL(U),x("ok",`Exported ${w.length} row(s) to CSV.`)};return n?e.jsx("div",{className:"fixed inset-0 z-50 bg-black/60 backdrop-blur-sm flex items-start justify-center p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-6xl my-8 border-2 border-rose-900/20",children:[e.jsxs("div",{className:"bg-gradient-to-r from-rose-900 to-rose-950 text-white p-6 rounded-t-2xl flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"bg-amber-400/20 rounded-lg p-2.5",children:e.jsx(ts,{className:"w-6 h-6 text-amber-300"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Mailgun Suppression List"}),e.jsx("p",{className:"text-sm text-rose-100/80 mt-0.5",children:"Auto-ingested hard bounces & complaints across all sending domains · Manual unsuppress · CSV export"})]})]}),e.jsx("button",{onClick:v,className:"text-rose-100 hover:text-white hover:bg-white/10 rounded-lg p-2 transition",children:e.jsx(Ie,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-5",children:[i&&e.jsxs("div",{className:`flex items-center gap-2 px-4 py-2.5 rounded-lg border text-sm ${i.kind==="ok"?"bg-emerald-50 border-emerald-200 text-emerald-900":"bg-rose-50 border-rose-200 text-rose-900"}`,children:[i.kind==="ok"?e.jsx(Bs,{className:"w-4 h-4"}):e.jsx(ce,{className:"w-4 h-4"}),i.msg]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(yt,{label:"Total Suppressed",value:M.total,accent:"rose",icon:e.jsx(Re,{className:"w-4 h-4"})}),e.jsx(yt,{label:"Hard Bounces",value:M.hard,accent:"amber",icon:e.jsx(ce,{className:"w-4 h-4"})}),e.jsx(yt,{label:"Complaints",value:M.complaints,accent:"purple",icon:e.jsx(ts,{className:"w-4 h-4"})}),e.jsx(yt,{label:"Manual",value:M.manual,accent:"slate",icon:e.jsx(ss,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"border border-slate-200 rounded-xl p-4 bg-slate-50/50",children:[e.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-slate-600 mb-2",children:"Manually Add Suppression"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Tt,{placeholder:"[email protected]",value:k,onChange:h=>B(h.target.value),className:"bg-white"}),e.jsx(Tt,{placeholder:"Reason (optional)",value:_,onChange:h=>P(h.target.value),className:"bg-white"}),e.jsxs(ut,{onClick:L,disabled:J==="add"||!k,size:"sm",className:"w-full bg-rose-900 hover:bg-rose-950",children:[e.jsx(ss,{className:"w-4 h-4 mr-1"})," ",J==="add"?"Adding…":"Suppress Recipient"]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-xl p-4 bg-slate-50/50",children:[e.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-slate-600 mb-2",children:"Filter & Export"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ps,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"}),e.jsx(Tt,{placeholder:"Search recipient or reason…",value:l,onChange:h=>A(h.target.value),className:"bg-white pl-9"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:o,onChange:h=>y(h.target.value),className:"flex-1 text-sm border border-slate-200 rounded-md px-2 py-1.5 bg-white",children:[e.jsx("option",{value:"all",children:"All sources"}),e.jsx("option",{value:"mailgun_event",children:"Mailgun event"}),e.jsx("option",{value:"manual",children:"Manual"})]}),e.jsxs("select",{value:a,onChange:h=>d(h.target.value),className:"flex-1 text-sm border border-slate-200 rounded-md px-2 py-1.5 bg-white",children:[e.jsx("option",{value:"all",children:"All events"}),e.jsx("option",{value:"permanent_fail",children:"Hard bounces"}),e.jsx("option",{value:"complained",children:"Complaints"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(ut,{size:"sm",variant:"outline",onClick:g,disabled:S,className:"flex-1",children:[e.jsx(Se,{className:`w-4 h-4 mr-1 ${S?"animate-spin":""}`})," Refresh"]}),e.jsxs(ut,{size:"sm",onClick:I,disabled:w.length===0,className:"flex-1 bg-amber-600 hover:bg-amber-700",children:[e.jsx(ws,{className:"w-4 h-4 mr-1"})," CSV (",w.length,")"]})]})]})]})]}),e.jsxs("div",{className:"border border-slate-200 rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"bg-slate-100 px-4 py-2 text-xs font-bold uppercase tracking-wider text-slate-700 flex items-center justify-between",children:[e.jsxs("span",{children:["Suppressed Recipients (",w.length," of ",m.length,")"]}),e.jsx("span",{className:"text-slate-500 font-normal normal-case tracking-normal",children:"Sorted by most recent"})]}),e.jsx("div",{className:"max-h-[420px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-white sticky top-0 border-b border-slate-200",children:e.jsxs("tr",{className:"text-left text-xs uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Recipient"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Event"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Source"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Domain"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Reason"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Suppressed"}),e.jsx("th",{className:"px-3 py-2 font-semibold text-right",children:"Action"})]})}),e.jsxs("tbody",{children:[w.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-3 py-12 text-center text-slate-400 italic",children:S?"
12Loading suppressions…":"No suppressions match the current filters."})}),w.map(h=>e.jsxs("tr",{className:"border-t border-slate-100 hover:bg-rose-50/30",children:[e.jsx("td",{className:"px-3 py-2 font-mono text-xs text-slate-900 break-all",children:h.recipient}),e.jsxs("td",{className:"px-3 py-2",children:[h.event_type==="permanent_fail"&&e.jsx(gt,{className:"bg-amber-100 text-amber-900 border-amber-300 hover:bg-amber-100",children:"Hard Bounce"}),h.event_type==="complained"&&e.jsx(gt,{className:"bg-purple-100 text-purple-900 border-purple-300 hover:bg-purple-100",children:"Complaint"}),!h.event_type&&e.jsx(gt,{variant:"outline",className:"text-slate-500",children:"—"})]}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-600",children:h.source}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-600",children:h.sending_domain||"—"}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-700 max-w-xs truncate",title:h.reason||"",children:h.reason||"—"}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-500 whitespace-nowrap",children:new Date(h.suppressed_at).toLocaleString()}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsxs(ut,{size:"sm",variant:"outline",onClick:()=>T(h.recipient),disabled:J===h.recipient,className:"text-xs h-7 px-2 border-emerald-300 text-emerald-800 hover:bg-emerald-50",children:[e.jsx(Ns,{className:"w-3 h-3 mr-1"})," ",J===h.recipient?"…":"Unsuppress"]})})]},h.recipient))]})]})})]}),e.jsxs("div",{className:"border border-slate-200 rounded-xl overflow-hidden",children:[e.jsx("div",{className:"bg-slate-100 px-4 py-2 text-xs font-bold uppercase tracking-wider text-slate-700",children:"Recent Outbound Sends Blocked by Suppression List (last 50)"}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-white sticky top-0 border-b border-slate-200",children:e.jsxs("tr",{className:"text-left uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-3 py-2 font-semibold",children:"When"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Send Function"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Email Type"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Recipient"}),e.jsx("th",{className:"px-3 py-2 font-semibold",children:"Reason"})]})}),e.jsxs("tbody",{children:[t.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-3 py-6 text-center text-slate-400 italic",children:"No suppression skips logged yet. They'll appear here when send-financial-email, send-recruitment-email, send-payment-reminder, or send-lead-confirmation skip a suppressed recipient."})}),t.map(h=>e.jsxs("tr",{className:"border-t border-slate-100",children:[e.jsx("td",{className:"px-3 py-1.5 text-slate-500 whitespace-nowrap",children:new Date(h.skipped_at).toLocaleString()}),e.jsx("td",{className:"px-3 py-1.5",children:e.jsx(gt,{variant:"outline",className:"text-[10px] font-mono",children:h.send_function})}),e.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:h.email_type||"—"}),e.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:h.recipient}),e.jsx("td",{className:"px-3 py-1.5 text-slate-600 max-w-xs truncate",title:h.suppression_reason||"",children:h.suppression_reason||"—"})]},h.id))]})]})})]}),e.jsxs("p",{className:"text-[11px] text-slate-500 leading-relaxed",children:["Permanent failures and complaint events from ",e.jsx("span",{className:"font-mono",children:"mailgun_events"})," are automatically ingested into"," ",e.jsx("span",{className:"font-mono",children:"mailgun_suppressions"})," by the mailgun-webhook function. The four institutional send functions (financial, recruitment, payment-reminder, lead-confirmation) query this list before every outbound send and short-circuit with a logged skip in ",e.jsx("span",{className:"font-mono",children:"mailgun_suppression_skips"})," instead of attempting delivery."]})]})]})}):null}function yt({label:n,value:v,accent:m,icon:f}){const t={rose:"from-rose-50 to-rose-100 border-rose-200 text-rose-900",amber:"from-amber-50 to-amber-100 border-amber-200 text-amber-900",purple:"from-purple-50 to-purple-100 border-purple-200 text-purple-900",slate:"from-slate-50 to-slate-100 border-slate-200 text-slate-800"};return e.jsxs("div",{className:`bg-gradient-to-br ${t[m]} border rounded-xl p-3`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider font-bold opacity-80",children:[f,n]}),e.jsx("div",{className:"text-2xl font-bold mt-1 font-mono",children:v.toLocaleStr
12ing()})]})}function ca(){const[n,v]=require("react").useState(!1);return require("react").useEffect(()=>{const m=()=>v(!0);return typeof window<"u"&&window.addEventListener("open-suppression-list",m),()=>{typeof window<"u"&&window.removeEventListener("open-suppression-list",m)}},[]),e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>v(!0),title:"Open Mailgun Suppression List Manager",className:"fixed bottom-6 right-6 z-40 bg-gradient-to-br from-rose-900 to-rose-950 text-amber-200 shadow-2xl rounded-full px-4 py-3 text-sm font-bold tracking-wide border-2 border-amber-300/40 hover:scale-105 transition flex items-center gap-2",children:[e.jsx("span",{"aria-hidden":!0,children:"⛔"}),"Suppression List"]}),e.jsx(da,{open:n,onClose:()=>v(!1)})]})}typeof window<"u"&&(window.__openSuppressionList=()=>{const n=new CustomEvent("open-suppression-list");window.dispatchEvent(n)});const Je="#6B1D3A",us="#C5A572",Mt="mail.zorganicsinstitute.edu",xa=()=>{var Ne;const[n,v]=useState([]),[m,f]=useState(!0),[t,N]=useState(null),[S,z]=useState(!0),[l,A]=useState([]),[o,y]=useState(!0),[a,d]=useState(!1),[k,B]=useState(!1),[_,P]=useState(!1),[J,Y]=useState(!1),[i,Q]=useState("5.0"),[g,x]=useState(!1),[w,M]=useState(!1),[T,L]=useState(!1),[I,h]=useState(!1),O=useCallback(async()=>{f(!0),z(!0),y(!0);const u=new Date(Date.now()-30*24*60*60*1e3).toISOString(),[V,pe,me]=await Promise.all([D.from("compliance_email_log").select("*").order("created_at",{ascending:!1}).limit(500),D.from("compliance_auto_schedule").select("id, admin_alert_email, alert_on_high_bounce_rate, bounce_rate_threshold, last_bounce_alert_at, last_bounce_rate, last_bounce_alert_details").limit(1).single(),D.from("mailgun_events").select("id, event_type, recipient, message_id, severity, reason, sending_domain, event_timestamp, created_at").eq("sending_domain",Mt).gte("created_at",u).order("created_at",{ascending:!1}).limit(500)]);!V.error&&V.data&&v(V.data),!pe.error&&pe.data&&(N(pe.data),Q(String(pe.data.bounce_rate_threshold||5))),!me.error&&me.data&&A(me.data),f(!1),z(!1),y(!1)},[]);useEffect(()=>{O()},[O]);const q=useMemo(()=>{const u=(t==null?void 0:t.bounce_rate_threshold)||5,V={delivered:0,permanent_fail:0,temporary_fail:0,complained:0,unsubscribed:0,accepted:0,opened:0,clicked:0,rejected:0,stored:0};for(const xt of l){const mt=xt.event_type;V[mt]!==void 0&&V[mt]++}const pe=V.delivered,me=V.permanent_fail,he=V.temporary_fail,Be=V.complained,kt=V.unsubscribed,at=me+Be,Pe=pe+at,Ue=Pe>0?at/Pe*100:0,qe=Ue>u,ct=Pe>0?Be/Pe*100:0,St=Math.max(0,Math.min(100,Math.round(100-Ue*2-ct*10)));return{counts:V,delivered:pe,hard:me,soft:he,complained:Be,unsubscribed:kt,totalBounced:at,denominator:Pe,bounceRate:Ue,aboveThreshold:qe,score:St,threshold:u}},[l,t==null?void 0:t.bounce_rate_threshold]),ue=useMemo(()=>new Date(Date.now()-30*24*60*60*1e3),[]),U=useMemo(()=>n.filter(u=>new Date(u.created_at)>=ue),[n,ue]),b=U.filter(u=>u.email_status==="sent").length,$=U.filter(u=>u.email_status==="bounced").length,H=U.filter(u=>u.email_status==="bounced"&&u.bounce_type==="hard").length,ne=U.filter(u=>u.email_status==="bounced"&&u.bounce_type==="soft").length,ae=U.filter(u=>u.email_status==="bounced"&&u.bounce_type==="complaint").length,re=b+$,Z=re>0?$/re*100:0,ie=Z.toFixed(1),se=(t==null?void 0:t.bounce_rate_threshold)||5,c=Z>se,R=n.filter(u=>u.email_status==="sent").length,G=n.filter(u=>u.email_status==="bounced").length,F=R+G,C=F>0?(G/F*100).toFixed(1):"0.0",de=useMemo(()=>{const u=U.filter(me=>me.email_status==="bounced").sort((me,he)=>new Date(he.bounced_at||he.created_at).getTime()-new Date(me.bounced_at||me.created_at).getTime()),V=new Set,pe=[];for(const me of u){const he=me.student_email||"unknown";V.has(he)||(V.add(he),pe.push(me))}return pe},[U]),ge=async()=>{if(!t)return;M(!0);const u=!t.alert_on_high_bounce_rate,{error:V}=await D.from("compliance_auto_schedule").update({alert_on_high_bounce_rate:u,updated_at:new Date().toISOString()}).eq("id",t.id);V||N({...t,alert_on_high_bounce_rate:u}),M(!1)},Me=async()=>{if(!t)return;const u=parseFloat(i);if(isNaN(u)||u<0||u>100)return;x(!0);const{error:V}=await D.from("compliance_auto_schedule").update({bounce_rate_threshold:u,updated_at:new Date().toISOString()}).eq("id",t.id);V||(N({...t,bounce_rate_threshold:u}),Y(!1)),x(!1)},ee=t==null?void 0:t.last_bounce_alert_details;return m||S?e.jsx("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(X,{size:24,className:"animate-spin text-gray-300"})})}):e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{backgroundColor:c?"#fdf2f8":"#f0fdf4"}
12,children:c?e.jsx(wt,{size:18,className:"text-pink-600"}):e.jsx(Vt,{size:18,className:"text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Bounce Rate Monitor"}),e.jsxs("p",{className:"text-[10px] text-gray-500",children:["30-day rolling bounce rate with automatic admin alerts at ",se,"% threshold"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:O,className:"flex items-center gap-1 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-gray-200 text-gray-600 hover:bg-gray-50",children:[e.jsx(Se,{size:10})," Refresh"]}),e.jsxs("button",{onClick:()=>P(!_),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-semibold border text-pink-600 border-pink-200 hover:bg-pink-50 transition-colors",children:[_?e.jsx(Le,{size:12}):e.jsx(Fe,{size:12}),_?"Collapse":"Expand"]})]})]}),e.jsx("div",{className:`px-6 py-3 border-b border-gray-100 ${c?"bg-gradient-to-r from-pink-50/80 to-red-50/50":"bg-gradient-to-r from-emerald-50/50 to-green-50/30"}`,children:e.jsxs("div",{className:"flex items-center gap-6 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:`text-2xl font-mono font-black ${c?"text-pink-700":"text-emerald-700"}`,children:[ie,"%"]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold text-gray-600",children:"30-Day Bounce Rate"}),e.jsxs("p",{className:"text-[9px] text-gray-400",children:[$," bounced / ",re," total"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${c?"bg-red-500 animate-pulse":"bg-emerald-500"}`}),e.jsx("span",{className:`text-[10px] font-bold ${c?"text-red-700":"text-emerald-700"}`,children:c?`ABOVE ${se}% THRESHOLD`:`Below ${se}% threshold`})]}),e.jsxs("div",{className:"flex items-center gap-3 ml-auto",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500"}),e.jsxs("span",{className:"text-[9px] font-semibold text-gray-500",children:["Hard: ",H]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500"}),e.jsxs("span",{className:"text-[9px] font-semibold text-gray-500",children:["Soft: ",ne]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-purple-500"}),e.jsxs("span",{className:"text-[9px] font-semibold text-gray-500",children:["Spam: ",ae]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(We,{size:11,className:t!=null&&t.alert_on_high_bounce_rate?"text-pink-600":"text-gray-300"}),e.jsx("span",{className:`text-[9px] font-bold ${t!=null&&t.alert_on_high_bounce_rate?"text-pink-700":"text-gray-400"}`,children:t!=null&&t.alert_on_high_bounce_rate?"Alerts ON":"Alerts OFF"})]})]})}),e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 bg-gradient-to-r from-indigo-50/40 via-white to-violet-50/30",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center bg-indigo-100",children:e.jsx(Zt,{size:14,className:"text-indigo-700"})}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-bold text-gray-900 flex items-center gap-2",children:[".EDU Sending Domain Reputation",e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[8px] font-mono font-bold bg-indigo-100 text-indigo-700",children:Mt})]}),e.jsx("p",{className:"text-[9px] text-gray-500",children:"Real-time Mailgun webhook events (permanent_fail / temporary_fail / complained / unsubscribed) over the last 30 days, HMAC-verified via MAILGUN_WEBHOOK_SIGNING_KEY"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:`px-2.5 py-1 rounded-lg text-[10px] font-bold ${q.score>=90?"bg-emerald-100 text-emerald-700":q.score>=70?"bg-amber-100 text-amber-700":"bg-red-100 text-red-700"}`,children:["Reputation: ",q.score,"/100"]}),e.jsxs("button",{onClick:()=>B(!0),className:"flex items-center gap-1 px-2.5 py-1 rounded-lg text-[10px] font-bold text-white shadow-sm",style:{background:`linear-gradient(135deg, ${Je}, ${Je}dd)`},title:"Open one-time Mailgun webhook setup wizard",children:[e.jsx(vs,{size:10})," Setup Wizard"]}),e.jsxs("button",{onClick:()=>d(!a),className:"flex items-center gap-1 px-2.5 py-1 rounded-lg text-[10px] font-semibold border border-indigo-200 text-indigo-700 hover:bg-indigo-50",children:[a?e.jsx(Le,{size:10}):e.jsx(Fe,{size:10}),a?"Hide Events":`View ${l.length} Events`]})]})]}),o?e.jsxs("div",{className:"flex items-center justify-center py-3 text-gray-400",children:[e.jsx(X,{size:14,className:"animate-spin mr-2"}),e.jsx("span",{className:"text-[10px]",children:"Loading .edu domain events…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-7 gap-2",children:[e.jsxs("div",{className:`col-span-2 md:col-span-2 rounded-lg border p-3 flex items-center gap-3 ${q.aboveThreshold?"bg-pink-50 border-pink-200":"bg-emerald-50 border-emerald-200"}`,children:[e.jsxs("div",{className:`text-2xl font-mono font-black ${q.aboveThreshold?"text-pink-700":"text-emerald-700"}`,children:[q.bounceRate.toFixed(1),"%"]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-bold text-gray-700",children:".edu Bounce Rate"}),e.jsxs("p",{className:"text-[8px] text-gray-500",children:[q.totalBounced," / ",q.denominator," processed"]}),e.jsx("p",{className:`text-[8px] font-bold mt-0.5 ${q.aboveThreshold?"text-pink-700":"text-emerald-700"}`,children:q.aboveThreshold?`ABOVE ${q.threshold}% threshold`:`Below ${q.threshold}% threshold`})]})]}),e.jsxs("div",{className:"rounded-lg border border-emerald-100 bg-emerald-50/60 p-2 text-center",children:[e.jsx("p",{className:"font-mono text-base font-bold text-emerald-700",children:q.delivered}),e.jsx("p",{className:"text-[8px] font-semibold text-emerald-700 uppercase",children:"Delivered"})]}),e.jsxs("div",{className:"rounded-lg border border-red-100 bg-red-50/60 p-2 text-center",children:[e.jsx("p",{className:"font-mono text-base font-bold text-red-700",children:q.hard}),e.jsx("p",{className:"text-[8px] font-semibold text-red-700 uppercase",children:"Hard Bounce"})]}),e.jsxs("div",{className:"rounded-lg border border-amber-100 bg-amber-50/60 p-2 text-center",children:[e.jsx("p",{className:"font-mono text-base font-bold text-amber-700",children:q.soft}),e.jsx("p",{className:"text-[8px] font-semibold text-amber-700 uppercase",children:"Soft Bounce"})]}),e.jsxs("div",{className:"rounded-lg border border-purple-100 bg-purple-50/60 p-2 text-center",children:[e.jsx("p",{className:"font-mono text-base font-bold text-purple-700",children:q.complained}),e.jsx("p",{className:"text-[8px] font-semibold text-purple-700 uppercase",children:"Spam"})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 p-2 text-center",children:[e.jsx("p",{className:"font-mono text-base font-bold text-gray-700",children:q.unsubscribed}),e.jsx("p",{className:"text-[8px] font-semibold text-gray-600 uppercase",children:"Unsub"})]})]}),a&&e.jsx("div",{className:"mt-3 rounded-lg border border-gray-200 overflow-hidden",children:e.jsx("div",{className:"max-h-72 overflow-y-auto",children:l.length===0?e.jsxs("div",{className:"text-center py-6 text-gray-400",children:[e.jsx(_t,{size:20,className:"mx-auto mb-1 text-gray-300"}),e.jsxs("p",{className:"text-[11px] font-medium",children:["No webhook events recorded yet for ",Mt]}),e.jsx("p",{className:"text-[9px] text-gray-400 mt-1",children:"Events appear here as soon as Mailgun POSTs to the mailgun-webhook edge function"})]}):e.jsxs("table",{className:"w-full text-[11px]",children:[e.jsx("thead",{className:"bg-gray-50 sticky top-0",children:e.jsxs("tr",{className:"border-b border-gray-100",children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Event"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Recipient"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Severity"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Reason"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:l.slice(0,100).map(u=>{const V=u.event_type==="delivered"?"bg-emerald-50 text-emerald-700":u.event_type==="permanent_fail"?"bg-red-50 text-red-700":u.event_type==="temporary_fail"?"bg-amber-50 text-amber-700":u.event_type==="complained"?"bg-purple-50 text-purple-700":u.event_type==="unsubscribed"?"bg-gray-100 text-gray-700":u.event_type==="opened"?"bg-blue-50 text-blue-700":u.event_type==="clicked"?"bg-indigo-50 text-indigo-700":"bg-gray-50 text-gray-600",pe=u.event_timestamp||u.created_at;return e.jsxs("tr",{className:"hover:bg-indigo-50/30",children:[e.jsx("td",{className:"px-3 py-1.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold ${V}`,children:u.event_type})}),e.jsx("td",{className:"px-3 py-1.5 font-mono text-[10px] text-gray-600 truncate max-w-[180px]",title:u.recipient||"",children:u.recipient||"—"}),e.jsx("td",{className:"px-3 py-1.5 text-[10px] text-gray-500",children:u.severity||"—"}),e.jsx("td",{className:"px-3 py-1.5 text-[10px] text-gray-500 truncate max-w-[260px]",title:u.reason||"",children:u.reason||"—"}),e.jsx("td",{className:"px-3 py-1.5 font-mono text-[9px] text-gray-400 whitespace-nowrap",children:pe?new Date(pe).toLocaleStr
12ing("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"—"})]},u.id)})})]})})})]})]}),_&&e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:`rounded-xl border-2 p-5 ${t!=null&&t.alert_on_high_bounce_rate?"border-pink-200 bg-pink-50/30":"border-gray-200 bg-gray-50/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Kt,{size:14,className:"text-gray-500"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Alert Configuration"})]}),e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Admin Email Alerts"}),e.jsxs("button",{onClick:ge,disabled:w,className:`relative w-11 h-6 rounded-full transition-colors ${t!=null&&t.alert_on_high_bounce_rate?"bg-pink-500":"bg-gray-300"}`,children:[w&&e.jsx(X,{size:10,className:"absolute top-1.5 left-1/2 -translate-x-1/2 animate-spin text-white"}),e.jsx("div",{className:`absolute top-0.5 w-5 h-5 rounded-full bg-white shadow transition-transform ${t!=null&&t.alert_on_high_bounce_rate?"translate-x-5.5 left-0.5":"left-0.5"}`,style:{transform:t!=null&&t.alert_on_high_bounce_rate?"translateX(22px)":"translateX(0)"}})]})]}),e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Threshold"}),J?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"number",step:"0.5",min:"0",max:"100",value:i,onChange:u=>Q(u.target.value),className:"w-16 px-2 py-1 text-xs font-mono border border-pink-300 rounded text-center focus:outline-none focus:ring-1 focus:ring-pink-400"}),e.jsx("span",{className:"text-xs text-gray-400",children:"%"}),e.jsx("button",{onClick:Me,disabled:g,className:"px-2 py-1 rounded text-[9px] font-bold bg-pink-500 text-white hover:bg-pink-600 disabled:opacity-50",children:g?e.jsx(X,{size:10,className:"animate-spin"}):"Save"}),e.jsx("button",{onClick:()=>{Y(!1),Q(String(se))},className:"px-2 py-1 rounded text-[9px] font-bold bg-gray-200 text-gray-600 hover:bg-gray-300",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>Y(!0),className:"flex items-center gap-1 px-2 py-1 rounded text-xs font-mono font-bold text-pink-700 bg-pink-50 border border-pink-200 hover:bg-pink-100",children:[se,"% ",e.jsx(as,{size:10})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Alert Recipient"}),e.jsx("span",{className:"text-[10px] font-mono text-gray-500 truncate max-w-[160px]",children:(t==null?void 0:t.admin_alert_email)||"Not configured"})]}),e.jsx("div",{className:"mt-3 px-3 py-2 rounded-lg bg-white border border-gray-100",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ke,{size:10,className:"text-gray-400"}),e.jsx("span",{className:"text-[9px] text-gray-500",children:"Alert cooldown: 24 hours between alerts"})]})})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 p-5 bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(_s,{size:14,style:{color:us}}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"30-Day Rolling Window"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-3",children:[e.jsxs("div",{className:"text-center p-2 rounded-lg bg-emerald-50 border border-emerald-100",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-emerald-700",children:b}),e.jsx("p",{className:"text-[8px] font-semibold text-emerald-600 uppercase",children:"Delivered"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-pink-50 border border-pink-100",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-pink-700",children:$}),e.jsx("p",{className:"text-[8px] font-semibold text-pink-600 uppercase",children:"Bounced"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[e.jsxs("div",{className:"text-center p-1.5 rounded bg-red-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-red-700",children:H}),e.jsx("p",{className:"text-[7px] text-red-600 font-semibold uppercase",children:"Hard"})]}),e.jsxs("div",{className:"text-center p-1.5 rounded bg-amber-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-amber-700",children:ne}),e.jsx("p",{className:"text-[7px] text-amber-600 font-semibold uppercase",children:"Soft"})]}),e.jsxs("div",{className:"text-center p-1.5 rounded bg-purple-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-purple-700",children:ae}),e.jsx("p",{className:"text-[7px] text-purple-600 font-semibold uppercase",children:"Spam"})]})]}),e.jsx("div",{className:"mt-3 text-center",children:e.jsxs("span",{className:"text-[9px] text-gray-400",children:["All-time: ",C,"% (",G,"/",F,")"]})})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 p-5 bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(We,{size:14,style:{color:us}}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Last Bounce Alert"})]}),t!=null&&t.last_bounce_alert_at?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ce,{size:14,className:"text-pink-600"}),e.jsx("span",{className:"text-xs font-bold text-pink-700",children:"Alert Sent"})]}),e.jsx("p",{className:"text-[10px] text-gray-500 mb-2",children:new Date(t.last_bounce_alert_at).toLocaleStr
12ing("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}),t.last_bounce_rate!=null&&e.jsxs("div",{className:"px-3 py-2 rounded-lg bg-pink-50 border border-pink-100 mb-2",children:[e.jsxs("p",{className:"font-mono text-lg font-bold text-pink-700 text-center",children:[t.last_bounce_rate,"%"]}),e.jsx("p",{className:"text-[8px] text-pink-600 text-center font-semibold uppercase",children:"Rate at Alert Time"})]}),ee&&e.jsxs("button",{onClick:()=>h(!I),className:"w-full flex items-center justify-center gap-1 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-pink-200 text-pink-600 hover:bg-pink-50",children:[e.jsx(as,{size:10})," ",I?"Hide Details":"View Details"]})]}):e.jsxs("div",{className:"flex flex-col items-center py-4 text-gray-400",children:[e.jsx(We,{size:24,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No alerts sent yet"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:"Alerts fire when bounce rate exceeds threshold"})]})]})]}),I&&ee&&e.jsxs("div",{className:"rounded-xl border-2 border-pink-200 bg-pink-50/30 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ee,{size:14,className:"text-pink-600"}),e.jsx("span",{className:"text-xs font-bold text-pink-800",children:"Last Alert Details"})]}),e.jsx("button",{onClick:()=>h(!1),className:"p-1 rounded hover:bg-pink-100",children:e.jsx(Ie,{size:12,className:"text-pink-400"})})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-3",children:[{label:"Bounce Rate",value:`${ee.bounce_rate}%`,color:"#be185d"},{label:"Threshold",value:`${ee.threshold}%`,color:"#6b7280"},{label:"Sent (30d)",value:ee.total_sent_30d,color:"#059669"},{label:"Bounced (30d)",value:ee.total_bounced_30d,color:"#dc2626"},{label:"Hard Bounces",value:ee.hard_bounces,color:"#dc2626"},{label:"Soft Bounces",value:ee.soft_bounces,color:"#d97706"},{label:"Complaints",value:ee.complaints,color:"#7c3aed"},{label:"Unique Emails",value:ee.unique_bounced_emails,color:"#be185d"}].map((u,V)=>e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white border border-pink-100",children:[e.jsx("p",{className:"font-mono text-sm font-bold",style:{color:u.color},children:u.value}),e.jsx("p",{className:"text-[8px] font-semibold text-gray-500 uppercase",children:u.label})]},V))}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-gray-500",children:[e.jsxs("span",{children:["Batch: ",e.jsxs("code",{className:"font-mono text-gray-600",children:[(Ne=ee.batch_id)==null?void 0:Ne.slice(0,20),"..."]})]}),e.jsxs("span",{children:["Day: ",ee.reminder_day]}),e.jsxs("span",{children:["Alerted: ",ee.alerted_at?new Date(ee.alerted_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"—"]})]})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 overflow-hidden",children:[e.jsxs("button",{onClick:()=>L(!T),className:"w-full px-5 py-3 flex items-center justify-between bg-gray-50 hover:bg-gray-100 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{size:14,className:"text-pink-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Bounced Recipients (30-Day)"}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[9px] font-bold bg-pink-100 text-pink-700",children:de.length})]}),T?e.jsx(Le,{size:14,className:"text-gray-400"}):e.jsx(Fe,{size:14,className:"text-gray-400"})]}),T&&e.jsx("div",{className:"max-h-80 overflow-y-auto",children:de.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-400",children:[e.jsx(le,{size:24,className:"mx-auto mb-2 text-emerald-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No bounced emails in the last 30 days"})]}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50 border-b border-gray-100",children:[e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-500",children:"Student"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Email"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Program"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500",children:"Type"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Reason"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-500",children:"Bounced At"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:de.map(u=>{var V;return e.jsxs("tr",{className:"hover:bg-pink-50/30",children:[e.jsx("td",{className:"px-4 py-2 font-medium text-gray-900",children:u.student_name}),e.jsx("td",{className:"px-3 py-2 font-mono text-[10px] text-gray-500",children:u.student_email||"—"}),e.jsx("td",{className:"px-3 py-2 text-gray-600",children:u.program_name||"—"}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold ${u.bounce_type==="hard"?"bg-red-50 text-red-700":u.bounce_type==="complaint"?"bg-purple-50 text-purple-700":"bg-amber-50 text-amber-700"}`,children:u.bounce_type==="complaint"?"Spam":u.bounce_type||"Unknown"})}),e.jsx("td",{className:"px-3 py-2 text-gray-500 max-w-[200px] truncate",title:u.bounce_reason||"",children:((V=u.bounce_reason)==null?void 0:V.slice(0,60))||"—"}),e.jsx("td",{className:"px-4 py-2 font-mono text-[10px] text-gray-500",children:u.bounced_at?new Date(u.bounced_at).toLocaleStr
12ing("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"—"})]},u.id)})})]})})]}),e.jsxs("div",{className:`rounded-xl border-2 p-5 ${c?"border-red-200 bg-red-50/30":"border-emerald-200 bg-emerald-50/20"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[c?e.jsx(dt,{size:14,className:"text-red-600"}):e.jsx(le,{size:14,className:"text-emerald-600"}),e.jsx("span",{className:`text-xs font-bold ${c?"text-red-800":"text-emerald-800"}`,children:c?"Recommended Actions — Bounce Rate Above Threshold":"Email Deliverability Healthy"})]}),c?e.jsx("div",{className:"space-y-2",children:[{num:1,title:"Verify Email Addresses",desc:"Cross-reference bounced emails with student records. Remove or correct invalid addresses."},{num:2,title:"Check DNS Records",desc:"Ensure SPF, DKIM, and DMARC records are correctly configured for the sending domain."},{num:3,title:"Review Sender Reputation",desc:"Check Mailgun dashboard for reputation scores. Rates above 5% can result in domain blacklisting."},{num:4,title:"Suppress Hard Bounces",desc:"Add hard-bounced emails to a suppression list to prevent repeated delivery attempts."},{num:5,title:"Contact Students Directly",desc:"For students with bounced emails, reach out via phone to obtain valid email addresses."}].map(u=>e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[9px] font-bold text-white shrink-0 bg-red-600",children:u.num}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-gray-800",children:u.title}),e.jsx("p",{className:"text-[10px] text-gray-600",children:u.desc})]})]},u.num))}):e.jsxs("p",{className:"text-xs text-gray-600",children:["Your 30-day bounce rate of ",e.jsxs("strong",{children:[ie,"%"]})," is below the ",e.jsxs("strong",{children:[se,"%"]})," threshold. No immediate action required. The system will automatically alert the admin if the rate exceeds the threshold after any batch run."]})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-gray-50/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ee,{size:12,className:"text-gray-400"}),e.jsx("span",{className:"text-[10px] font-bold text-gray-600",children:"How Bounce Rate Alerts Work"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-3 text-[10px] text-gray-500",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded-full flex items-center justify-center text-[8px] font-bold text-white shrink-0",style:{backgroundColor:Je},children:"1"}),e.jsx("span",{children:"After each compliance batch run, the edge function queries the last 30 days of email logs"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded-full flex items-center justify-center text-[8px] font-bold text-white shrink-0",style:{backgroundColor:Je},children:"2"}),e.jsx("span",{children:"It calculates: bounced / (sent + bounced) as the rolling bounce rate"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded-full flex items-center justify-center text-[8px] font-bold text-white shrink-0",style:{backgroundColor:Je},children:"3"}),e.jsx("span",{children:"If rate exceeds the threshold, a formatted alert email is sent to the admin with bounced recipients and recommended actions"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"w-4 h-4 rounded-full flex items-center justify-center text-[8px] font-bold text-white shrink-0",style:{backgroundColor:Je},children:"4"}),e.jsx("span",{children:"A 24-hour cooldown prevents alert spam — only one alert per day even if the rate stays above threshold"})]})]})]})]}),e.jsx(oa,{open:k,onClose:()=>B(!1)}),e.jsx(ca,{})]})},jt="#6B1D3A",Lt={1:{color:jt,bgColor:`${jt}08`,borderColor:`${jt}20`,label:"Upcoming Payment"},8:{color:"#d97706",bgColor:"#fffbeb",borderColor:"#f59e0b30",label:"Payment Warning"},11:{color:"#dc2626",bgColor:"#fef2f2",borderColor:"#dc262630",label:"Final Notice + Late Fee"}};function ma(n){const v=new Date,m=n.getTime()-v.getTime();if(m<=0)return"Now";const f=Math.floor(m/(1e3*60*60*24)),t=Math.floor(m%(1e3*60*60*24)/(1e3*60*60));if(f>0)return`${f}d ${t}h`;const N=Math.floor(m%(1e3*60*60)/(1e3*60));return t>0?`${t}h ${N}m`:`${N}m`}const pa=()=>{const[n,v]=r.useState(!1),[m,f]=r.useState(null),t="https://tojqzezdtojnxquphifh.databasepad.com/functions/v1/auto-compl
12iance-reminders",N="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY2ZDg4NjE3LWYyMWUtNGY3OC1hN2Q2LWZkOTlmMGMxZjNiMyJ9.eyJwcm9qZWN0SWQiOiJ0b2pxemV6ZHRvam54cXVwaGlmaCIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNzc0OTA2NzUwLCJleHAiOjIwOTAyNjY3NTAsImlzcyI6ImZhbW91cy5kYXRhYmFzZXBhZCIsImF1ZCI6ImZhbW91cy5jbGllbnRzIn0.ZPMChrZXp0qUEzvJSqCQnvcQ-DCZiIFFkVKUw2YzZXA",S="0 16 1,8,11 * *",z=`curl -X POST '${t}' \\
13  -H 'Content-Type: application/json' \\
14  -H 'Authorization: Bearer ${N}' \\
15  -d '{}'`,l=(a,d)=>{navigator.clipboard.writeText(a).then(()=>{f(d),setTimeout(()=>f(null),2e3)})},A=({text:a,field:d,label:k})=>e.jsxs("button",{onClick:()=>l(a,d),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-semibold transition-all ${m===d?"bg-emerald-50 text-emerald-700 border border-emerald-200":"bg-gray-50 text-gray-600 border border-gray-200 hover:bg-gray-100 hover:text-gray-800"}`,children:[m===d?e.jsx(Wt,{size:11}):e.jsx(Yt,{size:11}),m===d?"Copied!":k||"Copy"]}),y=(()=>{const a=[],d=new Date;let k=d.getMonth(),B=d.getFullYear();const _=[1,8,11];for(;a.length<3;){for(const P of _){const J=new Date(B,k,P,8,0,0);if(J>d&&(a.push({date:J,day:P}),a.length>=3))break}k++,k>11&&(k=0,B++)}return a})();return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{backgroundColor:"#eef2ff"},children:e.jsx(Zt,{size:18,className:"text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Cron Webhook Configuration"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"External cron service setup for automatic execution at 8:00 AM PST"})]})]}),e.jsxs("button",{onClick:()=>v(!n),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-indigo-200 text-indigo-600 hover:bg-indigo-50 transition-colors",children:[n?e.jsx(Le,{size:12}):e.jsx(Fe,{size:12}),n?"Hide Details":"Show Configuration"]})]}),e.jsx("div",{className:"px-6 py-3 bg-gradient-to-r from-indigo-50/50 to-purple-50/50 border-b border-gray-100",children:e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-indigo-500"}),e.jsx("span",{className:"text-[10px] font-bold text-indigo-700",children:"CRON"}),e.jsx("code",{className:"px-2 py-0.5 rounded bg-white border border-indigo-200 text-[10px] font-mono text-indigo-800 font-bold",children:S})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-gray-500",children:[e.jsx(ke,{size:10}),e.jsx("span",{children:"8:00 AM PST on the 1st, 8th & 11th of every month"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto",children:[e.jsx("span",{className:"text-[10px] text-gray-400",children:"Next:"}),y.map((a,d)=>{var k,B;return e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold",style:{backgroundColor:((k=Lt[a.day])==null?void 0:k.bgColor)||"#f3f4f6",color:((B=Lt[a.day])==null?void 0:B.color)||"#6b7280"},children:a.date.toLocaleDateString("en-US",{month:"short",day:"numeric"})},d)})]})]})}),n&&e.jsxs("div",{className:"p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Us,{size:13,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Webhook URL"}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-blue-50 text-blue-700",children:"POST"})]}),e.jsx(A,{text:t,field:"url",label:"Copy URL"})]}),e.jsx("div",{className:"bg-gray-900 rounded-lg px-4 py-3 overflow-x-auto",children:e.jsx("code",{className:"text-[11px] font-mono text-emerald-400 break-all select-all",children:t})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{size:13,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Required Headers"})]}),e.jsx(A,{text:`Content-Type: application/json
16Authorization: Bearer ${N}`,field:"headers",label:"Copy Headers"})]}),e.jsxs("div",{className:"bg-gray-900 rounded-lg px-4 py-3 space-y-1.5 overflow-x-auto",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono text-gray-500 shrink-0",children:"Content-Type:"}),e.jsx("span",{className:"text-[11px] font-mono text-amber-400",children:"application/json"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono text-gray-500 shrink-0",children:"Authorization:"}),e.jsxs("span",{className:"text-[11px] font-mono text-amber-400 break-all",children:["Bearer ",N.slice(0,40),"...",N.slice(-20)]})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx(A,{text:`Bearer ${N}`,field:"auth-header",label:"Copy Full Auth Header"}),e.jsx(A,{text:N,field:"anon-key",label:"Copy API Key Only"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ks,{size:13,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Request Body"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"(empty JSON object)"})]}),e.jsx(A,{text:"{}",field:"body",label:"Copy Body"})]}),e.jsx("div",{className:"bg-gray-900 rounded-lg px-4 py-3",children:e.jsx("code",{className:"text-[11px] font-mono text-purple-400",children:"{}"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qt,{size:13,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Cron Expression"})]}),e.jsx(A,{text:S,field:"cron",label:"Copy Cron"})]}),e.jsxs("div",{className:"bg-gray-900 rounded-lg px-4 py-3 flex items-center gap-4",children:[e.jsx("code",{className:"text-lg font-mono text-cyan-400 font-bold",children:S}),e.jsxs("div",{className:"text-[10px] text-gray-400 space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-mono text-gray-500 w-4",children:"0"}),e.jsx("span",{children:"= minute 0"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-mono text-gray-500 w-4",children:"16"}),e.jsx("span",{children:"= 4:00 PM UTC (8:00 AM PST)"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-mono text-gray-500 w-12",children:"1,8,11"}),e.jsx("span",{children:"= 1st, 8th & 11th day of month"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-mono text-gray-500 w-4",children:"*"}),e.jsx("span",{children:"= every month, every day of week"})]})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vs,{size:13,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"cURL Command"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:"(test from terminal)"})]}),e.jsx(A,{text:z.replace(/\\\n\s*/g," "),field:"curl",label:"Copy cURL"})]}),e.jsx("div",{className:"bg-gray-900 rounded-lg px-4 py-3 overflow-x-auto",children:e.jsx("pre",{className:"text-[10px] font-mono text-green-400 whitespace-pre-wrap",children:z})})]}),e.jsxs("div",{className:"rounded-xl border-2 border-indigo-100 bg-indigo-50/30 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(vt,{size:14,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-indigo-800",children:"Exter
16nal Cron Setup (cron-job.org)"})]}),e.jsxs("ol",{className:"space-y-2.5 text-xs text-gray-700",children:[[e.jsxs(e.Fragment,{children:["Go to ",e.jsx("a",{href:"https://cron-job.org",target:"_blank",rel:"noopener noreferrer",className:"text-indigo-600 font-semibold underline hover:text-indigo-800",children:"cron-job.org"})," and create a free account"]}),e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:'"Create Cronjob"'})," and paste the Webhook URL above"]}),e.jsxs(e.Fragment,{children:["Set ",e.jsx("strong",{children:"Request Method"})," to ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-white text-[10px] font-mono border",children:"POST"})]}),e.jsxs(e.Fragment,{children:["Under ",e.jsx("strong",{children:'"Advanced"'})," → ",e.jsx("strong",{children:'"Headers"'}),", add both required headers (Content-Type and Authorization)"]}),e.jsxs(e.Fragment,{children:["Set ",e.jsx("strong",{children:"Request Body"})," to ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-white text-[10px] font-mono border",children:"{}"})]}),e.jsxs(e.Fragment,{children:["Set ",e.jsx("strong",{children:"Schedule"})," to ",e.jsx("strong",{children:'"Custom"'})," and enter: ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-white text-[10px] font-mono border font-bold",children:S})]}),e.jsxs(e.Fragment,{children:["Set ",e.jsx("strong",{children:"Timezone"})," to ",e.jsx("strong",{children:"UTC"})," (the cron expression already accounts for PST conversion)"]})].map((a,d)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-bold text-white shrink-0",style:{backgroundColor:jt},children:d+1}),e.jsx("span",{children:a})]},d)),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] font-bold text-white shrink-0 bg-emerald-600",children:"8"}),e.jsxs("span",{children:["Click ",e.jsx("strong",{children:'"Create"'})," — the cron job will automatically call the edge function on schedule"]})]})]}),e.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-white border border-indigo-100",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ee,{size:12,className:"text-indigo-500"}),e.jsx("span",{className:"text-[10px] font-bold text-indigo-700",children:"Duplicate Prevention Built-In"})]}),e.jsx("p",{className:"text-[10px] text-gray-600",children:'The edge function automatically prevents duplicate runs on the same day. If the cron fires multiple times, only the first execution will process reminders. Subsequent calls will be logged as "skipped_already_ran" in the Cron Log.'})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(st,{size:13,className:"text-indigo-600"}),e.jsx("span",{className:"text-xs font-bold text-gray-800",children:"Upcoming Scheduled Runs"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:y.map((a,d)=>{const k=Lt[a.day];return e.jsxs("div",{className:"rounded-lg border p-3 text-center",style:{borderColor:k==null?void 0:k.borderColor,backgroundColor:k==null?void 0:k.bgColor},children:[e.jsx("p",{className:"text-lg font-bold font-mono",style:{color:k==null?void 0:k.color},children:a.date.toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx("p",{className:"text-[10px] font-semibold",style:{color:k==null?void 0:k.color},children:k==null?void 0:k.label}),e.jsx("p",{className:"text-[9px] text-gray-400 mt-1",children:"8:00 AM PST"}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-center gap-1",children:[e.jsx(ke,{size:9,className:"text-gray-400"}),e.jsx("span",{className:"text-[9px] font-mono text-gray-500",children:ma(a.date)})]})]},d)})})]})]})]})},gs="#6B1D3A",ha="#4A1228",Ft="#C5A572",bs="#D4BA8A",It="#A68B5B",ua=({showRunModal:n,setShowRunModal:v,isRunning:m,runComplete:f,runSummary:t,setRunComplete:N,setRunSummary:S,runProgress:z,urgencyConfig:l,effectiveDay:A,runComplianceReminders:o})=>n?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:()=>{m||(v(!1),N(!1),S(null))},children:[e.jsx("div",{className:"absolute inset-0 bg-black/30 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-white rounded-2xl shadow-2xl w-full max-w-lg overflow-hidden",onClick:y=>y.stopPropagation(),children:[e.jsx("div",{className:"h-1",style:{background:`linear-gradient(90deg, ${It}, ${bs}, ${It})`}}),f&&t?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center py-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full flex items-center justify-center mb-4",style:{backgroundColor:"#d1fae5"},children:e.jsx(le,{size:32,className:"text-emerald-600"})}),e.jsx("h3",{className:"text-xl font-bold text-gray-900 mb-1",children:"Compliance Run Complete"}),e.jsxs("p",{className:"text-sm text-gray-500 mb-6",children:["Batch: ",t.batchId.slice(0,20),"..."]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 w-full mb-6",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-emerald-50 border border-emerald-200 text-center",children:[e.jsx("p",{className:"font-mono text-2xl font-bold text-emerald-700",children:t.sent}),e.jsx("p",{className:"text-[10px] font-semibold text-emerald-600 uppercase",children:"Emails Sent"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-red-50 border border-red-200 text-center",children:[e.jsx("p",{className:"font-mono text-2xl font-bold text-red-700",children:t.failed}),e.jsx("p",{className:"text-[10px] font-semibold text-red-600 uppercase",children:"Failed"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-gray-50 border border-gray-200 text-center",children:[e.jsx("p",{className:"font-mono text-2xl font-bold text-gray-700",children:t.skipped}),e.jsx("p",{className:"text-[10px] font-semibold text-gray-600 uppercase",children:"Skipped"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-amber-50 border border-amber-200 text-center",children:[e.jsx("p",{className:"font-mono text-2xl font-bold text-amber-700",children:t.lateFees}),e.jsx("p",{className:"text-[10px] font-semibold text-amber-600 uppercase",children:"Late Fees Applied"})]})]}),e.jsx("button",{onClick:()=>{v(!1),N(!1),S(null)},className:"w-full px-4 py-2.5 rounded-lg text-sm font-semibold text-white",style:{background:`linear-gradient(135deg, ${gs}, ${ha})`},children:"Close"})]})}):m?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex flex-col items-center py-4",children:[e.jsx(X,{size:40,className:"animate-spin mb
16-4",style:{color:Ft}}),e.jsx("h3",{className:"text-lg font-bold text-gray-900 mb-1",children:"Sending Compliance Reminders..."}),e.jsxs("p",{className:"text-sm text-gray-500 mb-6",children:["Processing ",z.current," of ",z.total," students"]}),e.jsx("div",{className:"w-full h-3 bg-gray-100 rounded-full overflow-hidden mb-4",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${z.total>0?z.current/z.total*100:0}%`,background:`linear-gradient(90deg, ${Ft}, ${bs})`}})}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 w-full",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-emerald-600",children:z.sent}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Sent"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-red-600",children:z.failed}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Failed"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-gray-500",children:z.skipped}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Skipped"})]})]})]})}):e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-bold",style:{color:gs},children:"Run Compliance Reminders"}),e.jsx("button",{onClick:()=>v(!1),className:"p-2 rounded-lg hover:bg-gray-100 text-gray-400",children:e.jsx(Ie,{size:18})})]}),e.jsxs("div",{className:"p-4 rounded-xl border-2 mb-4",style:{backgroundColor:l.bgColor,borderColor:l.borderColor},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{style:{color:l.color},children:l.icon}),e.jsx("span",{className:"text-sm font-bold",style:{color:l.color},children:l.label})]}),e.jsx("p",{className:"text-xs text-gray-600",children:l.description})]}),e.jsxs("div",{className:"space-y-3 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600",children:[e.jsx(le,{size:14,className:"text-emerald-500 shrink-0"}),e.jsxs("span",{children:["Query all students with outstanding balances from ",e.jsx("strong",{children:"financial_ledger"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600",children:[e.jsx(le,{size:14,className:"text-emerald-500 shrink-0"}),e.jsxs("span",{children:["Query active Z Bank loans with remaining balances from ",e.jsx("strong",{children:"z_bank_loans"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600",children:[e.jsx(le,{size:14,className:"text-emerald-500 shrink-0"}),e.jsxs("span",{children:["Send ",e.jsx("strong",{children:"payment-reminder"})," emails via Mailgun API (",l.level," urgency)"]})]}),A===11&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-red-600 font-semibold",children:[e.jsx(ce,{size:14,className:"text-red-500 shrink-0"}),e.jsxs("span",{children:["Auto-apply ",e.jsx("strong",{children:"$25 late fee"})," to Z Bank loans (z_bank_payments)"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-600",children:[e.jsx(le,{size:14,className:"text-emerald-500 shrink-0"}),e.jsxs("span",{children:["Log all results to ",e.jsx("strong",{children:"compliance_email_log"})," table"]})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 px-4 py-2.5 border border-gray-200 rounded-lg text-sm font-medium text-gray-600 hover:bg-gray-50",children:"Cancel"}),e.jsxs("button",{onClick:o,className:"flex-1 px-4 py-2.5 text-white rounded-lg text-sm font-bold shadow-md hover:opacity-90 transition-all flex items-center justify-center gap-2",style:{background:`linear-gradient(135deg, ${Ft}, ${It})`},children:[e.jsx(Os,{size:16})," Run Now"]})]})]})]})]}):null,Bt="#6B1D3A",ga="#4A1228",ba="#C5A572",fa="#D4BA8A",fs="#A68B5B",Pt="net_price_calculator",ya=()=>{const[n,v]=r.useState([]),[m,f]=r.useState(!0),[t,N]=r.useState(!1),[S,z]=r.useState(null),l=r.useCallback(async()=>{f(!0);const{data:d,error:k}=await D.from("link_monitor_logs").select("*").order("checked_at",{ascending:!1}).limit(200);if(!k&&d){const B=new Set,_=[];for(const P of d)B.has(P.policy_key)||(B.add(P.policy_key),_.push(P));v(_)}f(!1)},[]);r.useEffect(()=>{l()},[l]);const A=async()=>{N(!0),z(null);try{const{data:d,error:k}=await D.functions.invoke("compliance-link-monitor",{body:{}});k?z(typeof k=="string"?k:(k==null?void 0:k.message)||"Scan failed"):d&&d.success===!1&&z(d.error||"Scan reported a failure"),await l()}catch(d){z((d==null?void 0:d.message)||"Network error")}N(!1)},o=r.useMemo(()=>n.filter(d=>!d.ok),[n]),y=r.useMemo(()=>n.find(d=>d.policy_key===Pt),[n]),a=r.useMemo(()=>n.length===0?null:n.reduce((d,k)=>new Date(k.checked_at)>new Date(d)?k.checked_at:d,n[0].checked_at),[n]);return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex flex-col md:flex-row md:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{backgroundColor:`${Bt}10`},children:e.jsx(rs,{size:18,style:{color:Bt}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Official Link Health Monitor"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Automated checks (every 6 hours) verify federal & compliance destinations return HTTP 200"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsxs("span",{className:"hidden md:inline-flex items-center gap-1 text-[10px] font-mono text-gray-400",children:[e.jsx(ke,{size:11}
16)," ",new Date(a).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})]}),e.jsxs("button",{onClick:A,disabled:t,className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-[10px] font-bold text-white transition-all disabled:opacity-50 hover:opacity-90",style:{background:`linear-gradient(135deg, ${Bt}, ${ga})`},children:[t?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(et,{size:12}),"Run Link Check Now"]}),e.jsxs("button",{onClick:l,disabled:m,className:"flex items-center gap-1 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-gray-200 text-gray-600 hover:bg-gray-50 disabled:opacity-50",children:[e.jsx(Se,{size:12})," Refresh"]})]})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[S&&e.jsx("div",{className:"px-4 py-3 rounded-lg bg-red-50 border border-red-200 text-xs text-red-700 font-medium",children:S}),o.length>0&&e.jsxs("div",{className:"rounded-xl border-2 border-red-300 bg-red-50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ce,{size:18,className:"text-red-600"}),e.jsxs("span",{className:"text-sm font-bold text-red-700",children:[o.length," Broken Official Link",o.length!==1?"s":""," Detected"]})]}),e.jsx("p",{className:"text-xs text-red-600 mb-3",children:"One or more required compliance destinations are not returning HTTP 200. Staff should verify and update these URLs — a moved federal page can create a regulatory disclosure gap."}),e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsxs("div",{className:"flex items-start justify-between gap-3 px-3 py-2 rounded-lg bg-white border border-red-200",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(os,{size:13,className:"text-red-500 shrink-0"}),e.jsx("span",{className:"text-xs font-bold text-gray-900 truncate",children:d.label}),d.policy_key===Pt&&e.jsx("span",{className:"px-1.5 py-px rounded text-[8px] font-bold bg-red-100 text-red-700",children:"FEDERAL"})]}),e.jsx("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] font-mono text-red-500 hover:underline break-all",children:d.url}),d.error&&e.jsx("p",{className:"text-[10px] text-red-600 mt-0.5",children:d.error})]}),e.jsx("span",{className:"shrink-0 px-2 py-0.5 rounded-full text-[10px] font-bold bg-red-100 text-red-700 font-mono",children:d.status_code??"ERR"})]},d.policy_key))})]}),o.length===0&&y&&e.jsx("div",{className:"rounded-xl border-2 p-4",style:{borderColor:y.ok?"#05966930":"#dc262630",backgroundColor:y.ok?"#f0fdf4":"#fef2f2"},children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(tt,{size:20,className:y.ok?"text-emerald-600":"text-red-600"}),e.jsxs("div",{children:[e.jsxs("p",{className:`text-sm font-bold ${y.ok?"text-emerald-700":"text-red-700"}`,children:["Federal Net Price Calculator — ",y.ok?"Online (HTTP 200)":"Needs Attention"]}),e.jsxs("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] font-mono text-gray-500 hover:underline inline-flex items-center gap-1",children:[y.url," ",e.jsx(vt,{size:9})]})]})]}),y.response_ms!=null&&e.jsxs("span",{className:"text-[10px] font-mono text-gray-400",children:[y.response_ms," ms"]})]})}),m?e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(X,{size:22,className:"animate-spin",style:{color:ba}})}):n.length===0?e.jsxs("div",{className:"flex flex-col items-center py-10 text-gray-400",children:[e.jsx(rs,{size:32,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium text-gray-500",children:"No link checks recorded yet"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:'Click "Run Link Check Now" to perform the first scan.'})]}):e.jsx("div",{className:"overflow-x-auto rounded-lg border border-gray-100",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50 border-b border-gray-100",children:[e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"Destination"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"URL"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500 uppercase tracking-wider",children:"HTTP"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500 uppercase tracking-wider",children:"Latency"}),e.jsx("th",{className:"px-4 py-2 text-center font-semibold text-gray-500 uppercase tracking-wider",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"Checked"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:n.map(d=>e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-gray-900",children:d.label}),d.policy_key===Pt&&e.jsx("span",{className:"px-1.5 py-px rounded text-[8px] font-bold bg-amber-50 text-amber-700 border border-amber-200",children:"FEDERAL"})]})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",className:"font-mono text-[10px] text-gray-500 hover:underline inline-flex items-center gap-1",children:[d.url.replace(/^https?:\/\//,"")," ",e.jsx(vt,{size:9})]})}),e.jsx("td",{className:"px-3 py-2.5 text-center font-mono font-bold",style:{color:d.ok?"#059669":"#dc2626"},children:d.status_code??"—"}),e.jsx("td",{className:"px-3 py-2.5 text-center font-mono text-gray-500",children:d.response_ms!=null?`${d.response_ms}ms`:"—"}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("div",{className:"flex justify-center",children:d.ok?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-emerald-50 text-emerald-700",children:[e.jsx(le,{size:10})," Healthy"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-red-50 text-red-700 border border-red-200",title:d.error||"",children:[e.jsx(os,{size:10})," Broken"]})})}),e.jsx("td",{className:"px-4 py-2.5 font-mono text-[10px] text-gray-500",children:new Date(d.checked_at).toLocaleStr
16ing("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})})]},d.policy_key))})]})})]}),e.jsx("div",{className:"h-1",style:{background:`linear-gradient(90deg, ${fs}, ${fa}, ${fs})`}})]})},oe="#6B1D3A",Ut="#4A1228",ye="#C5A572",ot="#D4BA8A",Xe="#A68B5B";function Ot(n){return"$"+(n/100).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}const Ae={1:{level:"upcoming",label:"Upcoming Payment",color:oe,bgColor:`${oe}08`,borderColor:`${oe}20`,icon:e.jsx(st,{size:14}),description:"1st of month — Friendly upcoming payment reminder"},8:{level:"warning",label:"Payment Warning",color:"#d97706",bgColor:"#fffbeb",borderColor:"#f59e0b30",icon:e.jsx(ce,{size:14}),description:"8th of month — Payment due in 2 days warning"},11:{level:"final-notice",label:"Final Notice + Late Fee",color:"#dc2626",bgColor:"#fef2f2",borderColor:"#dc262630",icon:e.jsx(dt,{size:14}),description:"11th of month — Final notice with $25 late fee applied to Z Bank loans"}};function ja(n){const v=new Date,m=v.getDate(),f=v.getMonth(),t=v.getFullYear(),N=[...n].sort((o,y)=>o-y);for(const o of N)if(o>m){const y=new Date(t,f,o),a=Ae[o];return{date:y,day:o,urgency:(a==null?void 0:a.level)||"upcoming",label:(a==null?void 0:a.label)||"Reminder"}}const S=f+1,z=N[0],l=new Date(t,S,z),A=Ae[z];return{date:l,day:z,urgency:(A==null?void 0:A.level)||"upcoming",label:(A==null?void 0:A.label)||"Reminder"}}function Na(n){const v=new Date,m=n.getTime()-v.getTime();if(m<=0)return"Now";const f=Math.floor(m/(1e3*60*60*24)),t=Math.floor(m%(1e3*60*60*24)/(1e3*60*60));if(f>0)return`${f}d ${t}h`;const N=Math.floor(m%(1e3*60*60)/(1e3*60));return t>0?`${t}h ${N}m`:`${N}m`}const va=()=>{var Jt,Xt;const{students:n,loading:v}=Gs(),{programs:m,loading:f}=Ws(),[t,N]=r.useState([]),[S,z]=r.useState(!0),[l,A]=r.useState(null),[o,y]=r.useState(null),[a,d]=r.useState(!0),[k,B]=r.useState(!1),[_,P]=r.useState([]),[J,Y]=r.useState(!0),[i,Q]=r.useState(!1),[g,x]=r.useState(!1),[w,M]=r.useState(null),[T,L]=r.useState(!1),[I,h]=r.useState({current:0,total:0,sent:0,failed:0,skipped:0}),[O,q]=r.useState(!1),[ue,U]=r.useState(!1),[b,$]=r.useState(null),[H,ne]=r.useState(null),[ae,re]=r.useState(!1),[Z,ie]=r.useState("all"),se=H||new Date().getDate(),c=s=>{var j;return((j=n.find(E=>E.id===s))==null?void 0:j.name)||s},R=s=>{var j;return((j=n.find(E=>E.id===s))==null?void 0:j.email)||""},G=s=>{var j;return((j=m.find(E=>E.id===s))==null?void 0:j.name)||s},F=r.useCallback(async()=>{z(!0);const{data:s,error:j}=await D.from("compliance_email_log").select("*").order("created_at",{ascending:!1}).limit(500);!j&&s&&N(s),z(!1)},[]),C=r.useCallback(async()=>{d(!0);const{data:s,error:j}=await D.from("compliance_auto_schedule").select("*").limit(1).single();!j&&s&&y(s),d(!1)},[]),de=r.useCallback(async()=>{Y(!0);const{data:s,error:j}=await D.from("compliance_cron_log").select("*").order("created_at",{ascending:!1}).limit(50);!j&&s&&P(s),Y(!1)},[]);r.useEffect(()=>{F(),C(),de()},[F,C,de]);const ge=nt.paymentReminders.includes(se),Me=r.useMemo(()=>{if(ge)return se;const s=[...nt.paymentReminders].sort((E,W)=>E-W),j=s.find(E=>E>se);return j||s[0]},[se,ge]),ee=Ae[Me]||Ae[1],Ne=r.useMemo(()=>ja(nt.paymentReminders),[]),u=r.useMemo(()=>t.filter(s=>s.email_status==="sent").length,[t]),V=r.useMemo(()=>t.filter(s=>s.email_status==="sent"&&(s.retry_count||0)>0).length,[t]),pe=r.useMemo(()=>t.filter(s=>s.email_status==="failed"||s.email_status==="failed_after_retries").length,[t]),me=r.useMemo(()=>t.filter(s=>s.email_status==="failed_after_retries").length,[t]),he=r.useMemo(()=>t.filter(s=>s.email_status==="bounced").length,[t]),Be=r.useMemo(()=>t.filter(s=>s.email_status==="bounced"&&s.bounce_type==="complaint").length,[t]),kt=r.useMemo(()=>t.filter(s=>s.email_status==="skipped").length,[t]),at=r.useMemo(()=>t.filter(s=>s.late_fee_applied).reduce((s,j)=>s+(j.late_fee_amount||0),0),[t]),Pe=r.useMemo(()=>t.reduce((s,j)=>s+(j.retry_count||0),0),[t]),Ue=r.useMemo(()=>{const s=u+he;return s>0?(he/s*100).toFixed(1):"0.0"},[u,he]),qe=r.useMemo(()=>Z==="all"?t:Z==="bounced"?t.filter(s=>s.email_status==="bounced"):Z==="failed"?t.filter(s=>s.email_status==="failed"||s.email_status==="failed_after_retries"):t.filter(s=>s.email_status===Z),[t,Z]),ct=r.useMemo(()=>{const s=new Map;for(const j of qe){const E=j.batch_id||`no_batch_${j.id}`;s.has(E)||s.set(E,[]),s.get(E).push(j)}return Array.from(s.entries()).sort((j,E)=>{const W=new Date(j[1][0].created_at).getTime();return new Date(E[1][0].created_at).getTime()-W})},[qe]),St=async()=>
16{if(!o)return;B(!0);const s=!o.enabled,{error:j}=await D.from("compliance_auto_schedule").update({enabled:s,updated_at:new Date().toISOString()}).eq("id",o.id);j||y({...o,enabled:s}),B(!1)},xt=async(s=!1)=>{x(!0),M(null);try{const{data:j,error:E}=await D.functions.invoke("auto-compliance-reminders",{body:{force:s,overrideDay:H||void 0,triggerType:s?"manual-force":"manual-test"}});if(E){const W=typeof E=="string"?E:(E==null?void 0:E.message)||JSON.stringify(E);M({success:!1,error:W})}else typeof j=="string"?M({success:!1,error:j.slice(0,300)}):j&&typeof j=="object"?(M(j),C(),de(),F()):M({success:!1,error:"Unexpected response from edge function"})}catch(j){M({success:!1,error:j.message||"Network error"})}x(!1)},mt=async()=>{L(!0),U(!1),$(null),h({current:0,total:0,sent:0,failed:0,skipped:0});const s=`batch_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,j=Me,E=Ae[j]||Ae[1];try{const{data:W}=await D.from("financial_ledger").select("*"),{data:xe}=await D.from("financial_payments").select("*"),{data:ze}=await D.from("z_bank_loans").select("*").eq("status","active"),{data:pt}=await D.from("z_bank_payments").select("*"),Te=[];if(W)for(const K of W){const p=K.total_tuition+K.kit_fee+K.registration_fee,Oe=(xe||[]).filter(_e=>_e.ledger_id===K.id).reduce((_e,Ke)=>_e+Ke.amount,0),we=p-Oe;if(we>0){const _e=R(K.student_id);_e&&Te.push({studentId:K.student_id,studentName:c(K.student_id),studentEmail:_e,programId:K.program_id,programName:G(K.program_id),source:"ledger",outstandingBalance:we,fundingSource:K.funding_source})}}if(ze){for(const K of ze)if(K.remaining_balance>0){const p=R(K.student_id);p&&(Te.find(we=>we.studentId===K.student_id&&we.source==="z-bank")||Te.push({studentId:K.student_id,studentName:c(K.student_id),studentEmail:p,programId:K.program_id,programName:G(K.program_id),source:"z-bank",outstandingBalance:K.remaining_balance,monthlyPayment:K.monthly_payment}))}}h(K=>({...K,total:Te.length}));let rt=0,ve=0,lt=0,ht=0;for(let K=0;K<Te.length;K++){const p=Te[K];if(h(te=>({...te,current:K+1})),!p.studentEmail){lt++,await D.from("compliance_email_log").insert({student_id:p.studentId,student_name:p.studentName,student_email:null,program_id:p.programId,program_name:p.programName,email_type:"payment-reminder",urgency_level:E.level,reminder_day:j,source:p.source,outstanding_balance:p.outstandingBalance,late_fee_applied:!1,late_fee_amount:0,email_status:"skipped",error_message:"No email address on file",batch_id:s}),h(te=>({...te,skipped:te.skipped+1}));continue}let Oe=!1,we=0;if(j===11&&p.source==="z-bank"&&ze){const te=ze.find(Ze=>Ze.student_id===p.studentId&&Ze.status==="active");if(te){const Ze=new Date,Ct=new Date(Ze.getFullYear(),Ze.getMonth(),1).toISOString().split("T")[0];if(!(pt||[]).find(fe=>fe.loan_id===te.id&&fe.late_fee_applied===!0&&fe.payment_date>=Ct)){we=$t.lateFeeAmount;const fe=new Date,Cs=new Date(fe.getFullYear(),fe.getMonth(),$t.paymentDueDay);await D.from("z_bank_payments").insert({loan_id:te.id,amount:0,payment_date:fe.toISOString().split("T")[0],due_date:Cs.toISOString().split("T")[0],status:"late",late_fee_applied:!0,nsf_fee_applied:!1,fee_amount:we,payment_method:null,notes:`Auto-applied $25 late fee — compliance reminder batch ${s}`}),await D.from("z_bank_loans").update({remaining_balance:te.remaining_balance+we,updated_at:new Date().toISOString()}).eq("id",te.id),Oe=!0,ht++}}}let _e="failed",Ke=null;try{const te=new Date,Ct=new Date(te.getFullYear(),te.getMonth(),$t.paymentDueDay).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),{data:He,error:fe}=await D.functions.invoke("send-financial-email",{body:{type:"payment-reminder",recipientEmail:p.studentEmail,data:{studentName:p.studentName,programName:p.programName,remainingBalance:p.outstandingBalance+(Oe?we:0),dueDate:Ct,monthlyPayment:p.monthlyPayment||null,reminderDay:j,fundingSource:p.fundingSource||(p.source==="z-bank"?"Z Bank Loan":"Self-Pay")}}});fe?Ke=typeof fe=="string"?fe:fe.message||JSON.stringify(fe):He!=null&&He.success?_e="sent":Ke=(He==null?void 0:He.error)||"Unknown email error"}catch(te){Ke=te.message||"Exception during email send"}await D.from("compliance_email_log").insert({student_id:p.studentId,student_name:p.studentName,student_email:p.studentEmail,program_id:p.programId,program_name:p.programName,email_type:"payment-reminder",urgency_level:E.level,reminder_day:j,source:p.source,outstanding_balance:p.outstandingBalance,late_fee_applied:Oe,late_fee_amount:Oe?we:0,email_status:_e,error_message:Ke,batch_id:s,sent_at:_e==="sent"?new Date().toISOString():null}),_e==="sent"?(rt++,h(te=>({...te,sent:te.sent+1}))):(ve++,h(te=>({...te,failed:te.failed+1}))),await new Promise(te=>setTimeout(te,300))}$({sent:rt,failed:ve,skipped:lt,lateFees:ht,batchId:s}),U(!0),F()}catch(W){console.error("Compliance reminder run error:",W),$({sent:0,failed:0,skipped:0,lateFees:0,batchId:""}),U(!0)}finally{L(!1)}},Ss=()=>{const s=["Date,Student,Email,Program,Source,Urgency,Balance,Late Fee,Status,Error",...qe.map(xe=>
16[new Date(xe.created_at).toLocaleString(),xe.student_name,xe.student_email||"",xe.program_name||"",xe.source,xe.urgency_level,(xe.outstanding_balance/100).toFixed(2),xe.late_fee_applied?(xe.late_fee_amount/100).toFixed(2):"0",xe.email_status,xe.error_message||""].map(ze=>`"${ze}"`).join(","))].join(`
17`),j=new Blob([s],{type:"text/csv"}),E=URL.createObjectURL(j),W=document.createElement("a");W.href=E,W.download=`compliance_email_log_${new Date().toISOString().split("T")[0]}.csv`,W.click(),URL.revokeObjectURL(E)};return v||f?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24",children:[e.jsx(X,{size:40,className:"animate-spin mb-4",style:{color:ye}}),e.jsx("p",{className:"text-gray-500 font-medium",children:"Loading compliance data..."})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden shadow-lg",style:{background:`linear-gradient(135deg, ${Ut}, ${oe})`},children:[e.jsx("div",{className:"h-1",style:{background:`linear-gradient(90deg, ${Xe}, ${ot}, ${Xe})`}}),e.jsxs("div",{className:"px-6 py-5 flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center shadow-lg",style:{background:`linear-gradient(135deg, ${ye}, ${Xe})`},children:e.jsx(We,{size:24,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:"Compliance Reminder Automation"}),e.jsx("p",{className:"text-sm",style:{color:ot},children:"Automated payment reminders on the 1st, 8th & 11th — Mailgun API"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>re(!ae),className:"flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-medium border text-white/80 hover:text-white transition-all",style:{borderColor:`${ye}40`},children:[e.jsx(st,{size:14})," Day: ",se,H&&e.jsx("span",{className:"text-[10px] opacity-70",children:"(override)"})]}),e.jsxs("button",{onClick:()=>q(!0),disabled:T,className:"flex items-center gap-2 px-5 py-2.5 rounded-lg text-sm font-bold text-white shadow-lg transition-all hover:opacity-90 disabled:opacity-50",style:{background:`linear-gradient(135deg, ${ye}, ${Xe})`},children:[T?e.jsx(X,{size:16,className:"animate-spin"}):e.jsx(Nt,{size:16}),"Run Compliance Reminders"]})]})]})]}),ae&&e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ee,{size:14,style:{color:ye}}),e.jsx("p",{className:"text-xs font-semibold text-gray-700",children:"Override Day of Month (for testing)"})]}),e.jsx("button",{onClick:()=>{ne(null),re(!1)},className:"text-xs text-gray-400 hover:text-gray-600",children:"Reset to today"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:nt.paymentReminders.map(s=>e.jsxs("button",{onClick:()=>{ne(s),re(!1)},className:`px-4 py-2 rounded-lg text-sm font-bold border-2 transition-all ${se===s?"text-white border-transparent":"border-gray-200 text-gray-600 hover:border-gray-300"}`,style:se===s?{backgroundColor:oe,borderColor:oe}:{},children:[s===1?"1st":s===8?"8th":"11th",e.jsx("span",{className:"block text-[9px] font-normal opacity-70 mt-0.5",children:s===1?"Upcoming":s===8?"Warning":"Final Notice"})]},s))})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{backgroundColor:`${oe}10`},children:e.jsx(Hs,{size:18,style:{color:oe}})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-gray-900",children:"Auto-Scheduler (Cron)"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Edge function runs automatically on the 1st, 8th & 11th"})]})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("button",{onClick:()=>Q(!i),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-gray-200 text-gray-600 hover:bg-gray-50 transition-colors",children:[e.jsx(ls,{size:12})," Cron Log"]})})]}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"rounded-xl border-2 p-5 transition-all",style:{borderColor:o!=null&&o.enabled?"#059669":"#e5e7eb",backgroundColor:o!=null&&o.enabled?"#f0fdf4":"#fafafa"},children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[o!=null&&o.enabled?e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-emerald-500 animate-pulse"}):e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-gray-300"}),e.jsx("span",{className:`text-sm font-bold ${o!=null&&o.enabled?"text-emerald-700":"text-gray-500"}`,children:o!=null&&o.enabled?"Auto-Schedule Active":"Auto-Schedule Disabled"})]})}),e.jsx("p",{className:"text-xs text-gray-500 mb-4",children:o!=null&&o.enabled?"The edge function will automatically process reminders on 
17scheduled days.":"Enable to allow the cron job to automatically send compliance reminders."}),e.jsx("button",{onClick:St,disabled:k||a,className:`w-full flex items-center justify-center gap-2 px-4 py-3 rounded-lg text-sm font-bold transition-all disabled:opacity-50 ${o!=null&&o.enabled?"bg-white border-2 border-emerald-300 text-emerald-700 hover:bg-emerald-50":"text-white shadow-md hover:opacity-90"}`,style:o!=null&&o.enabled?{}:{background:"linear-gradient(135deg, #059669, #047857)"},children:k?e.jsx(X,{size:16,className:"animate-spin"}):o!=null&&o.enabled?e.jsxs(e.Fragment,{children:[e.jsx(ns,{size:16})," Disable Auto-Schedule"]}):e.jsxs(e.Fragment,{children:[e.jsx(ns,{size:16})," Enable Auto-Schedule"]})})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 p-5 bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(qt,{size:16,style:{color:ye}}),e.jsx("span",{className:"text-xs font-bold text-gray-500 uppercase tracking-wider",children:"Next Scheduled Run"})]}),o!=null&&o.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-2",children:[e.jsx("p",{className:"text-2xl font-bold font-mono",style:{color:oe},children:Ne.date.toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx("span",{className:"text-xs font-semibold text-gray-400",children:Ne.date.toLocaleDateString("en-US",{year:"numeric"})})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold text-white",style:{backgroundColor:((Jt=Ae[Ne.day])==null?void 0:Jt.color)||oe},children:Ne.day===1?"1st":Ne.day===8?"8th":"11th"}),e.jsx("span",{className:"text-xs font-medium",style:{color:(Xt=Ae[Ne.day])==null?void 0:Xt.color},children:Ne.label})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 rounded-lg bg-gray-50 border border-gray-100",children:[e.jsx(ke,{size:12,className:"text-gray-400"}),e.jsxs("span",{className:"text-xs font-mono font-semibold text-gray-600",children:[Na(Ne.date)," until next run"]})]})]}):e.jsxs("div",{className:"flex flex-col items-center py-4 text-gray-400",children:[e.jsx(is,{size:24,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"Auto-schedule disabled"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:"Enable to see next run"})]})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 p-5 bg-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(_t,{size:16,style:{color:ye}}),e.jsx("span",{className:"text-xs font-bold text-gray-500 uppercase tracking-wider",children:"Last Auto-Run"})]}),o!=null&&o.last_run_at?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.last_run_status==="success"?e.jsx(le,{size:16,className:"text-emerald-600"}):o.last_run_status==="partial"?e.jsx(ce,{size:16,className:"text-amber-600"}):o.last_run_status==="error"?e.jsx(Re,{size:16,className:"text-red-600"}):e.jsx(ke,{size:16,className:"text-gray-400"}),e.jsx("span",{className:`text-sm font-bold ${o.last_run_status==="success"?"text-emerald-700":o.last_run_status==="partial"?"text-amber-700":o.last_run_status==="error"?"text-red-700":"text-gray-600"}`,children:o.last_run_status==="success"?"Completed Successfully":o.last_run_status==="partial"?"Partial Success":o.last_run_status==="error"?"Error":"Never Run"})]}),e.jsxs("p",{className:"text-xs text-gray-500 mb-3",children:[new Date(o.last_run_at).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),o.last_run_day&&e.jsxs("span",{className:"ml-1 text-gray-400",children:["— Day ",o.last_run_day]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-1.5",children:[e.jsxs("div",{className:"text-center p-1.5 rounded bg-emerald-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-emerald-700",children:o.last_run_sent}),e.jsx("p",{className:"text-[8px] text-emerald-600 font-semibold",children:"SENT"})]}),e.jsxs("div",{className:"text-center p-1.5 rounded bg-red-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-red-700",children:o.last_run_failed}),e.jsx("p",{className:"text-[8px] text-red-600 font-semibold",children:"FAIL"})]}),e.jsxs("div",{className:"text-center p-1.5 rounded bg-gray-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-gray-600",children:o.last_run_ski
vendor: 1,274 bytes, line 17
17pped}),e.jsx("p",{className:"text-[8px] text-gray-500 font-semibold",children:"SKIP"})]}),e.jsxs("div",{className:"text-center p-1.5 rounded bg-amber-50",children:[e.jsx("p",{className:"font-mono text-sm font-bold text-amber-700",children:o.last_run_late_fees}),e.jsx("p",{className:"text-[8px] text-amber-600 font-semibold",children:"FEES"})]})]}),o.last_run_error&&e.jsx("div",{className:"mt-2 px-2 py-1.5 rounded bg-red-50 border border-red-100",children:e.jsx("p",{className:"text-[10px] text-red-600 font-mono truncate",children:o.last_run_error})})]}):e.jsxs("div",{className:"flex flex-col items-center py-4 text-gray-400",children:[e.jsx(ke,{size:24,className:"mb-2 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium",children:"No auto-runs yet"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-1",children:"Will populate after first cron execution"})]})]})]}),e.jsxs("div",{className:"mt-5 pt-5 border-t border-gray-100",children:[e.jsxs("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-bold text-gray-700",children:["Edge Function: ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-gray-100 text-[10px] font-mono",children:"auto-compl
17iance-reminders"})]}),e.jsx("p",{className:"text-[10px] text-gray-500 mt-0.5",children:"Test the edge function manually or force-run regardless of schedule/toggle state"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>xt(!1),disabled:g,className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-semibold border border-gray-200 text-gray-600 hover:bg-gray-50 transition-colors disabled:opacity-50",children:[g?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(et,{size:12}),"Test Run (Respects Toggle)"]}),e.jsxs("button",{onClick:()=>xt(!0),disabled:g,className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-bold text-white transition-all disabled:opacity-50 hover:opacity-90",style:{background:`linear-gradient(135deg, ${oe}, ${Ut})`},children:[g?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Nt,{size:12}),"Force Run (Bypass All Checks)"]})]})]}),w&&e.jsxs("div",{className:`mt-3 p-4 rounded-xl border-2 ${w.success&&w.action==="executed"?"bg-emerald-50 border-emerald-200":w.success&&w.action==="skipped"?"bg-amber-50 border-amber-200":"bg-red-50 border-red-200"}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w.success&&w.action==="executed"?e.jsx(le,{size:16,className:"text-emerald-600"}):w.success&&w.action==="skipped"?e.jsx(ce,{size:16,className:"text-amber-600"}):e.jsx(Re,{size:16,className:"text-red-600"}),e.jsx("span",{className:`text-sm font-bold ${w.success&&w.action==="executed"?"text-emerald-700":w.success&&w.action==="skipped"?"text-amber-700":"text-red-700"}`,children:w.action==="executed"?"Edge Function Executed Successfully":w.action==="skipped"?`Skipped: ${w.reason}`:`Error: ${w.error}`})]}),e.jsx("button",{onClick:()=>M(null),className:"p-1 rounded hover:bg-white/50",children:e.jsx(Ie,{size:14,className:"text-gray-400"})})]}),w.action==="executed"&&e.jsxs("div",{className:"mt-3 grid grid-cols-5 gap-2",children:[e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white/60",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-gray-800",children:w.targets}),e.jsx("p",{className:"text-[9px] text-gray-500 font-semibold",children:"TARGETS"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white/60",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-emerald-700",children:w.sent}),e.jsx("p",{className:"text-[9px] text-emerald-600 font-semibold",children:"SENT"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white/60",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-red-700",children:w.failed}),e.jsx("p",{className:"text-[9px] text-red-600 font-semibold",children:"FAILED"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white/60",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-gray-600",children:w.skipped}),e.jsx("p",{className:"text-[9px] text-gray-500 font-semibold",children:"SKIPPED"})]}),e.jsxs("div",{className:"text-center p-2 rounded-lg bg-white/60",children:[e.jsx("p",{className:"font-mono text-lg font-bold text-amber-700",children:w.lateFees}),e.jsx("p",{className:"text-[9px] text-amber-600 font-semibold",children:"LATE FEES"})]})]})]})]})]}),i&&e.jsxs("div",{className:"border-t border-gray-100",children:[e.jsxs("div",{className:"px-6 py-3 bg-gray-50/50 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ls,{size:14,style:{color:ye}}),e.jsx("span",{className:"text-xs font-bold text-gray-700",children:"Cron Execution Log"}),e.jsxs("span",{className:"text-[10px] font-mono text-gray-400",children:[_.length," entries"]})]}),e.jsxs("button",{onClick:de,className:"flex items-center gap-1 text-[10px] text-gray-500 hover:text-gray-700",children:[e.jsx(Se,{size:10})," Refresh"]})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto",children:J?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(X,{size:20,className:"animate-spin text-gray-300"})}):_.length===0?e.jsx("div",{className:"text-center py-8 text-gray-400",children:e.jsx("p",{className:"text-xs",children:"No cron executions logged yet"})}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50 border-b border-gray-100",children:[e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-500",children:"Time"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Trigger"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500",children:"Day"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500",children:"Reminder?"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500",children:"Enabled?"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500",children:"Action"}),e.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-500",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:_.map(s=>{var j,E;return e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-gray-600",children:new Date(s.created_at).toLocaleStr
17ing("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold ${s.trigger_type==="cron"?"bg-purple-50 text-purple-700":s.trigger_type==="manual-force"?"bg-red-50 text-red-700":"bg-blue-50 text-blue-700"}`,children:s.trigger_type})}),e.jsx("td",{className:"px-3 py-2 text-center font-mono font-bold",children:s.trigger_day}),e.jsx("td",{className:"px-3 py-2 text-center",children:s.was_reminder_day?e.jsx(le,{size:12,className:"inline text-emerald-500"}):e.jsx(Ie,{size:12,className:"inline text-gray-300"})}),e.jsx("td",{className:"px-3 py-2 text-center",children:s.auto_enabled?e.jsx(Zs,{size:12,className:"inline text-emerald-500"}):e.jsx(is,{size:12,className:"inline text-gray-300"})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold ${s.action_taken==="executed"?"bg-emerald-50 text-emerald-700":s.action_taken==="error"?"bg-red-50 text-red-700":"bg-gray-100 text-gray-600"}`,children:s.action_taken})}),e.jsx("td",{className:"px-4 py-2 text-gray-500 max-w-[200px] truncate",children:((j=s.details)==null?void 0:j.message)||(((E=s.details)==null?void 0:E.sent)!==void 0?`${s.details.sent} sent, ${s.details.failed} failed`:"—")})]},s.id)})})]})})]})]}),e.jsx(pa,{}),e.jsx(ya,{}),e.jsx(ra,{}),e.jsx(la,{}),e.jsxs("div",{className:"p-4 rounded-xl border-2 flex items-start gap-3",style:{backgroundColor:ee.bgColor,borderColor:ee.borderColor},children:[e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${ee.color}15`,color:ee.color},children:ee.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-bold",style:{color:ee.color},children:ee.label}),!ge&&!H&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold bg-gray-100 text-gray-500",children:["Not a scheduled day — will use nearest: ",Me===1?"1st":Me===8?"8th":"11th"]}),ge&&e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold text-white",style:{backgroundColor:ee.color},children:"ACTIVE REMINDER DAY"})]}),e.jsx("p",{className:"text-xs text-gray-600",children:ee.description}),Me===11&&e.jsxs("p",{className:"text-xs font-semibold text-red-600 mt-1 flex items-center gap-1",children:[e.jsx(ce,{size:12})," $25 late fees will be auto-applied to active Z Bank loans"]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm p-5",children:[e.jsxs("h3",{className:"text-sm font-bold text-gray-800 mb-4 flex items-center gap-2",children:[e.jsx(st,{size:16,style:{color:ye}})," Monthly Reminder Schedule"]}),e.jsxs("div",{className:"flex items-center gap-0 relative",children:[e.jsx("div",{className:"absolute top-5 left-0 right-0 h-0.5 bg-gray-200"}),Array.from({length:30},(s,j)=>j+1).map(s=>{const j=nt.paymentReminders.includes(s),E=s===se,W=Ae[s];return e.jsxs("div",{className:"flex-1 flex flex-col items-center relative z-10",style:{minWidth:0},children:[j?e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center text-xs font-bold border-2 transition-all ${E?"text-white shadow-lg scale-110":"bg-white"}`,style:E?{backgroundColor:(W==null?void 0:W.color)||oe,borderColor:(W==null?void 0:W.color)||oe}:{borderColor:(W==null?void 0:W.color)||oe,color:(W==null?void 0:W.color)||oe},children:s}):s===10?e.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-[8px] font-bold bg-gray-100 text-gray-400 border border-gray-200",title:"Z Bank Due Date",children:s}):null,j&&e.jsx("span",{className:"text-[8px] font-semibold mt-1 whitespace-nowrap",style:{color:W==null?void 0:W.color},children:s===1?"Remind":s===8?"Warn":"Final"}),s===10&&!j&&e.jsx("span",{className:"text-[7px] text-gray-400 mt-1 whitespace-nowrap",children:"Due"})]},s)}).filter((s,j)=>[0,7,9,10].includes(j))]}),e.jsx("div",{className:"flex items-center justify-between mt-4 px-2",children:[{day:1,label:"1st — Upcoming Reminder",color:oe},{day:8,label:"8th — Payment Warning",color:"#d97706"},{day:10,label:"10th — Z Bank Due Date",color:"#6b7280"},{day:11,label:"11th — Final Notice + Late Fee",color:"#dc2626"}].map(s=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:s.color}}),e.jsx("span",{className:"text-[10px] font-medium",style:{color:s.color},children:s.label})]},s.day))})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-9 gap-3",children:[{label:"Total Sent",value:u,color:"#059669",icon:e.jsx(le,{size:14})},{label:"Sent w/ Retry",value:V,color:"#0891b2",icon:e.jsx(Gt,{size:14})},{label:"Failed",value:pe,color:"#dc2626",icon:e.jsx(Re,{size:14})},{label:"Exhausted Retries",value:me,color:"#7c2d12",icon:e.jsx(je,{size:14})},{label:"Bounced",value:he,color:"#be185d",icon:e.jsx(wt,{size:14})},{label:"Bounce Rate",value:`${Ue}%`,color:"#9333ea",icon:e.jsx(_s,{size:14})},{label:"Skipped",value:kt,color:"#6b7280",icon:e.jsx(dt,{size:14})},{label:"Late Fees",value:Ot(at),color:"#d97706",icon:e.jsx(ce,{size:14})},{label:"Total Retries",value:Pe,color:"#7c3aed",icon:e.jsx(Ht,{size:14})}].map((s,j)=>e.jsxs("div",{className:`bg-white rounded-xl border p-4 shadow-sm ${s.label==="Bounce Rate"&&parseFloat(Ue)>
175?"border-red-200 bg-red-50/30":s.label==="Bounced"&&he>0?"border-pink-200 bg-pink-50/30":"border-gray-100"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{backgroundColor:`${s.color}12`,color:s.color},children:s.icon}),e.jsx("span",{className:"text-[10px] font-semibold text-gray-400 uppercase tracking-wider",children:s.label})]}),e.jsx("p",{className:"font-mono text-xl font-bold",style:{color:s.color},children:s.value}),s.label==="Bounced"&&Be>0&&e.jsxs("p",{className:"text-[9px] font-semibold text-pink-600 mt-1",children:[Be," spam complaint",Be!==1?"s":""]}),s.label==="Bounce Rate"&&parseFloat(Ue)>5&&e.jsx("p",{className:"text-[9px] font-semibold text-red-600 mt-1",children:"Above 5% threshold"})]},j))}),e.jsx(xa,{}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-gray-100 flex flex-col md:flex-row md:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ks,{size:16,style:{color:ye}}),e.jsx("h3",{className:"text-sm font-bold text-gray-800",children:"Compliance Email Log"}),e.jsxs("span",{className:"text-[10px] font-mono text-gray-400",children:[qe.length," entries"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex bg-gray-100 rounded-lg p-0.5",children:["all","sent","bounced","failed","skipped"].map(s=>e.jsxs("button",{onClick:()=>ie(s),className:`px-3 py-1 rounded-md text-[10px] font-semibold transition-all ${Z===s?"bg-white shadow text-gray-900":"text-gray-500 hover:text-gray-700"}`,children:[s.charAt(0).toUpperCase()+s.slice(1),s==="bounced"&&he>0?` (${he})`:""]},s))}),e.jsxs("button",{onClick:Ss,className:"flex items-center gap-1 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-gray-200 text-gray-600 hover:bg-gray-50",children:[e.jsx(ws,{size:12})," Export CSV"]}),e.jsxs("button",{onClick:F,className:"flex items-center gap-1 px-3 py-1.5 rounded-lg text-[10px] font-semibold border border-gray-200 text-gray-600 hover:bg-gray-50",children:[e.jsx(Se,{size:12})," Refresh"]})]})]}),S?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(X,{size:24,className:"animate-spin",style:{color:ye}})}):ct.length===0?e.jsxs("div",{className:"flex flex-col items-center py-16 text-gray-400",children:[e.jsx(Ye,{size:40,className:"mb-3 text-gray-300"}),e.jsx("p",{className:"font-medium text-gray-500",children:"No Compliance Emails Sent Yet"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:'Click "Run Compliance Reminders" to send the first batch.'})]}):e.jsx("div",{className:"divide-y divide-gray-50",children:ct.map(([s,j])=>{const E=l===s,W=j.filter(p=>p.email_status==="sent").length,xe=j.filter(p=>p.email_status==="failed"||p.email_status==="failed_after_retries").length,ze=j.filter(p=>p.email_status==="failed_after_retries").length,pt=j.filter(p=>p.email_status==="bounced").length,Te=j.filter(p=>p.email_status==="skipped").length,rt=j.filter(p=>p.late_fee_applied).length,ve=j[0],lt=new Date(ve.created_at),ht=s.startsWith("auto_"),K=Z==="all"?j:j.filter(p=>p.email_status===Z);return K.length===0&&Z!=="all"?null:e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>A(E?null:s),className:"w-full px-5 py-3.5 flex items-center justify-between hover:bg-gray-50/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center text-white text-xs font-bold",style:{backgroundColor:ve.urgency_level==="final-notice"?"#dc2626":ve.urgency_level==="warning"?"#d97706":oe},children:ve.reminder_day}),e.jsxs("div",{className:"text-left",children:[e.jsxs("p",{className:"text-xs font-bold text-gray-900",children:[lt.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})," — ",e.jsx("span",{style:{color:ve.urgency_level==="final-notice"?"#dc2626":ve.urgency_level==="warning"?"#d97706":oe},children:ve.urgency_level==="final-notice"?"Final Notice":ve.urgency_level==="warning"?"Warning":"Upcoming"}),ht&&e.jsx("span",{className:"ml-2 px-1.5 py-0.5 rounded text-[9px] font-bold bg-purple-50 text-purple-700",children:"AUTO"})]}),e.jsxs("p",{className:"text-[10px] text-gray-500",children:[lt.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"})," — Batch: ",s.slice(0,16),"..."]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-bold bg-emerald-50 text-emerald-700",children:[W," sent"]}),pt>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-bold bg-pink-50 text-pink-700 border border-pink-200",children:[pt," bounced"]}),xe>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-bold bg-red-50 text-red-700",children:[xe," failed"]}),ze>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-bold bg-orange-50 text-orange-800 border border-orange-200",children:[ze," exhausted"]}),Te>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-bold bg-gray-100 text-gray-600",children:[Te," skipped"]}),rt>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-bold bg-amber-50 text-amber-700",children:[rt," late fees"]})]}),e.jsxs("span",{className:"text-[10px] font-mono text-gray-400",children:[j.length," emails"]}),E?e.jsx(Le,{size:14,className:"text-gray-400"}):e.jsx(Fe,{size:14,className:"text-gray-400"})]})]}),E&&e.jsx("div",{className:"border-t border-gray-100 bg-gray-50/30",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50 border-b border-gray-100",children:[e.jsx("th",{className:"px-5 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"Student"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"Email"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"Program"}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-500 uppercase tracking-wider",children:"Source"}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-gray-500 uppercase tracking-wider",children:"Balance"}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-500 uppercase tracking-wider",children:"Late Fee"}),e.jsx("th",{className:"px-5 py-2 text-center font-semibold text-gray-500 uppercase tracking-wider",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:(Z==="all"?j:K).map(p=>e.jsxs("tr",{className:"hover:bg-white transition-colors",children:[e.jsx("td",{className:"px-5 py-2.5 font-medium text-gray-900",children:p.student_name}),e.jsx("td",{className:"px-3 py-2.5 font-mono text-gray-500 text-[10px]",children:p.student_email||"—"}),e.jsx("td",{className:"px-3 py-2.5 text-gray-600",children:p.program_name||"—"}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-bold ${p.source==="z-bank"?"bg-purple-50 text-purple-700":"bg-blue-50 text-blue-700"}`,children:p.source==="z-bank"?"Z Bank":"Ledger"})}),e.jsx("td",{className:"px-3 py-2.5 text-right font-mono font-bold text-red-600",children:Ot(p.outstanding_balance)}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:p.late_fee_applied?e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-bold bg-amber-50 text-amber-700",children:["+",Ot(p.late_fee_amount)]}):e.jsx("span",{className:"text-gray-300",children:"—"})}),e.jsx("td",{className:"px-5 py-2.5",children:e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[p.email_status==="bounced"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-pink-50 text-pink-700 border border-pink-300",title:p.bounce_reason||"Mailgun reported bounce",children:[e.jsx(wt,{size:10})," Bounced",p.bounce_type&&e.jsx("span",{className:"ml-0.5 px-1 py-px rounded bg-pink-100 text-[8px] font-mono",children:p.bounce_type==="complaint"?"spam":p.bounce_type})]}):p.email_status==="sent"&&(p.retry_count||0)===0?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-emerald-50 text-emerald-700",children:[e.jsx(le,{size:10})," Sent"]}):p.email_status==="sent"&&(p.retry_count||0)>0?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-cyan-50 text-cyan-700 border border-cyan-200",title:`Sent after ${p.retry_count} retry(ies). ${(p.retry_errors||[]).join(" | ")}`,children:[e.jsx(Gt,{size:10})," Sent",e.jsxs("span",{className:"ml-0.5 px-1 py-px rounded bg-cyan-100 text-[8px] font-mono",children:[p.retry_count,"x"]})]}):p.email_status==="failed_after_retries"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-orange-50 text-orange-800 border border-orange-300",title:p.error_message||"",children:[e.jsx(je,{size:10})," Exhausted",e.jsxs("span",{className:"ml-0.5 px-1 py-px rounded bg-orange-100 text-[8px] font-mono",children:[p.retry_count,"/",p.max_retries||3]})]}):p.email_status==="failed"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-red-50 text-red-700",title:p.error_message||"",children:[e.jsx(Re,{size:10})," Failed"]}):p.email_status==="skipped"?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-gray-100 text-gray-600",children:[e.jsx(dt,{size:10})," Skipped"]}):e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[9px] font-bold bg-gray-100 text-gray-500",children:p.email_status}),p.email_status==="bounced"&&p.bounced_at&&e.jsx("span",{className:"text-[8px] font-mono text-pink-500",title:p.bounce_reason||"",children:new Date(p.bounced_at).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}),(p.retry_count||0)>0&&p.email_status!=="sent"&&p.email_status!=="failed_after_retries"&&p.email_status!=="bounced"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[8px] font-mono text-violet-600",children:[e.jsx(Ht,{size:8})," ",p.retry_count," retries"]})]})})]}
17,p.id))})]})})})]},s)})})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:`linear-gradient(135deg, ${Ut}, ${oe})`},children:[e.jsx("div",{className:"h-1",style:{background:`linear-gradient(90deg, ${Xe}, ${ot}, ${Xe})`}}),e.jsxs("div",{className:"px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Vt,{size:16,style:{color:ye}}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold",style:{color:ye},children:"Zorganics Institute of Cosmetology"}),e.jsx("p",{className:"text-[10px]",style:{color:ot},children:"1530 Cornwall Ave, Suite 200, Bellingham, WA 98225"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px]",style:{color:ot},children:[e.jsx(Ye,{size:10})," Mailgun API — Compliance Automation"]})]})]}),e.jsx(ua,{showRunModal:O,setShowRunModal:q,isRunning:T,runComplete:ue,runSummary:b,setRunComplete:U,setRunSummary:$,runProgress:I,urgencyConfig:ee,effectiveDay:Me,runComplianceReminders:mt})]})},Aa=Object.freeze(Object.defineProperty({__proto__:null,default:va},Symbol.toStringTag,{value:"Module"}));export{va as C,Vs as T,$t as Z,$a as a,Da as b,Ve as c,Aa as d,Ta as g};

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.