1import{c as F,d as ae,u as K,e as le,_ as ie,s as q,ad as Fs,aS as ns,r as f,j as e,aT as ls,ae as is,af as cs,ag as xe,ah as ds,aU as Ds,aV as Ms,aW as Ls,aX as zs,aY as Is,aZ as Os,a_ as Us,a$ as Bs,b0 as Ks,am as Ws,b1 as Qs,b2 as Gs,w as Vs,h as A,L as O,S as de,K as he,M as pe,N as je,O as ge,Q as fe,J as U,b3 as $e,Z as B,n as _,P as os,C as y,i as w,aL as xs,aQ as H,f as P,g as T,B as C,aA as L,E as Ee,R as J,T as ms,G as us,H as Y,I as ee,b4 as oe,b5 as hs,aB as ps,b6 as Hs,aR as ze,aH as js,b7 as Js,aq as Fe,ap as Zs}from"./index-Bm3D-n5I.js";import{i as E,l as p,T as W,h as Q,j as N,k as G,B as gs,A as Ke,m as We,a as Qe,b as Ge,c as Ve,d as He,e as Je,f as Ze,g as Xe}from"./alert-dialog-Dq3rBWk1.js";import{S as z}from"./scroll-area-DhLXWTqZ.js";import{U as Xs}from"./user-search-7iT7RjXe.js";import{W as Ye,A as Ys}from"./wrench-DT8xxza4.js";import{T as Pe}from"./trash-2-BjnQWe9C.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 et=F("BellRing",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}],["path",{d:"M4 2C2.8 3.7 2 5.7 2 8",key:"tap9e0"}],["path",{d:"M22 8c0-2.3-.8-4.3-2-6",key:"5bb3ad"}]]);/** 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 De=F("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const es=F("Building2",[["path",{d:"M6 22V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v18Z",key:"1b4qmf"}],["path",{d:"M6 12H4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2",key:"i71pzd"}],["path",{d:"M18 9h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2",key:"10jefs"}],["path",{d:"M10 6h4",key:"1itunk"}],["path",{d:"M10 10h4",key:"tcdvrf"}],["path",{d:"M10 14h4",key:"kelpxr"}],["path",{d:"M10 18h4",key:"1ulq68"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const st=F("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/** 22 * @license lucide-react v0.462.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const tt=F("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);/** 27 * @license lucide-react v0.462.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const Me=F("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/** 32 * @license lucide-react v0.462.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const at=F("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/** 37 * @license lucide-react v0.462.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const rt=F("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",ke
41y:"1mlx9k"}]]);/** 42 * @license lucide-react v0.462.0 - ISC 43 * 44 * This source code is licensed under the ISC license. 45 * See the LICENSE file in the root directory of this source tree. 46 */const nt=F("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/** 47 * @license lucide-react v0.462.0 - ISC 48 * 49 * This source code is licensed under the ISC license. 50 * See the LICENSE file in the root directory of this source tree. 51 */const lt=F("FlaskConical",[["path",{d:"M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2",key:"pzvekw"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M7 16h10",key:"wp8him"}]]);/** 52 * @license lucide-react v0.462.0 - ISC 53 * 54 * This source code is licensed under the ISC license. 55 * See the LICENSE file in the root directory of this source tree. 56 */const Ie=F("Gauge",[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]]);/** 57 * @license lucide-react v0.462.0 - ISC 58 * 59 * This source code is licensed under the ISC license. 60 * See the LICENSE file in the root directory of this source tree. 61 */const it=F("HardDrive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]]);/** 62 * @license lucide-react v0.462.0 - ISC 63 * 64 * This source code is licensed under the ISC license. 65 * See the LICENSE file in the root directory of this source tree. 66 */const ct=F("Layers",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65",key:"dd6zsq"}],["path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65",key:"ep9fru"}]]);/** 67 * @license lucide-react v0.462.0 - ISC 68 * 69 * This source code is licensed under the ISC license. 70 * See the LICENSE file in the root directory of this source tree. 71 */const dt=F("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/** 72 * @license lucide-react v0.462.0 - ISC 73 * 74 * This source code is licensed under the ISC license. 75 * See the LICENSE file in the root directory of this source tree. 76 */const ot=F("ListChecks",[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);/** 77 * @license lucide-react v0.462.0 - ISC 78 * 79 * This source code is licensed under the ISC license. 80 * See the LICENSE file in the root directory of this source tree. 81 */const xt=F("Radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]);/** 82 * @license lucide-react v0.462.0 - ISC 83 * 84 * This source code is licensed under the ISC license. 85 * See the LICENSE file in the root directory of this source tree. 86 */const mt=F("SearchX",[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/** 87 * @license lucide-react v0.462.0 - ISC 88 * 89 * This source code is licensed under the ISC license. 90 * See the LICENSE file in the root directory of this source tree. 91 */const ut=F("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);/** 92 * @license lucide-react v0.462.0 - ISC 93 * 94 * This source code is licensed under the ISC license. 95 * See the LICENSE file in the root directory of this source tree.
96 */const Le=F("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/** 97 * @license lucide-react v0.462.0 - ISC 98 * 99 * This source code is licensed under the ISC license. 100 * See the LICENSE file in the root directory of this source tree. 101 */const ht=F("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/** 102 * @license lucide-react v0.462.0 - ISC 103 * 104 * This source code is licensed under the ISC license. 105 * See the LICENSE file in the root directory of this source tree. 106 */const Ce=F("Unplug",[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]]);/** 107 * @license lucide-react v0.462.0 - ISC 108 * 109 * This source code is licensed under the ISC license. 110 * See the LICENSE file in the root directory of this source tree. 111 */const me=F("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function pt(){const{isAdmin:s}=ae();return K({queryKey:["admin-dashboard"],queryFn:async()=>{const{data:c,error:t}=await q.functions.invoke("admin-dashboard");if(t)throw t;return c},enabled:s,refetchInterval:6e4})}function jt(){const{isAdmin:s}=ae();return K({queryKey:["admin-autoapply-health"],queryFn:async()=>{const{data:c,error:t}=await q.functions.invoke("admin-dashboard",{body:{mode:"autoapply"}});if(t)throw t;return c},enabled:s,refetchInterval:3e4})}function gt(){const{isAdmin:s}=ae();return K({queryKey:["resolver-process-health"],queryFn:async()=>{const{data:c,error:t}=await q.functions.invoke("resolver-health?mode=process");if(t)throw t;return c},enabled:s,refetchInterval:6e4})}function ft(){const s=le();return ie({mutationFn:async()=>{const{data:c,error:t}=await q.functions.invoke("resolver-health?mode=wipe",{method:"POST"});if(t)throw t;return c},onSuccess:()=>{s.invalidateQueries({queryKey:["resolver-process-health"]})}})}function Nt(){const s=le();return ie({mutationFn:async()=>{const{data:c,error:t}=await q.functions.invoke("resolver-health?mode=wipe-discover",{method:"POST"});if(t)throw t;return c},onSuccess:()=>{s.invalidateQueries({queryKey:["resolver-process-health"]})}})}function bt(){const{isAdmin:s}=ae();return K({queryKey:["resolver-config"],queryFn:async()=>{const{data:c,error:t}=await q.functions.invoke("resolver-health?mode=config");if(t)throw t;return c},enabled:s})}function vt(){const s=le();return ie({mutationFn:async c=>{const{data:t,error:n}=await q.functions.invoke("resolver-health?mode=save-config",{method:"POST",body:c});if(n)throw n;return t},onSuccess:()=>{s.invalidateQueries({queryKey:["resolver-config"]})}})}function yt(){const s=le();return ie({mutationFn:async c=>{const{data:t,error:n}=await q.functions.invoke("resolver-health?mode=run",{method:"POST",body:{target:c}});if(n)throw n;return t},onSuccess:()=>{s.invalidateQueries({queryKey:["resolver-process-health"]})}})}function wt(){const{isAdmin:s}=ae();return K({queryKey:["intelligence-stats"],queryFn:async()=>{const{data:c,error:t}=await q.functions.invoke("company-intelligence?mode=stats");if(t)throw t;return c},enabled:!!s})}function kt(s=50){const{isAdmin:c}=ae();return K({queryKey:["intelligence-top",s],queryFn:async()=>{const{data:t,error:n}=await q.functions.invoke(`company-intelligence?mode=top&limit=${s}`);if(n)throw n;return t},enabled:!!c})}function _t(){const s=le();return ie({mutationFn:async c=>{const{data:t,error:n}=await q.functions.invoke("intelligence-build",{method:"POST",body:{dryRun:(c==null?void 0:c.dryRun)===!0}});if(n)throw n;return t},onSuccess:()=>{s.invalidateQueries({queryKey:["intelligence-stats"]}),s.invalidateQueries({queryKey:["intelligence-top"]})}})}function Ct(s,c){const{isAdmin:t}=ae(),n=s.trim();return K({queryKey:["intelligence-lookup",c,n],queryFn:async()=>{const i=c==="company"?"company":"slug",{data:x,error:u}=await q.functions.invoke(`company-intelligence?mode=lookup&${i}=${encodeURIComponent(n)}`);if(u)throw u;return x},enabled:!!t&&n.length>0})}function St(){return ie({mutationFn:async s=>{const{data:c,error:t}=await q.functions.invoke("resolve-public-poc",{method:"POST",body:s});if(t)throw t;return c}})}var Se="Popover",[fs,xa]=Fs(Se,[ns]),ue=ns(),[At,se]=fs(Se),Ns=s=>{const{__scopePopover:c,children:t,open:n,defaultOpen:i,onOpenChange:x,modal:u=!1}=s,a=ue(c),d=f.useRef(null),[j,h]=f.useState(!1),[r,l]=Ws({prop:n,defaultProp:i??!1,onChange:x,caller:Se});return e.jsx(Qs,{...a,children:e.jsx(At,{scope:c,contentId:Gs(),triggerRef:d,open:r,onOpenChange:l,onOpenToggle:f.useCallback(()=>l(m=>!m),[l]),hasCustomAnchor:j,onCustomAnchorAdd:f.useCallback(()=>h(!0),[]),onCustomAnchorRemove:f.useCallback(()=>h(!1),[]),modal:u,children:t})})};Ns.displayName=Se;var bs="PopoverAnchor",Rt=f.forwardRef((s,c)=>{const{__scopePopover:t,...n}=s,i=se(bs,t),x=ue(t),{onCustomAnchorAdd:u,onCustomAnchorRemove:a}=i;return f.useEffect(()=>(u(),()=>a()),[u,a]),e.jsx(ls,{...x,...n,ref:c})});Rt.displayName=bs;var vs="PopoverTrigger",ys=f.forwardRef((s,c)=>{const{__scopePopover:t,...n}=s,i=se(vs,t),x=ue(t),u=is(c,i.triggerRef),a=e.jsx(cs.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Ss(i.open),...n,ref:u,onClick:xe(s.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:e.jsx(ls,{asChild:!0,...x,children:a})});ys.displayName=vs;var Oe="PopoverPortal",[$t,Pt]=fs(Oe,{forceMount:void 0}),ws=s=>{const{__scopePopover:c,forceMount:t,children:n,container:i}=s,x=se(Oe,c);return e.jsx($t,{scope:c,forceMount:t,children:e.jsx(ds,{present:t||x.open,children:e.jsx(Bs,{asChild:!0,container:i,children:n})})})};ws.displayName=Oe;var ne="PopoverContent",ks=f.forwardRef((s,c)=>{const t=Pt(ne,s.__scopePopover),{forceMount:n=t.forceMount,...i}=s,x=se(ne,s.__scopePopover);return e.jsx(ds,{present:n||x.open,children:x.modal?e.jsx(qt,{...i,ref:c}):e.jsx(Et,{...i,ref:c})})});ks.displayName=ne;var Tt=Ks("PopoverContent.RemoveScroll"),qt=f.forwardRef((s,c)=>{const t=se(ne,s.__scopePopover),n=f.useRef(null),i=is(c,n),x=f.useRef(!1);return f.useEffect(()=>{const u=n.current;if(u)return Ds(u)},[]),e.jsx(Ms,{as:Tt,allowPinchZoom:!0,children:e.jsx(_s,{...s,ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:xe(s.onCloseAutoFocus,u=>{var a;u.preventDefault(),x.current||(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:xe(s.onPointerDownOutside,u=>{const a=u.detail.originalEvent,d=a.button===0&&a.ctrlKey===!0,j=a.button===2||d;x.current=j},{checkForDefaultPrevented:!1}),onFocusOutside:xe(s.onFocusOutside,u=>u.preventDefault(),{checkForDefaultPrevented:!1})})})}),Et=f.forwardRef((s,c)=>{const t=se(ne,s.__scopePopover),n=f.useRef(!1),i=f.useRef(!1);return e.jsx(_s,{...s,ref:c,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:x=>{var u,a;(u=s.onCloseAutoFocus)==null||u.call(s,x),x.defaultPrevented||(n.current||(a=t.triggerRef.current)==null||a.focus(),x.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:x=>{var d,j;(d=s.onInteractOutside)==null||d.call(s,x),x.defaultPrevented||(n.current=!0,x.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const u=x.target;((j=t.triggerRef.current)==null?void 0:j.contains(u))&&x.preventDefault(),x.detail.originalEvent.type==="focusin"&&i.current&&x.preventDefault()}})}),_s=f.forwardRef((s,c)=>{const{__scopePopover:t,trapFocus:n,onOpenAutoFocus:i,onCloseAutoFocus:x,disableOutsidePointerEvents:u,onEscapeKeyDown:a,onPointerDownOutside:d,onFocusOutside:j,onInteractOutside:h,...r}=s,l=se(ne,t),m=ue(t);return Ls(),e.jsx(zs,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:i,onUnmountAutoFocus:x,children:e.jsx(Is,{asChild:!0,disableOutsidePointerEvents:u,onInteractOutside:h,onEscapeKeyDown:a,onPointerDownOutside:d,onFocusOutside:j,onDismiss:()=>l.onOpenChange(!1),children:e.jsx(Os,{"data-state":Ss(l.open),role:"dialog",id:l.contentId,...m,...r,ref:c,style:{...r.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Cs="PopoverClose",Ft=f.forwardRef((s,c)=>{const{__scopePopover:t,...n}=s,i=se(Cs,t);return e.jsx(cs.button,{type:"button",...n,ref:c,onClick:xe(s.onClick,()=>i.onOpenChange(!1))})});Ft.displayName=Cs;var Dt="PopoverArrow",Mt=f.forwardRef((s,c)=>{const{__scopePopover:t,...n}=s,i=ue(t);return e.jsx(Us,{...i,...n,ref:c})});Mt.displayName=Dt;function Ss(s){return s?"open":"closed"}var Lt=Ns,zt=ys,It=ws,As=ks;const Ot=Lt,Ut=zt,Rs=f.forwardRef(({className:s,align:c="center",sideOffset:t=4,...n},i)=>e.jsx(It,{children:e.jsx(As,{ref:i,align:c,sideOffset:t,className:Vs("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:sli
111de-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...n})}));Rs.displayName=As.displayName;const Ne=[{label:"Every 2 min",value:"*/2 * * * *"},{label:"Every 5 min",value:"*/5 * * * *"},{label:"Every 10 min",value:"*/10 * * * *"},{label:"Every 15 min",value:"*/15 * * * *"},{label:"Every 30 min",value:"*/30 * * * *"},{label:"Every hour",value:"0 * * * *"}],ss={batch_size:10,max_attempts:5,promote_batch_size:24,resolve_schedule:"*/5 * * * *",promote_schedule:"*/5 * * * *",resolve_enabled:!0,promote_enabled:!0,classify_batch_size:12,classify_schedule:"*/5 * * * *",classify_enabled:!0,intel_batch_size:25,intel_schedule:"*/5 * * * *",intel_enabled:!0,api_batch_size:20,api_schedule:"*/5 * * * *",api_enabled:!0,chain_enabled:!0,api_call_delay_ms:2100,api_cooldown_minutes:5};function Bt(){const{data:s}=bt(),c=vt(),t=yt(),[n,i]=f.useState(ss),[x,u]=f.useState(!1);f.useEffect(()=>{s!=null&&s.config&&!x&&i({...ss,...s.config})},[s==null?void 0:s.config,x]);const a=r=>{t.mutate(r,{onSuccess:l=>{var k;const m=l.classify,v=l.intel,o=l.api,$=l.promote,R=[];m&&R.push(m.ok?`classified ${m.processed??0}`:`classify failed${m.error?`: ${m.error}`:""}`),v&&R.push(v.ok?`resolved ${v.processed??0}`:`intel failed${v.error?`: ${v.error}`:""}`),o&&R.push(o.ok?`API ${o.processed??0} (${((k=o.disposition)==null?void 0:k.api_resolved)??0} ok)`:`API failed${o.error?`: ${o.error}`:""}`),$&&R.push($.ok?`promoted ${$.promoted??0}`:`promote failed${$.error?`: ${$.error}`:""}`),_.success(`Run complete â ${R.join(" · ")}`)},onError:l=>_.error(`Run failed: ${l.message}`)})},d=()=>{c.mutate(n,{onSuccess:r=>{r.cronError?_.warning(`Settings saved, but schedule update failed: ${r.cronError}`):_.success("Resolver settings saved"),u(!1)},onError:r=>_.error(`Save failed: ${r.message}`)})},j=r=>r===""?0:Math.max(0,parseInt(r,10)||0),h=(r,l)=>e.jsxs(A,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>a(r),disabled:t.isPending,children:[t.isPending&&t.variables===r?e.jsx(B,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(os,{className:"h-3.5 w-3.5 mr-1.5"}),l]});return e.jsxs(e.Fragment,{children:[h("classify","Run classify"),h("intel","Run resolve"),h("api","Run API"),h("promote","Run promote"),e.jsxs(Ot,{open:x,onOpenChange:u,children:[e.jsx(Ut,{asChild:!0,children:e.jsxs(A,{size:"sm",variant:"outline",className:"h-7 text-xs",children:[e.jsx(ut,{className:"h-3.5 w-3.5 mr-1.5"}),"Settings"]})}),e.jsx(Rs,{align:"end",className:"w-80 max-h-[70vh] overflow-y-auto",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Resolver settings"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Applies to the whole funnel queue."})]}),e.jsxs("div",{className:"space-y-2 rounded-md border border-border/60 p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-xs font-semibold",children:"Event chaining (instant)"}),e.jsx(de,{checked:n.chain_enabled!==!1,onCheckedChange:r=>i(l=>({...l,chain_enabled:r}))})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"When on, each stage fires the next one immediately as soon as it finishes â no waiting for the timer. Crons below stay as a safety net. Steps are never skipped."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-xs font-semibold",children:"Stage 1 · Classify cron"}),e.jsx(de,{checked:n.classify_enabled,onCheckedChange:r=>i(l=>({...l,classify_enabled:r}))})]}),e.jsxs(he,{value:n.classify_schedule,onValueChange:r=>i(l=>
111({...l,classify_schedule:r})),disabled:!n.classify_enabled,children:[e.jsx(pe,{className:"h-8 text-xs",children:e.jsx(je,{})}),e.jsx(ge,{children:Ne.map(r=>e.jsx(fe,{value:r.value,className:"text-xs",children:r.label},r.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"Classify batch size"}),e.jsx(U,{type:"number",min:1,max:50,className:"h-8 text-xs",value:n.classify_batch_size,onChange:r=>i(l=>({...l,classify_batch_size:j(r.target.value)}))})]})]}),e.jsx($e,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-xs font-semibold",children:"Stage 2 · Intel resolve cron"}),e.jsx(de,{checked:n.intel_enabled,onCheckedChange:r=>i(l=>({...l,intel_enabled:r}))})]}),e.jsxs(he,{value:n.intel_schedule,onValueChange:r=>i(l=>({...l,intel_schedule:r})),disabled:!n.intel_enabled,children:[e.jsx(pe,{className:"h-8 text-xs",children:e.jsx(je,{})}),e.jsx(ge,{children:Ne.map(r=>e.jsx(fe,{value:r.value,className:"text-xs",children:r.label},r.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"Intel batch size"}),e.jsx(U,{type:"number",min:1,max:100,className:"h-8 text-xs",value:n.intel_batch_size,onChange:r=>i(l=>({...l,intel_batch_size:j(r.target.value)}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"Max attempts"}),e.jsx(U,{type:"number",min:1,max:20,className:"h-8 text-xs",value:n.max_attempts,onChange:r=>i(l=>({...l,max_attempts:j(r.target.value)}))})]})]})]}),e.jsx($e,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-xs font-semibold",children:"Stage 3 · API resolve cron"}),e.jsx(de,{checked:n.api_enabled,onCheckedChange:r=>i(l=>({...l,api_enabled:r}))})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Resolves leftover unresolved jobs via the LinkedIn job API. Promotes approved ATS only; caches non-approved companies permanently to save API calls."}),e.jsxs(he,{value:n.api_schedule,onValueChange:r=>i(l=>({...l,api_schedule:r})),disabled:!n.api_enabled,children:[e.jsx(pe,{className:"h-8 text-xs",children:e.jsx(je,{})}),e.jsx(ge,{children:Ne.map(r=>e.jsx(fe,{value:r.value,className:"text-xs",children:r.label},r.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"API batch size"}),e.jsx(U,{type:"number",min:1,max:50,className:"h-8 text-xs",value:n.api_batch_size,onChange:r=>i(l=>({...l,api_batch_size:j(r.target.value)}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"Delay/call (ms)"}),e.jsx(U,{type:"number",min:2e3,max:6e4,step:100,className:"h-8 text-xs",value:n.api_call_delay_ms??2100,onChange:r=>i(l=>({...l,api_call_delay_ms:j(r.target.value)}))})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ultra plan: 30 req/min cap â keep delay ⥠2,000 ms (â2,100 ms recommended) so the resolver never self-induces 429s."}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"Cooldown after rate-limit / auth error (min)"}),e.jsx(U,{type:"number",min:1,max:240,className:"h-8 text-xs",value:n.api_cooldown_minutes??10,onChange:r=>i(l=>({...l,api_cooldown_minutes:j(r.target.value)}))}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The API stage never self-loops. Calls are paced, and on a 429/401/403 it backs off for this long before any retry."})]})]}),e.jsx($e,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-xs font-semibold",children:"Stage 4 · Promote cron"}),e.jsx(de,{checked:n.promote_enabled,onCheckedChange:r=>i(l=>({...l,promote_enabled:r}))})]}),e.jsxs(he,{value:n.promote_schedule,onValueChange:r=>i(l=>({...l,promote_schedule:r})),disabled:!n.promote_enabled,children:[e.jsx(pe,{className:"h-8 text-xs",children:e.jsx(je,{})}),e.jsx(ge,{children:Ne.map(r=>e.jsx(fe,{value:r.value,className:"text-xs",children:r.label},r.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-[11px] text-muted-foreground",children:"Promote batch size"}),e.jsx(U,{type:"number",min:1,max:200,className:"h-8 text-xs",value:n.promote_batch_size,onChange:r=>i(l=>({...l,promote_batch_size:j(r.target.value)}))})]})]}),e.jsxs(A,{size:"sm",className:"w-full h-8 text-xs",onClick:d,disabled:c.isPending,children:[c.isPending?e.jsx(B,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):null,"Save settings"]})]})})]})]})}const ts={public_api:{label:"Cookie-free API",variant:"default"},template:{label:"URL template",variant:"secondary"},tenant_api:{label:"Tenant API",variant:"secondary"},none:{label:"Needs cookies",variant:"outline"}};function X({label:s,value:c}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:s}
111),e.jsx("div",{className:"text-sm font-medium mt-0.5",children:c})]})}function Kt({initialQuery:s="",initialKind:c="company"}){var v;const[t,n]=f.useState(s),[i,x]=f.useState(c),[u,a]=f.useState(s),{data:d,isFetching:j}=Ct(u,i),h=()=>a(t.trim()),r=d==null?void 0:d.company,l=((v=r==null?void 0:r.ats_resolution_strategy)==null?void 0:v.predicted_strategy)||"none",m=ts[l]||ts.none;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(y,{children:e.jsx(w,{className:"pt-5",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"inline-flex rounded-md border p-0.5",children:[e.jsxs(A,{size:"sm",variant:i==="company"?"secondary":"ghost",className:"h-8",onClick:()=>x("company"),children:[e.jsx(es,{className:"h-3.5 w-3.5 mr-1.5"})," Company"]}),e.jsxs(A,{size:"sm",variant:i==="slug"?"secondary":"ghost",className:"h-8",onClick:()=>x("slug"),children:[e.jsx(Le,{className:"h-3.5 w-3.5 mr-1.5"})," Slug"]})]}),e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(xs,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(U,{value:t,onChange:o=>n(o.target.value),onKeyDown:o=>o.key==="Enter"&&h(),placeholder:i==="company"?"Search company, e.g. DoorDash":"Search slug, e.g. doordashusa",className:"pl-8"})]}),e.jsx(A,{size:"sm",onClick:h,disabled:!t.trim(),children:"Search"})]})})}),!u&&e.jsx(y,{children:e.jsx(w,{className:"py-12 text-center text-sm text-muted-foreground",children:"Search a company or slug to inspect its knowledge-graph node."})}),u&&j&&e.jsx(H,{className:"h-48 rounded-lg"}),u&&!j&&d&&!d.found&&e.jsx(y,{children:e.jsxs(w,{className:"py-12 text-center text-sm text-muted-foreground",children:[e.jsx(mt,{className:"h-6 w-6 mx-auto mb-2 opacity-60"}),"No match for ",e.jsxs("span",{className:"font-medium text-foreground",children:["â",u,"â"]})," in the graph yet."]})}),u&&!j&&r&&e.jsxs(e.Fragment,{children:[e.jsxs(y,{children:[e.jsx(P,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(es,{className:"h-4 w-4"}),r.display_name||r.normalized_name]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"outline",children:r.predicted_ats}),e.jsxs(C,{variant:m.variant,children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"}),m.label]})]})]})}),e.jsx(w,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(X,{label:"ATS confidence",value:`${Math.round((r.ats_confidence||0)*100)}%`}),e.jsx(X,{label:"Historical jobs",value:r.historical_jobs??0}),e.jsx(X,{label:"Resolved",value:r.resolved_count??0}),e.jsx(X,{label:"Success rate",value:r.success_rate!=null?`${Math.round(r.success_rate*100)}%`:"â"}),e.jsx(X,{label:"Primary slug",value:e.jsx("span",{className:"font-mono text-xs",children:r.primary_slug||"â"})}),e.jsx(X,{label:"Primary career URL",value:r.primary_career_url?e.jsx("a",{href:r.primary_career_url,target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline break-all",children:r.primary_career_url}):"â"}),e.jsx(X,{label:"Normalized name",value:e.jsx("span",{className:"font-mono text-xs",children:r.normalized_name})}),e.jsx(X,{label:"Last seen",value:e.jsx("span",{className:"text-xs text-muted-foreground",children:r.last_seen_at?L(new Date(r.last_seen_at),{addSuffix:!0}):"â"})})]})})]}),e.jsx(be,{icon:Le,title:"Slug candidates",rows:(d==null?void 0:d.slugs)||[],columns:["ATS","Slug","Occurrences","Conf."],render:o=>e.jsxs(E,{children:[e.jsx(p,{children:e.jsx(C,{variant:"outline",children:o.ats})}),e.jsx(p,{className:"font-mono text-xs",children:o.slug}),e.jsx(p,{className:"text-right tabular-nums",children:o.occurrences}),e.jsx(p,{className:"text-right tabular-nums",children:o.confidence!=null?`${Math.round(o.confidence*100)}%`:"â"})]},`${o.ats}-${o.slug}`)}),e.jsx(be,{icon:dt,title:"Career URLs",rows:(d==null?void 0:d.careerUrls)||[],columns:["ATS","Base URL","Occurrences"],render:o=>e.jsxs(E,{children:[e.jsx(p,{children:e.jsx(C,{variant:"outline",children:o.ats})}),e.jsx(p,{className:"font-mono text-xs break-all",children:o.base_url}),e.jsx(p,{className:"text-right tabular-nums",children:o.occurrences})]},o.base_url)}),e.jsx(be,{icon:rt,title:"URL templates",rows:(d==null?void 0:d.templates)||[],columns:["ATS","Template","Occurrences","Conf."],render:o=>e.jsxs(E,{children:[e.jsx(p,{children:e.jsx(C,{variant:"outline",children:o.ats})}),e.jsx(p,{className:"font-mono text-xs break-all",children:o.template}),e.jsx(p,{className:"text-right tabular-nums",children:o.occurrences}),e.jsx(p,{className:"text-right tabular-nums",children:o.confidence!=null?`${Math.round(o.confidence*100)}%`:"â"})]},o.template)}),e.jsx(be,{icon:me,title:"Aliases",rows:(d==null?void 0:d.aliases)||[],columns:["Alias","Occurrences"],render:o=>e.jsxs(E,{children:[e.jsx(p,{children:o.alias}),e.jsx(p,{className:"text-right tabular-nums",children:o.occurrences})]},o.alias)})]})]})}function be({icon:s,title:c,rows:t,columns:n,render:i}){return e.jsxs(y,{children:[e.jsx(P,{className:"pb-2",children:e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(s,{className:"h-3.5 w-3.5"})," ",c,e.jsx(C,{variant:"secondary",className:"ml-1",children:t.length})]})}),e.jsx(w,{children:t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-3",children:"None recorded."}):e.jsx(z,{className:"max-h-[280px]",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsx(E,{children:n.map((x,u)=>e.jsx(N,{className:u>=2?"text-right":"",children:x},x))})}),e.jsx(G,{children:t.map(i)})]})})})]})}const as={matched:{label:"Match",variant:"default"},ambiguous:{label:"Ambiguous",variant:"secondary"},no_match:{label:"No match",variant:"outline"},no_slug:{label:"No slug",variant:"outline"},no_company:{label:"No company",variant:"outline"},board_error:{label:"Board error",variant:"destructive"}};function ve(s){return`${Math.round((s??0)*100)}%`}function Wt({url:s}){return s?e.jsxs("a",{href:s,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline max-w-[280px] truncate",onClick:c=>c.stopPropagation(),children:[e.jsx(Ee,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:s.replace(/^https?:\/\//,"")})]}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}function Qt(){const s=St(),[c,t]=f.useState(""),[n,i]=f.useState(""),[x,u]=f.useState(""),[a,d]=f.useState([]),[j,h]=f.useState(null),r=()=>{if(!c.trim()||!n.trim()){_.error("Company and title are required");return}s.mutate({company:c.trim(),title:n.trim(),location:x.trim()||null},{onSuccess:m=>{d(m.results),h(m.tally)},onError:m=>_.error(`Resolve failed: ${m.message}`)})},l=m=>{s.mutate({sample:m},{onSuccess:v=>{d(v.results),h(v.tally),v.count===0&&_.info("No pending jobs mapped to a Greenhouse/Ashby slug")},onError:v=>_.error(`Sample failed: ${v.message}`)})};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(y,{children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ce,{className:"h-4 w-4"})," Cookie-Free Resolver (POC)",e.jsxs(C,{variant:"outline",className:"ml-1",children:[e.jsx(lt,{className:"h-3 w-3 mr-1"})," observability only"]})]})}),e.jsxs(w,{className:"space-y-4 text-sm",children:[e.jsxs("p",{className:"text-muted-foreground",children:["Maps a job's ",e.jsx("span",{className:"text-foreground font-medium",children:"company â ATS + slug"}),", pulls the board's public posting list, and matches by title + location to read the apply URL straight off the board â no LinkedIn cookies. Writes n
111othing; results are for eyeballing accuracy. Greenhouse & Ashby only."]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:[e.jsx(U,{placeholder:"Company (e.g. Anthropic)",value:c,onChange:m=>t(m.target.value)}),e.jsx(U,{placeholder:"Title (e.g. Senior Cloud Engineer)",value:n,onChange:m=>i(m.target.value)}),e.jsx(U,{placeholder:"Location (optional)",value:x,onChange:m=>u(m.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(A,{size:"sm",onClick:r,disabled:s.isPending,children:[e.jsx(os,{className:`h-3.5 w-3.5 mr-1.5 ${s.isPending?"animate-pulse":""}`}),"Resolve job"]}),e.jsx(A,{size:"sm",variant:"outline",onClick:()=>l(10),disabled:s.isPending,children:"Run sample (10 pending)"})]}),j&&e.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(j).map(([m,v])=>{const o=as[m]||{label:m,variant:"outline"};return e.jsxs(C,{variant:o.variant,children:[o.label,": ",v]},m)})})]})]}),a.length>0&&e.jsxs(y,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(T,{className:"text-sm",children:"Match results"})}),e.jsx(w,{children:e.jsx(z,{className:"h-[460px]",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{children:"Decision"}),e.jsx(N,{children:"LinkedIn job"}),e.jsx(N,{children:"ATS / slug"}),e.jsx(N,{children:"Matched posting"}),e.jsx(N,{className:"text-right",children:"Conf."}),e.jsx(N,{children:"Apply URL"})]})}),e.jsx(G,{children:a.map((m,v)=>{var $;const o=as[m.status]||{label:m.status,variant:"outline"};return e.jsxs(E,{children:[e.jsx(p,{children:e.jsx(C,{variant:o.variant,children:o.label})}),e.jsxs(p,{children:[e.jsx("div",{className:"font-medium",children:m.input.title||"â"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[m.input.company,m.input.location?` · ${m.input.location}`:""]})]}),e.jsx(p,{className:"text-xs",children:m.ats?e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"outline",children:m.ats}),e.jsx("div",{className:"font-mono mt-0.5",children:m.slug}),typeof m.boardCount=="number"&&e.jsxs("div",{className:"text-muted-foreground",children:[m.boardCount," postings"]})]}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(p,{children:m.best?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-medium",children:m.best.title}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[m.best.location||"â"," · token ",ve(m.best.titleScore)," / seq ",ve(m.best.seqScore),!m.best.locationOk&&" · loc mismatch"]}),m.alternates&&m.alternates.length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:["alt: ",m.alternates.map(R=>`${R.title} (${ve(R.score)})`).join(", ")]})]}):m.error?e.jsx("span",{className:"text-destructive text-xs",children:m.error}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(p,{className:"text-right tabular-nums",children:ve(m.confidence)}),e.jsx(p,{className:"text-xs",children:e.jsx(Wt,{url:($=m.best)==null?void 0:$.apply_url})})]},v)})})]})})})]})]})}const rs={public_api:{label:"Cookie-free API",variant:"default"},template:{label:"URL template",variant:"secondary"},tenant_api:{label:"Tenant API",variant:"secondary"},none:{label:"Needs cookies",variant:"outline"}};function ye({icon:s,label:c,value:t,hint:n}){return e.jsx(y,{children:e.jsxs(w,{className:"pt-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs uppercase tracking-wide",children:[e.jsx(s,{className:"h-3.5 w-3.5"})," ",c]}),e.jsx("div",{className:"text-2xl font-semibold mt-1",children:t}),n&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:n})]})})}function Gt(){var v;const{data:s,isLoading:c}=wt(),{data:t,isLoading:n}=kt(50),i=_t(),[x,u]=f.useState(null),[a,d]=f.useState("overview"),[j,h]=f.useState(""),r=o=>{h(o),d("explorer")},l=o=>{i.mutate({dryRun:o},{onSuccess:$=>{if($.error){_.error(`Build failed: ${$.error}`);return}const R=$.summary;u(`${o?"Dry run":"Build"}: scanned ${R.scanned}, ${R.companies} companies, ${R.slugs} slugs, ${R.atsResolvableCompanies} cookie-free resolvable`),_.success(o?"Dry run complete":"Knowledge graph rebuilt")},onError:$=>_.error(`Build failed: ${$.message}`)})}
111,m=s&&s.companies>0?Math.round(s.cookieFreeResolvable/Math.min(s.companies,s.sampledForDistribution||s.companies)*100):0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(y,{children:[e.jsx(P,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(T,{className:"flex items-center gap-2 text-base",children:[e.jsx(De,{className:"h-4 w-4"})," Job Resolution Intelligence"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>l(!0),disabled:i.isPending,children:"Dry run"}),e.jsxs(A,{size:"sm",onClick:()=>l(!1),disabled:i.isPending,children:[e.jsx(J,{className:`h-3.5 w-3.5 mr-1.5 ${i.isPending?"animate-spin":""}`}),"Rebuild graph"]})]})]})}),e.jsxs(w,{className:"text-sm text-muted-foreground space-y-1",children:[e.jsxs("p",{children:["Mines historical jobs into a company â ATS â slug knowledge graph so apply links can be rebuilt",e.jsx("span",{className:"text-foreground font-medium",children:" without LinkedIn cookies"}),"."]}),x&&e.jsx("p",{className:"text-foreground",children:x})]})]}),e.jsxs(ms,{value:a,onValueChange:o=>d(o),children:[e.jsxs(us,{children:[e.jsxs(Y,{value:"overview",children:[e.jsx(De,{className:"h-3.5 w-3.5 mr-1.5"})," Overview"]}),e.jsxs(Y,{value:"explorer",children:[e.jsx(xs,{className:"h-3.5 w-3.5 mr-1.5"})," Explorer"]}),e.jsxs(Y,{value:"resolver",children:[e.jsx(Ce,{className:"h-3.5 w-3.5 mr-1.5"})," Resolver POC"]})]}),e.jsxs(ee,{value:"overview",className:"space-y-4 mt-4",children:[c?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Array.from({length:4}).map((o,$)=>e.jsx(H,{className:"h-24"},$))}):e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(ye,{icon:at,label:"Companies",value:(s==null?void 0:s.companies)??0}),e.jsx(ye,{icon:Le,label:"Slug candidates",value:(s==null?void 0:s.slugCandidates)??0}),e.jsx(ye,{icon:ht,label:"Title nodes",value:(s==null?void 0:s.titles)??0}),e.jsx(ye,{icon:Ce,label:"Cookie-free",value:`${(s==null?void 0:s.cookieFreeResolvable)??0}`,hint:`${m}% of sampled companies`})]}),(s==null?void 0:s.predictedAtsDistribution)&&Object.keys(s.predictedAtsDistribution).length>0&&e.jsxs(y,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(T,{className:"text-sm",children:"Predicted ATS distribution"})}),e.jsx(w,{className:"flex flex-wrap gap-2",children:Object.entries(s.predictedAtsDistribution).sort((o,$)=>$[1]-o[1]).map(([o,$])=>e.jsxs(C,{variant:"secondary",children:[o,": ",$]},o))})]}),e.jsxs(y,{children:[e.jsx(P,{className:"pb-2",children:e.jsx(T,{className:"text-sm",children:"Top companies by historical jobs"})}),e.jsx(w,{children:n?e.jsx(H,{className:"h-64"}):(((v=t==null?void 0:t.companies)==null?void 0:v.length)??0)===0?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"No data yet â run âRebuild graphâ to mine historical jobs."}):e.jsx(z,{className:"h-[420px]",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{children:"Company"}),e.jsx(N,{children:"Predicted ATS"}),e.jsx(N,{children:"Resolution"}),e.jsx(N,{className:"text-right",children:"Jobs"}),e.jsx(N,{className:"text-right",children:"Conf."}),e.jsx(N,{children:"Primary slug"}),e.jsx(N,{children:"Last seen"})]})}),e.jsx(G,{children:t.companies.map(o=>{var k;const $=((k=o.ats_resolution_strategy)==null?void 0:k.predicted_strategy)||"none",R=rs[$]||rs.none;return e.jsxs(E,{className:"cursor-pointer",onClick:()=>r(o.display_name||o.normalized_name),children:[e.jsx(p,{className:"font-medium",children:o.display_name||o.normalized_name}),e.jsx(p,{children:e.jsx(C,{variant:"outline",children:o.predicted_ats})}),e.jsx(p,{children:e.jsx(C,{variant:R.variant,children:R.label})}),e.jsx(p,{className:"text-right tabular-nums",children:o.historical_jobs}),e.jsxs(p,{className:"text-right tabular-nums",children:[Math.round(o.ats_confidence*100),"%"]}),e.jsx(p,{className:"font-mono text-xs",children:o.primary_slug||"â"}),e.jsx(p,{className:"text-xs text-muted-foreground",children:o.last_seen_at?L(new Date(o.last_seen_at),{addSuffix:!0}):"â"})]},o.id)})})]})})})]})]}),e.jsx(ee,{value:"explorer",className:"mt-4",children:e.jsx(Kt,{initialQuery:j,initialKind:"company"},j)}),e.jsx(ee,{value:"resolver",className:"mt-4",children:e.jsx(Qt,{})})]})]})}function Vt(){var x,u;const{data:s,isLoading:c}=jt();if(c)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Array.from({length:4}).map((a,d)=>e.jsx(H,{className:"h-24 rounded-lg"},d))}
111),e.jsx(H,{className:"h-64 rounded-lg"})]});if(!s)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load auto-apply health."});const t=s.totals,n=[{label:"Enabled Users",value:`${t.enabledUsers}`,sub:`${t.browserbaseUsers} on Browserbase`,icon:me,color:"text-primary"},{label:"In Flight / Queued",value:`${t.inFlight} / ${t.queued}`,sub:"cap 20 global · 5 per user",icon:Ie,color:"text-primary"},{label:"Applied (24h)",value:`${t.applied24h}`,sub:`${t.failed24h} skipped`,icon:oe,color:"text-[hsl(var(--success))]"},{label:"Success Rate (24h)",value:t.successRate24h==null?"â":`${t.successRate24h}%`,sub:"applied vs skipped",icon:gs,color:"text-[hsl(var(--warning))]"}],i=Object.entries(s.atsHealth).sort((a,d)=>d[1].applied+d[1].failed+d[1].inFlight+d[1].queued-(a[1].applied+a[1].failed+a[1].inFlight+a[1].queued));return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:n.map(a=>e.jsx(y,{children:e.jsx(w,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a.label}),e.jsx("p",{className:"text-2xl font-semibold mt-1",children:a.value}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:a.sub})]}),e.jsx(a.icon,{className:`h-5 w-5 ${a.color}`})]})})},a.label))}),e.jsxs(y,{children:[e.jsx(P,{className:"py-3",children:e.jsx(T,{className:"text-sm",children:"ATS Health (24h)"})}),e.jsx(w,{className:"pt-0",children:i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"No auto-apply activity in the last 24h."}):e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{children:"ATS"}),e.jsx(N,{className:"text-right",children:"Applied"}),e.jsx(N,{className:"text-right",children:"Skipped"}),e.jsx(N,{className:"text-right",children:"In flight"}),e.jsx(N,{className:"text-right",children:"Queued"}),e.jsx(N,{className:"text-right",children:"Success"})]})}),e.jsx(G,{children:i.map(([a,d])=>{const j=d.applied+d.failed;return e.jsxs(E,{children:[e.jsx(p,{className:"uppercase text-xs font-medium",children:a}),e.jsx(p,{className:"text-right",children:d.applied}),e.jsx(p,{className:"text-right",children:d.failed}),e.jsx(p,{className:"text-right",children:d.inFlight}),e.jsx(p,{className:"text-right",children:d.queued}),e.jsx(p,{className:"text-right",children:j?`${Math.round(d.applied/j*100)}%`:"â"})]},a)})})]})})]}),e.jsxs(y,{children:[e.jsx(P,{className:"py-3",children:e.jsx(T,{className:"text-sm",children:"Per User"})}),e.jsx(w,{className:"pt-0",children:e.jsx(z,{className:"h-[320px]",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{children:"User"}),e.jsx(N,{children:"Engine"}),e.jsx(N,{className:"text-right",children:"Queued"}),e.jsx(N,{className:"text-right",children:"In flight"}),e.jsx(N,{className:"text-right",children:"Applied 24h"}),e.jsx(N,{className:"text-right",children:"Skipped 24h"}),e.jsx(N,{children:"Last activity"})]})}),e.jsx(G,{children:s.perUser.map(a=>e.jsxs(E,{children:[e.jsxs(p,{className:"text-xs max-w-[200px] truncate",title:a.email,children:[a.email,!a.enabled&&e.jsx(C,{variant:"outline",className:"ml-2 text-[10px]",children:"off"})]}),e.jsx(p,{children:e.jsx(C,{variant:"outline",className:"text-[10px]",children:a.engine})}),e.jsx(p,{className:"text-right",children:a.queued}),e.jsx(p,{className:"text-right",children:a.inFlight}),e.jsx(p,{className:"text-right text-[hsl(var(--success))]",children:a.applied24h}),e.jsx(p,{className:"text-right text-destructive",children:a.failed24h}),e.jsx(p,{className:"text-xs text-muted-foreground",children:a.lastActivity?L(new Date(a.lastActivity),{addSuffix:!0}):"â"})]},a.user_id))})]})})})]}),e.jsxs(y,{children:[e.jsx(P,{className:"py-3",children:e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4 text-[hsl(var(--warning))]"}),"Stuck extension clients (",((x=s.stuckClients)==null?void 0:x.length)??0,")",e.jsxs("span",{className:"ml-auto text-[10px] font-normal text-muted-foreground",children:[s.sweptResets24h??0," jobs auto-recovered (24h)"]})]})}),e.jsx(w,{className:"pt-0",children:(u=s.stuckClients)!=null&&u.length?e.jsx(z,{className:"max-h-[180px]",children:s.stuckClients.map(a=>e.jsxs("div",{className:"text-xs border-b border-border py-2",children:[e.jsx("div",{className:"font-medium truncate",children:a.email}),e.jsxs("div",{className:"text-muted-foreground truncate",children:["lock held ",Math.round((a.lock_age_seconds??0)/60),"m · v",a.version??"â",a.last_seen?` · seen ${L(new Date(a.last_seen),{addSuffix:!0})}`:""]})]},a.instance_id))}):e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"No wedged clients â every extension lock
111is healthy."})})]}),s.adoption&&e.jsxs(y,{children:[e.jsx(P,{className:"py-3",children:e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(hs,{className:"h-4 w-4 text-primary"}),"Extension adoption",e.jsxs("span",{className:"ml-auto text-[10px] font-normal text-muted-foreground",children:[s.adoption.nudgedCount," install emails sent"]})]})}),e.jsxs(w,{className:"pt-0 space-y-3",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[{label:"Total users",value:s.adoption.totalUsers},{label:"Active (30d)",value:s.adoption.installedActive},{label:"Idle installs",value:s.adoption.installedIdle},{label:"Never installed",value:s.adoption.neverInstalledCount}].map(a=>e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a.label}),e.jsx("p",{className:"text-xl font-semibold mt-1",children:a.value})]},a.label))}),s.adoption.neverInstalled.length?e.jsx(z,{className:"max-h-[220px]",children:s.adoption.neverInstalled.map(a=>e.jsxs("div",{className:"text-xs border-b border-border py-2 flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate flex-1",children:a.email}),a.created_at&&e.jsxs("span",{className:"text-muted-foreground shrink-0",children:["joined ",L(new Date(a.created_at),{addSuffix:!0})]}),e.jsx(C,{variant:a.nudge_sent_at?"secondary":"outline",className:"text-[10px] h-4 shrink-0",children:a.nudge_sent_at?"emailed":"not emailed"})]},a.user_id))}):e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"Every user has shown extension activity."})]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs(y,{children:[e.jsx(P,{className:"py-3",children:e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4 text-[hsl(var(--warning))]"}),"Stuck runs (",s.stuck.length,")"]})}),e.jsx(w,{className:"pt-0",children:s.stuck.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"Nothing stuck â all in-flight runs are progressing."}):e.jsx(z,{className:"h-[220px] space-y-2",children:s.stuck.map(a=>e.jsxs("div",{className:"text-xs border-b border-border py-2",children:[e.jsxs("div",{className:"font-medium truncate",children:[a.title," · ",a.company]}),e.jsxs("div",{className:"text-muted-foreground truncate",children:[a.email," · ",e.jsx("span",{className:"uppercase",children:a.ats})," · ",a.stage," · ",L(new Date(a.updated_at),{addSuffix:!0})]})]},a.id))})})]}),e.jsxs(y,{children:[e.jsx(P,{className:"py-3",children:e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(ps,{className:"h-4 w-4 text-destructive"}),"Recent failures"]})}),e.jsx(w,{className:"pt-0",children:s.recentFailures.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"No failures in the last 7 days."}):e.jsx(z,{className:"h-[220px]",children:s.recentFailures.map(a=>e.jsxs("div",{className:"text-xs border-b border-border py-2",children:[e.jsxs("div",{className:"font-medium truncate",children:[a.title," · ",a.company]}),e.jsxs("div",{className:"text-muted-foreground truncate",children:[a.email," · ",e.jsx("span",{className:"uppercase",children:a.ats})," · ",a.engine||"ec2"," · ",L(new Date(a.updated_at),{addSuffix:!0})]}),a.error&&e.jsx("div",{className:"text-destructive truncate mt-0.5",children:a.error})]},a.id))})})]})]})]})}function Ht(){const[s,c]=f.useState(!1),t=le(),{data:n,isLoading:i}=K({queryKey:["outreach-poster-stats"],staleTime:6e4,queryFn:async()=>{var m,v,o;const a=q,[d,j,h,r]=await Promise.all([a.from("linkedin_job_posters").select("*",{count:"exact",head:!0}),a.from("linkedin_job_posters").select("*",{count:"exact",head:!0}).eq("found",!0),q.rpc("outreach_poster_backlog"),a.from("outreach_poster_lease").select("cooldown_until,note").eq("id",!0).maybeSingle()]),{data:l}=await a.from("linkedin_job_posters").select("checked_at").order("checked_at",{ascending:!1}).limit(1).maybeSingle();return{checked:d.count??0,found:j.count??0,remaining:Number(h.data??0),ready:!d.error,blocked:((m=r.data)==null?void 0:m.note)==="no_credit"||!!((v=r.data)!=null&&v.cooldown_until),blockedUntil:((o=r.data)==null?void 0:o.cooldown_until)??null,lastCheckedAt:(l==null?void 0:l.checked_at)??null}}}),x=async()=>{c(!0);try{const{data:a,error:d}=await q.functions.invoke("outreach-find-posters",{body:{batch:50}});if(d){const j=d instanceof Hs?await d.context.text():d.message;let h={};try{h=JSON.parse(j)}catch{}if(h.not_ready){_.info(h.error||"Contact lookup is not set up yet.");return}throw new Error(h.error||j)}if(a!=null&&a.not_ready){_.info(a.note||"Contact lookup is not set up yet.");return}(a==null?void 0:a.blocked)==="no_credit"?_.error(a.note||"Contact lookup paused â lookup account out of credit"):(a==null?void 0:a.skipped)==="locked"?_.info("Another backfill run is already in progress."):(a==null?void 0:a.skipped)==="cooldown"?_.info("Contact lookup is on billing cooldown; it will resume automatically."):a!=null&&a.checked?_.success(`Checked ${a.checked} job${a.checked===1?"":"s"} â found ${a.found} contact${a.found===1?"":"s"}, filled ${a.filled} (~$${a.cost_estimate_usd}).`):_.info((a==null?void 0:a.note)||"Nothing left to check."),t.invalidateQueries({queryKey:["outreach-poster-stats"]})}catch(a){_.error(`Backfill failed: ${a instanceof Error?a.message:String(a)}`)}finally{c(!1)}},u=n&&n.checked>0?Math.round(n.found/n.checked*100):null;return e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(Xs,{className:"h-4 w-4 text-primary"}),"Outreach contacts",u!==null&&e.jsxs(C,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:[u,"% hit rate"]})]})}),e.jsxs(w,{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Looks up the public LinkedIn job poster for jobs found in the past 7 days, newest first, whether applied or not. Roughly one post in five names a person; misses are cached so we never pay to check the same job twice."}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Jobs checked"}),e.jsx("p",{className:"text-xl font-semibold",children:i?"â":(n==null?void 0:n.checked)??0})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Contacts found"}),e.jsx("p",{className:"text-xl font-semibold",children:i?"â":(n==null?void 0:n.found)??0})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Unchecked"}),e.jsx("p",{className:"text-xl font-semibold",children:i?"â":(n==null?void 0:n.remaining)??0})]})]}),!i&&n&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[Math.max(n.checked-n.found,0)," checked
111jobs named no contact publicly. Unchecked counts only jobs the lookup has never seen."]}),!i&&n&&!n.ready&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Contact lookup switches on once this update is accepted."}),!i&&n&&n.blocked&&e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/10 p-3 flex items-start gap-2",children:[e.jsx(st,{className:"h-4 w-4 text-destructive shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-destructive",children:"Contact lookup paused â lookup account out of credit"}),n.lastCheckedAt&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:["Last successful check: ",new Date(n.lastCheckedAt).toLocaleString()]})]})]}),e.jsxs(A,{size:"sm",onClick:x,disabled:s||!i&&!!n&&(!n.ready||n.blocked),className:"w-full",children:[e.jsx(J,{className:`h-3.5 w-3.5 mr-1.5 ${s?"animate-spin":""}`}),s?"Looking up contactsâ¦":"Backfill next 50 jobs"]})]})]})}const we=25;function Jt(){const[s,c]=f.useState("found"),[t,n]=f.useState(we),{data:i,isLoading:x}=K({queryKey:["outreach-contacts-list",s,t],staleTime:3e4,refetchInterval:6e4,queryFn:async()=>{let a=q.from("outreach_targets").select("id, job_title, company, contact_name, contact_title, contact_linkedin_url, applied_at, created_at, job_url").order("created_at",{ascending:!1}).limit(t);s==="found"&&(a=a.not("contact_name","is",null));const{data:d,error:j}=await a;if(j)throw j;return d??[]}}),u=i??[];return e.jsxs(y,{className:"border-border",children:[e.jsxs(P,{className:"pb-3 flex flex-row items-center justify-between space-y-0",children:[e.jsxs(T,{className:"text-sm flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4 text-primary"}),"Jobs & contacts",e.jsx(C,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:x?"â":u.length})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(A,{size:"sm",variant:s==="found"?"default":"outline",className:"h-7 text-xs",onClick:()=>{c("found"),n(we)},children:"Found contacts"}),e.jsx(A,{size:"sm",variant:s==="all"?"default":"outline",className:"h-7 text-xs",onClick:()=>{c("all"),n(we)},children:"All checked"})]})]}),e.jsxs(w,{className:"space-y-2",children:[x&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loadingâ¦"}),!x&&u.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing here yet."}),u.map(a=>e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-lg border border-border p-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[a.job_url?e.jsxs("a",{href:a.job_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs font-medium truncate inline-flex items-center gap-1 hover:underline",children:[a.job_title||"Untitled role",e.jsx(Ee,{className:"h-3 w-3 shrink-0"})]}):e.jsx("p",{className:"text-xs font-medium truncate",children:a.job_title||"Untitled role"}),e.jsxs("p",{className:"text-[11px] text-muted-foreground truncate",children:[a.company||"Unknown company",a.applied_at&&` · ${new Date(a.applied_at).toLocaleDateString()}`]}),e.jsx(C,{variant:a.applied_at?"secondary":"outline",className:"mt-1 text-[10px] px-1.5 py-0",children:a.applied_at?"Applied":"Not applied yet"})]}),e.jsx("div",{className:"text-right shrink-0 max-w-[45%]",children:a.contact_name?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs font-medium truncate",children:a.contact_name}),a.contact_title&&e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:a.contact_title}),a.contact_linkedin_url&&e.jsxs("a",{href:a.contact_linkedin_url,target:"_blank",rel:"noopener noreferrer",className:"text-[11px] text-primary inline-flex items-center gap-1 hover:underline",children:["LinkedIn ",e.jsx(Ee,{className:"h-3 w-3"})]})]}):e.jsx(C,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"no contact"})})]},a.id)),u.length>=t&&e.jsx(A,{size:"sm",variant:"outline",className:"w-full",onClick:()=>n(a=>a+we),children:"Load more"})]})]})}function Zt(){const[s,c]=f.useState(null),[t,n]=f.useState(null),{data:i,isLoading:x,refetch:u,isFetching:a}=K({queryKey:["extension-adoption"],staleTime:6e4,queryFn:async()=>{const j=new Date(Date.now()-2592e6).toISOString(),[{data:h},{count:r}]=await Promise.all([q.from("extension_heartbeats").select("user_id,last_seen"),q.from("profiles").select("id",{count:"exact",head:!0}).not("extension_nudge_sent_at","is",null)]),l=new Map;
111(h||[]).forEach(o=>{const $=l.get(o.user_id);(!$||o.last_seen>$)&&l.set(o.user_id,o.last_seen)});let m=0,v=0;return l.forEach(o=>o>=j?m++:v++),{active:m,idle:v,nudged:r||0}}}),d=async j=>{n(j);try{const{data:h,error:r}=await q.functions.invoke("send-extension-nudge",{body:j==="send"?{action:"send",limit:200}:{action:"preview"}});if(r)throw r;j==="preview"?(c({count:h.count,recipients:h.recipients||[]}),_.success(`${h.count} accounts have no extension yet`)):(_.success(`Sent ${h.sent} install emails`),c(null),u())}catch(h){_.error((h==null?void 0:h.message)||"Request failed")}finally{n(null)}};return e.jsxs(y,{children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(hs,{className:"h-4 w-4"}),"Extension adoption",e.jsx(A,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>u(),disabled:a,children:e.jsx(J,{className:`h-3.5 w-3.5 ${a?"animate-spin":""}`})})]})}),e.jsxs(w,{className:"space-y-4",children:[x?e.jsx(H,{className:"h-16 rounded-md"}):e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Active (30d)"}),e.jsx("p",{className:"text-xl font-semibold",children:(i==null?void 0:i.active)??0})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Installed, idle"}),e.jsx("p",{className:"text-xl font-semibold",children:(i==null?void 0:i.idle)??0})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Already emailed"}),e.jsx("p",{className:"text-xl font-semibold",children:(i==null?void 0:i.nudged)??0})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>d("preview"),disabled:t!==null,children:"Preview recipients"}),e.jsxs(A,{size:"sm",className:"gap-2",onClick:()=>d("send"),disabled:t!==null||!s||s.count===0,children:[e.jsx(ze,{className:"h-4 w-4"}),s?`Send to ${s.count}`:"Send install email"]}),s&&e.jsxs(C,{variant:"outline",children:[s.count," without the extension"]})]}),s&&s.recipients.length>0&&e.jsx(z,{className:"h-40 rounded-md border p-2",children:e.jsx("ul",{className:"space-y-1 text-xs text-muted-foreground",children:s.recipients.map(j=>e.jsx("li",{children:j.email},j.email))})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each account is emailed at most once. Anyone who has used the extension or unsubscribed is skipped automatically."})]})]})}function Xt(){const[s,c]=f.useState("new_jobs"),[t,n]=f.useState(!1),{data:i,isLoading:x,refetch:u,isFetching:a}=K({queryKey:["daily-alert-stats"],staleTime:6e4,queryFn:async()=>{const{data:r,error:l}=await q.rpc("daily_alert_stats");if(l)throw l;return r||[]}}),d=f.useMemo(()=>{const r=[...i||[]];return r.sort((l,m)=>s==="email"?(l.email||"").localeCompare(m.email||""):(m[s]||0)-(l[s]||0)),r},[i,s]),j=f.useMemo(()=>{const r=i||[],l=r.filter(o=>o.eligible_today).length,m=r.filter(o=>o.last_sent_on&&o.local_time&&o.last_sent_on===o.local_time.slice(0,10)).length,v=r.filter(o=>!o.excluded&&(o.new_jobs||0)===0&&(o.auto_applied||0)===0).length;return{today:l,sentToday:m,nothingNew:v,users:r.length}},[i]),h=async()=>{var r;n(!0);try{const{data:l,error:m}=await q.functions.invoke("send-daily-job-alerts",{body:{action:"test"}});if(m)throw m;_.success(l!=null&&l.sent?"Test alert sent to your inbox":"Send skipped (address suppressed)")}catch(l){const m=((r=l==null?void 0:l.context)==null?void 0:r.responseBody)||(l==null?void 0:l.message)||"";let v=null;try{v=JSON.parse(m)}catch{v=null}const o=v==null?void 0:v.code,$=(v==null?void 0:v.error)||m||"Test send failed";o==="missing_unsubscribe"||$.includes("migrating to Lovable-managed")?_.error("Email migration needs publish. Publish the app, then retry this test.",{duration:6e3}):_.error($.slice(0,200))}finally{n(!1)}};return e.jsxs(y,{children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(et,{className:"h-4 w-4"}),"Daily alerts",e.jsx(A,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>u(),disabled:a,children:e.jsx(J,{className:`h-3.5 w-3.5 ${a?"animate-spin":""}`})})]})}),e.jsxs(w,{className:"space-y-4",children:[x?e.jsx(H,{className:"h-16 rounded-md"}):e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Users"}),e.jsx("p",{className:"text-xl font-semibold",children:j.users})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Eligible now"}),e.jsx("p",{className:"text-xl font-semibold",children:j.today})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Emailed today"}),e.jsx("p",{className:"text-xl font-semibold",children:j.sentToday})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing new"}),e.jsx("p",{className:"text-xl font-semibold",children:j.nothingNew})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["new_jobs","high_fit","auto_applied","email"].map(r=>e.jsx(A,{size:"sm",variant:s===r?"default":"outline",onClick:()=>c(r),children:r==="new_jobs"?"New jobs":r==="high_fit"?"80%+ fit":r==="auto_applied"?"AutoApplied":"Email"},r)),e.jsxs(A,{size:"sm",className:"gap-2 ml-auto",onClick:h,disabled:t,children:[e.jsx(ze,{className:"h-4 w-4"}),"Send test to me"]})]}),e.jsx(z,{className:"h-72 rounded-md border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-muted/60",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"p-2 font-medium",children:"User"}),e.jsx("th",{className:"p-2 font-medium",children:"Local time"}),e.jsx("th",{className:"p-2 font-medium text-right",children:"New"}),e.jsx("th",{className:"p-2 font-medium text-right",children:"80%+"}),e.jsx("th",{className:"p-2 font-medium text-right",children:"Applied"}),e.jsx("th",{className:"p-2 font-medium",children:"Status"}),e.jsx("th",{className:"p-2 font-medium",children:"Last sent"})]})}),e.jsx("tbody",{children:d.map(r=>e.jsxs("tr",{className:"border-t",children:[e.jsxs("td",{className:"p-2",children:[e.jsx("div",{className:"font-medium",children:r.full_name||"â"}),e.jsx("div",{className:"text-muted-foreground",children:r.email})]}),e.jsxs("td",{className:"p-2 text-muted-foreground",children:[r.local_time?r.local_time.slice(11,16):"â",e.jsx("div",{children:r.timezone})]}),e.jsx("td",{className:"p-2 text-right",children:r.new_jobs??0}),e.jsx("td",{className:"p-2 text-right",children:r.high_fit??0}),e.jsx("td",{className:"p-2 text-right",children:r.auto_applied??0}),e.jsx("td",{className:"p-2",children:r.excluded?e.jsx(C,{variant:"outline",children:"Excluded"}):r.eligible_today?e.jsx(C,{variant:"outline",children:"Eligible"}):e.jsx(C,{variant:"outline",children:"Skip"})}),e.jsx("td",{className:"p-2 text-muted-foreground",children:r.last_sent_on||"â"})]},r.user_id))})]})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each person gets at most one alert a day, at 11 AM their local time, and only when there are new jobs or AutoApplied jobs from the last 24 hours."})]})]})}function Yt(){const[s,c]=f.useState(null),[t,n]=f.useState(10),[i,x]=f.useState(null),u=async(d,j=!1)=>{c(d),x(null);try{const{data:h,error:r}=await q.functions.invoke("admin-repair-searches",{body:{mode:d,limit:t,dry_run:j}});if(r)throw r;if(h!=null&&h.error)throw new Error(h.error);x(h);const l=(h==null?void 0:h.flagged)??(h==null?void 0:h.processed)??0;_.success(`${d}: ${l} search${l===1?"":"es"}`)}catch(h){_.error((h==null?void 0:h.message)||"Repair run failed")}finally{c(null)}},a=(i==null?void 0:i.rows)||(i==null?void 0:i.results)||[];return e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(Ye,{className:"h-4 w-4"}),"Search repair"]})}),e.jsxs(w,{className:"space-y-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fixes searches that cancel themselves out, splits multi-city location text, corrects title typos, and widens searches with AI job titles from each user's resume."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Batch"}),e.jsx(U,{type:"number",min:1,max:100,value:t,onChange:d=>n(Math.max(1,Math.min(100,Number(d.target.value)||1))),className:"h-8 w-20"})]}),e.jsxs(A,{size:"sm",variant:"outline",disabled:!!s,onClick:()=>u("audit"),children:[s==="audit"?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin mr-1"}):e.jsx(ot,{className:"h-3.5 w-3.5 mr-1"}),"Audit"]}),e.jsxs(A,{size:"sm",variant:"outline",disabled:!!s,onClick:()=>u("sanitize"),children:[s==="sanitize"?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin mr-1"}):e.jsx(Ye,{className:"h-3.5 w-3.5 mr-1"}),"Sanitize"]}),e.jsxs(A,{size:"sm",variant:"outline",disabled:!!s,onClick:()=>u("expand"),children:[s==="expand"?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin mr-1"}):e.jsx(js,{className:"h-3.5 w-3.5 mr-1"}),"Add AI titles"]}),e.jsxs(A,{size:"sm",variant:"outline",disabled:!!s,onClick:()=>u("reparse"),children:[s==="reparse"?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin mr-1"}):e.jsx(Js,{className:"h-3.5 w-3.5 mr-1"}),"Re-parse resumes"]}),e.jsxs(A,{size:"sm",variant:"outline",disabled:!!s,onClick:()=>u("verify"),children:[s==="verify"?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin mr-1"}):e.jsx(tt,{className:"h-3.5 w-3.5 mr-1"}),"Verify (run now)"]})]}),a.length>0&&e.jsx("div",{className:"max-h-80 overflow-y-auto space-y-2",children:a.map((d,j)=>{var h,r,l;return e.jsxs("div",{className:"rounded-md border border-border p-2 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:d.email}),d.error?e.jsx(C,{variant:"outline",className:"text-destructive border-destructive/40",children:"error"}):d.skipped?e.jsx(C,{variant:"outline",children:d.skipped}):typeof d.staged=="number"?e.jsxs(C,{variant:"outline",children:[d.staged," new / ",d.cards_foun
111d," found"]}):null]}),((h=d.issues)==null?void 0:h.length)>0&&e.jsx("ul",{className:"mt-1 list-disc pl-4 text-muted-foreground",children:d.issues.map((m,v)=>e.jsx("li",{children:m},v))}),((r=d.changes)==null?void 0:r.length)>0&&e.jsx("ul",{className:"mt-1 list-disc pl-4 text-muted-foreground",children:d.changes.map((m,v)=>e.jsx("li",{children:m},v))}),((l=d.added)==null?void 0:l.length)>0&&e.jsxs("p",{className:"mt-1 text-muted-foreground",children:["Added: ",d.added.join(", ")]}),d.error&&e.jsx("p",{className:"mt-1 text-destructive",children:d.error})]},d.id||j)})}),i&&a.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing to report for this run."})]})]})}const ea=10*1024*1024*1024;function Te(s){return s==null?"unknown":s>=1024**3?`${(s/1024**3).toFixed(2)} GB`:s>=1024**2?`${(s/1024**2).toFixed(1)} MB`:`${Math.max(1,Math.round(s/1024))} kB`}function sa(){const[s,c]=f.useState(null),[t,n]=f.useState(!1),[i,x]=f.useState(null),u=f.useCallback(async()=>{n(!0),x(null);try{const{data:h,error:r}=await q.rpc("get_storage_health");if(r)throw r;c(h)}catch(h){x((h==null?void 0:h.message)||"Could not load storage health")}finally{n(!1)}},[]);f.useEffect(()=>{u()},[u]);const a=((s==null?void 0:s.db_bytes)??0)+((s==null?void 0:s.wal_bytes)??0),d=s?Math.round(a/ea*100):null,j=d==null?"ok":d>=85?"critical":d>=70?"warn":"ok";return e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(it,{className:"h-4 w-4"}),"Storage health",e.jsx("div",{className:"ml-auto",children:e.jsx(A,{size:"sm",variant:"ghost",disabled:t,onClick:u,children:t?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(J,{className:"h-3.5 w-3.5"})})})]})}),e.jsxs(w,{className:"space-y-3",children:[i&&e.jsx("p",{className:"text-xs text-destructive",children:i}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[e.jsxs(C,{variant:"outline",children:["Data ",Te(s.db_bytes)]}),e.jsxs(C,{variant:"outline",children:["Transaction log ",Te(s.wal_bytes)]}),d!=null&&e.jsxs(C,{variant:"outline",className:j==="critical"?"text-destructive border-destructive/40":j==="warn"?"text-amber-600 border-amber-500/40":"",children:["~",d,"% of 10 GB disk"]})]}),j!=="ok"&&e.jsxs("div",{className:`flex items-start gap-2 rounded-md border p-2 text-xs ${j==="critical"?"border-destructive/40 text-destructive":"border-amber-500/40 text-amber-600"}`,children:[e.jsx(Fe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsxs("span",{children:["Disk usage is ",j==="critical"?"critically high":"climbing"," â check the largest tables below and the last cleanup run."]})]}),e.jsxs("div",{className:"text-xs",children:[e.jsx("p",{className:"text-muted-foreground mb-1",children:"Largest tables"}),e.jsx("div",{className:"space-y-1",children:s.top_tables.map(h=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate",children:h.tbl}),e.jsx("span",{className:"text-muted-foreground shrink-0",children:Te(h.bytes)})]},h.tbl))})]}),e.jsxs("div",{className:"text-xs text-muted-foreground border-t border-border pt-2 space-y-0.5",children:[s.last_prune?e.jsxs("p",{children:["Last nightly cleanup: ",new Date(s.last_prune.ran_at).toLocaleString()," â"," ",s.last_prune.status]}):e.jsx("p",{children:"No successful cleanup run recorded yet."}),e.jsxs("p",{children:["Measured ",new Date(s.measured_at).toLocaleTimeString()]})]})]}),!s&&!i&&!t&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No data yet."})]})]})}function ke({value:s,label:c}){return e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("p",{className:"text-2xl font-semibold tabular-nums",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:c})]})}function ta(){const[s,c]=f.useState(null),[t,n]=f.useState(!1),[i,x]=f.useState(null),u=f.useCallback(async()=>{n(!0),x(null);try{const{data:a,error:d}=await q.rpc("get_pipeline_backlog");if(d)throw d;c(a)}catch(a){x((a==null?void 0:a.message)||"Could not load backlog")}finally{n(!1)}},[]);return f.useEffect(()=>{u();const a=setInterval(u,6e4);return()=>clearInterval(a)},[u]),e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Enrichment & scoring backlog",e.jsx("div",{className:"ml-auto",children:e.jsx(A,{size:"sm",variant:"ghost",disabled:t,onClick:u,children:t?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(J,{className:"h-3.5 w-3.5"})})})]})}),e.jsxs(w,{className:"space-y-3",children:[i&&e.jsx("p",{className:"text-xs text-destructive",children:i}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx(ke,{value:s.eligible_for_score,label:"Awaiting score"}),e.jsx(ke,{value:s.need_enrichment,label:"Missing description"}),e.jsx(ke,{value:s.users_with_backlog,label:"Users w/ backlog"}),e.jsx(ke,{value:s.gave_up,label:"Unreadable (retries used up)"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground border-t border-border pt-2 space-y-0.5",children:[e.jsxs("p",{children:["Last hour: ",s.enriched_last_hour," descriptions fetched, ",s.scored_last_hour," jobs scored."]}),e.jsxs("p",{children:["Measured ",new Date(s.measured_at).toLocaleTimeString()]})]})]}),!s&&!i&&!t&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No data yet."})]})]})}function aa(){const[s,c]=f.useState(null),[t,n]=f.useState(!1),i=async()=>{n(!0);try{const{data:x,error:u}=await q.rpc("get_auto_apply_funnel",{_days:7});if(u)throw u;c(x||[])}catch(x){_.error((x==null?void 0:x.message)||"Could not load the funnel")}finally{n(!1)}};return e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(nt,{className:"h-4 w-4"}),"Auto-apply funnel (7 days)"]}),e.jsxs(A,{size:"sm",variant:"outline",disabled:t,onClick:i,children:[t?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin mr-1"}):e.jsx(J,{className:"h-3.5 w-3.5 mr-1"}),"Load"]}
111)]})}),e.jsxs(w,{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Per user: jobs found, how many are LinkedIn (never auto-applied), how many are on supported boards, how many score 65+, how many are still fresh, how many are fully eligible, and how many were applied."}),s&&s.length>0&&e.jsx("div",{className:"max-h-96 overflow-auto rounded-md border border-border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-muted/60",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-2 py-1.5 font-medium",children:"User"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"Found"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"LinkedIn"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"Supported"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"65+"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"Fresh"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"Eligible"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"Applied"}),e.jsx("th",{className:"px-2 py-1.5 font-medium text-right",children:"Avg"})]})}),e.jsx("tbody",{children:s.map(x=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-2 py-1.5 truncate max-w-[200px]",children:x.email}),e.jsx("td",{className:"px-2 py-1.5 text-right",children:x.found}),e.jsx("td",{className:"px-2 py-1.5 text-right text-muted-foreground",children:x.linkedin}),e.jsx("td",{className:"px-2 py-1.5 text-right",children:x.supported}),e.jsx("td",{className:"px-2 py-1.5 text-right",children:x.scored}),e.jsx("td",{className:"px-2 py-1.5 text-right",children:x.fresh}),e.jsx("td",{className:"px-2 py-1.5 text-right font-medium",children:x.eligible}),e.jsx("td",{className:"px-2 py-1.5 text-right font-medium",children:x.applied}),e.jsx("td",{className:"px-2 py-1.5 text-right text-muted-foreground",children:x.avg_score})]},x.email))})]})}),s&&s.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No jobs found in the last 7 days."})]})]})}function _e({value:s,label:c}){return e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("p",{className:"text-2xl font-semibold tabular-nums",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:c})]})}function qe({on:s}){return e.jsx("span",{className:s?"text-primary":"text-muted-foreground/40",children:s?"â":"â"})}function ra(){const[s,c]=f.useState(null),[t,n]=f.useState(!1),[i,x]=f.useState(!1),u=f.useCallback(async()=>{n(!0);try{const{data:l,error:m}=await q.rpc("get_plan_usage_overview");if(m)throw m;c(l||[])}catch(l){_.error((l==null?void 0:l.message)||"Could not load plan usage")}finally{n(!1)}},[]);f.useEffect(()=>{u()},[u]);const a=async l=>{x(!0);try{const{data:m,error:v}=await q.functions.invoke("send-usage-emails",{body:{action:"test",threshold:l}});if(v)throw v;_.success(m!=null&&m.sent?`Test ${l}% email sent to you`:"Send was suppressed")}catch(m){_.error((m==null?void 0:m.message)||"Could not send the test email")}finally{x(!1)}},d=(s||[]).filter(l=>!l.dev_mode),j=d.filter(l=>l.pct>=50).length,h=d.filter(l=>l.pct>=80).length,r=d.filter(l=>l.pct>=100).length;return e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"pb-3",children:e.jsxs(T,{className:"text-base flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Zs,{className:"h-4 w-4"}),"Plan usage & upgrade emails"]}),e.jsx(A,{size:"sm",variant:"ghost",disabled:t,onClick:u,children:t?e.jsx(B,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(J,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(w,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx(_e,{value:d.length,label:"Users with usage"}),e.jsx(_e,{value:j,label:"Over 50%"}),e.jsx(_e,{value:h,label:"Over 80%"}),e.jsx(_e,{value:r,label:"Capped (paused)"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(ze,{className:"h-3.5 w-3.5"})," Send test to me:"]}),[50,80,100].map(l=>e.jsxs(A,{size:"sm",variant:"outline",disabled:i,onClick:()=>a(l),children:[l,"%"]},l))]}),s&&s.length>0&&e.jsx("div",{className:"max-h-96 overflow-auto rounded-md border border-border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-muted/50 sticky top-0",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"p-2 font-medium",children:"User"}),e.jsx("th",{className:"p-2 font-medium text-right",children:"Used"}),e.jsx("th",{className:"p-2 font-medium text-right",children:"%"}),e.jsx("th",{className:"p-2 font-medium",children:"Resets"}),e.jsx("th",{className:"p-2 font-medium text-center",children:"50"}),e.jsx("th",{className:"p-2 font-medium text-center",children:"80"}),e.jsx("th",{className:"p-2 font-medium text-center",children:"100"})]})}),e.jsx("tbody",{children:s.map(l=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsxs("td",{className:"p-2 truncate max-w-[200px]",children:[l.email,l.dev_mode&&e.jsx("span",{className:"ml-1 text-muted-foreground",children:"(dev)"})]}),e.jsxs("td",{className:"p-2 text-right tabular-nums",children:[l.used,"/",l.monthly_limit]}),e.jsxs("td",{className:`p-2 text-right tabular-nums ${l.pct>=100?"text-destructive font-medium":""}`,children:[l.pct,"%"]}),e.jsx("td",{className:"p-2 whitespace-nowrap",children:new Date(`${l.cycle_end}T00:00:00`).toLocaleDateString()}),e.jsx("td",{className:"p-2 text-center",children:e.jsx(qe,{on:l.sent_half})}),e.jsx("td",{className:"p-2 text-center",children:e.jsx(qe,{on:l.sent_almost})}),e.jsx("td",{className:"p-2 text-center",children:e.jsx(qe,{on:l.sent_limit})})]},l.user_id))})]})}),s&&s.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No usage this cycle yet."})]})]})}function ma(){const{data:s,isLoading:c}
111=pt(),{data:t,isFetching:n,refetch:i}=gt(),x=ft(),u=Nt(),[a,d]=f.useState("all");if(c)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Array.from({length:4}).map((g,M)=>e.jsx(H,{className:"h-24 rounded-lg"},M))}),e.jsx(H,{className:"h-64 rounded-lg"})]});if(!s)return e.jsx("p",{className:"text-muted-foreground text-sm",children:"Failed to load admin data."});const{userStats:j,appStats:h,atsBreakdown:r,recentFieldLogs:l,totalFieldErrors:m,perUser:v,recentSignups:o=[],recentRuns:$=[],runHealth:R,scoringSweepHealth:k,cleanupHealth:S,funnelHealth:Ae}=s,$s=h.totalApplied+h.totalFailed>0?(h.totalFailed/(h.totalApplied+h.totalFailed)*100).toFixed(1):"0",Ps=[{label:"Total Users",value:j.totalUsers,icon:me,color:"text-primary"},{label:"Active (7d)",value:j.activeUsers7d,icon:Ys,color:"text-[hsl(var(--success))]"},{label:"Total Applied",value:h.totalApplied,icon:oe,color:"text-[hsl(var(--success))]"},{label:"Error Rate",value:`${$s}%`,icon:Fe,color:"text-destructive"}],Re=$.filter(g=>a==="errors"?g.status==="error":a==="cron"?g.trigger==="cron":a==="manual"?g.trigger==="manual":!0),Ts=g=>{const b={success:{cls:"bg-[hsl(var(--success))]/15 text-[hsl(var(--success))] border-[hsl(var(--success))]/30",label:"success"},partial:{cls:"bg-warning/15 text-warning border-warning/30",label:"partial"},error:{cls:"bg-destructive/15 text-destructive border-destructive/30",label:"error"},running:{cls:"bg-primary/15 text-primary border-primary/30",label:"running"}}[g]||{cls:"bg-muted text-muted-foreground border-border",label:g};return e.jsx(C,{variant:"outline",className:`text-[10px] px-1.5 py-0 ${b.cls}`,children:b.label})};return e.jsx("div",{className:"space-y-4",children:e.jsxs(ms,{defaultValue:"overview",className:"w-full",children:[e.jsxs(us,{className:"grid w-full grid-cols-5 max-w-3xl",children:[e.jsx(Y,{value:"overview",children:"Overview"}),e.jsxs(Y,{value:"autoapply",children:[e.jsx(gs,{className:"h-3 w-3 mr-1"}),"Auto Apply"]}),e.jsxs(Y,{value:"discovery",children:[e.jsx(xt,{className:"h-3.5 w-3.5 mr-1.5"}),"Discovery Runs"]}),e.jsxs(Y,{value:"funnel",children:[e.jsx(ct,{className:"h-3.5 w-3.5 mr-1.5"}),"Funnel Health",(Ae==null?void 0:Ae.status)==="auth_expired"&&e.jsx("span",{className:"ml-1.5 inline-block h-1.5 w-1.5 rounded-full bg-destructive"})]}),e.jsxs(Y,{value:"intelligence",children:[e.jsx(De,{className:"h-3.5 w-3.5 mr-1.5"}),"Intelligence"]})]}),e.jsxs(ee,{value:"overview",className:"space-y-4 mt-4",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Ps.map(g=>e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:g.label}),e.jsx(g.icon,{className:`h-4 w-4 ${g.color}`})]}),e.jsx("p",{className:"text-2xl font-bold",children:g.value})]})},g.label))}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Signups (7d)"}),e.jsx("p",{className:"text-xl font-bold mt-1",children:j.signupsLast7d})]})}),e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Failed Jobs"}),e.jsx("p",{className:"text-xl font-bold mt-1 text-destructive",children:h.totalFailed})]})}),e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Field Errors"}),e.jsx("p",{className:"text-xl font-bold mt-1 text-destructive",children:m})]})})]}),e.jsxs(y,{className:"border-border",children:[e.jsxs(P,{className:"py-3 px-4 flex-row items-center justify-between space-y-0",children:[e.jsx(T,{className:"text-sm font-semibold",children:"Recent Signups"}),e.jsxs(C,{variant:"secondary",className:"text-xs",children:["Last ",o.length]})]}),e.jsx(w,{className:"p-0",children:e.jsx(z,{className:"h-72",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{className:"text-xs",children:"Email"}),e.jsx(N,{className:"text-xs text-right",children:"Signed up"})]})}),e.jsxs(G,{children:[o.map(g=>e.jsxs(E,{children:[e.jsx(p,{className:"text-xs font-medium truncate max-w-[280px]",children:g.email||"â"}),e.jsx(p,{className:"text-xs text-right text-muted-foreground",children:g.created_at?L(new Date(g.created_at),{addSuffix:!0}):"â"})]},g.id)),o.length===0&&e.jsx(E,{children:e.jsx(p,{colSpan:2,className:"text-center text-xs text-muted-foreground py-6",children:"No signups yet"})})]})]})})})]}),e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"py-3 px-4",children:e.jsx(T,{className:"text-sm font-semibold",children:"ATS Breakdown"})}),e.jsx(w,{className:"p-0",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{className:"text-xs",children:"ATS"}),e.jsx(N,{className:"text-xs text-right",children:"Total"}),e.jsx(N,{className:"text-xs text-right",children:"Applied"}),e.jsx(N,{className:"text-xs text-right",children:"Failed"}),e.jsx(N,{className:"text-xs text-right",children:"Success %"})]})}),e.jsx(G,{children:Object.entries(r).sort(([,g],[,M])=>M.total-g.total).map(([g,M])=>e.jsxs(E,{children:[e.jsx(p,{className:"text-xs font-medium capitalize",children:g}),e.jsx(p,{className:"text-xs text-right",children:M.total}),e.jsx(p,{className:"text-xs text-right text-[hsl(var(--success))]",children:M.applied}),e.jsx(p,{className:"text-xs text-right text-destructive",children:M.failed}),e.jsxs(p,{className:"text-xs text-right",children:[M.applied+M.failed>
1110?(M.applied/(M.applied+M.failed)*100).toFixed(0):"â","%"]})]},g))})]})})]}),e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"py-3 px-4",children:e.jsx(T,{className:"text-sm font-semibold",children:"Per-User Activity"})}),e.jsx(w,{className:"p-0",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{className:"text-xs",children:"Email"}),e.jsx(N,{className:"text-xs text-right",children:"Applied"}),e.jsx(N,{className:"text-xs text-right",children:"Errors"}),e.jsx(N,{className:"text-xs text-right",children:"Last Active"})]})}),e.jsxs(G,{children:[v.map(g=>e.jsxs(E,{children:[e.jsx(p,{className:"text-xs font-medium truncate max-w-[200px]",children:g.email}),e.jsx(p,{className:"text-xs text-right",children:g.totalApps}),e.jsx(p,{className:"text-xs text-right text-destructive",children:g.errors}),e.jsx(p,{className:"text-xs text-right text-muted-foreground",children:g.lastActive?L(new Date(g.lastActive),{addSuffix:!0}):"â"})]},g.user_id)),v.length===0&&e.jsx(E,{children:e.jsx(p,{colSpan:4,className:"text-center text-xs text-muted-foreground py-6",children:"No activity yet"})})]})]})})]}),e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"py-3 px-4",children:e.jsx(T,{className:"text-sm font-semibold",children:"Recent Field Logs (All Users)"})}),e.jsx(w,{className:"p-0",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{className:"text-xs",children:"Company"}),e.jsx(N,{className:"text-xs",children:"Job"}),e.jsx(N,{className:"text-xs",children:"ATS"}),e.jsx(N,{className:"text-xs",children:"Outcome"}),e.jsx(N,{className:"text-xs",children:"Error"}),e.jsx(N,{className:"text-xs text-right",children:"When"})]})}),e.jsxs(G,{children:[l.map(g=>e.jsxs(E,{children:[e.jsx(p,{className:"text-xs truncate max-w-[120px]",children:g.company||"â"}),e.jsx(p,{className:"text-xs truncate max-w-[150px]",children:g.job_title||"â"}),e.jsx(p,{className:"text-xs capitalize",children:g.ats_type||"â"}),e.jsx(p,{className:"text-xs",children:g.outcome||"â"}),e.jsx(p,{className:"text-xs text-destructive truncate max-w-[150px]",children:g.error_text||""}),e.jsx(p,{className:"text-xs text-right text-muted-foreground",children:g.created_at?L(new Date(g.created_at),{addSuffix:!0}):"â"})]},g.id)),l.length===0&&e.jsx(E,{children:e.jsx(p,{colSpan:6,className:"text-center text-xs text-muted-foreground py-6",children:"No logs yet"})})]})]})})]})]}),e.jsxs(ee,{value:"autoapply",className:"space-y-4 mt-4",children:[e.jsx(Vt,{}),e.jsx(Zt,{}),e.jsx(Xt,{}),e.jsx(Ht,{}),e.jsx(Jt,{})]}),e.jsxs(ee,{value:"discovery",className:"space-y-4 mt-4",children:[e.jsx(ta,{}),e.jsx(aa,{}),e.jsx(ra,{}),e.jsx(Yt,{}),e.jsx(sa,{}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3",children:[e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Success (24h)"}),e.jsx(oe,{className:"h-4 w-4 text-[hsl(var(--success))]"})]}),e.jsx("p",{className:"text-2xl font-bold text-[hsl(var(--success))]",children:(R==null?void 0:R.success)??0})]})}),e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Partial (24h)"}),e.jsx(Fe,{className:"h-4 w-4 text-warning"})]}),e.jsx("p",{className:"text-2xl font-bold text-warning",children:(R==null?void 0:R.partial)??0})]})}),e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Errors (24h)"}),e.jsx(ps,{className:"h-4 w-4 text-destructive"})]}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:(R==null?void 0:R.error)??0})]})}),e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Enrolled"}),e.jsx(me,{className:"h-4 w-4 text-primary"})]}),e.jsx("p",{className:"text-2xl font-bold",children:(R==null?void 0:R.enrolledUsers)??0})]})}),e.jsx(y,{className:"border-border",children:e.jsxs(w,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Never Run"}),e.jsx(Me,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("p",{className:"text-2xl font-bold",children:(R==null?void 0:R.neverRun)??0})]})})]}),e.jsxs(y,{className:"border-border",children:[e.jsxs(P,{className:"py-3 px-4 flex-row items-center justify-between space-y-0",children:[e.jsxs(T,{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(js,{className:"h-3.5 w-3.5 text-primary"}),"Scoring Sweep Health",k&&k.errors24h>0&&e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-destructive"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:k!=null&&k.lastRunAt?`Last run: ${L(new Date(k.lastRunAt),{addSuffix:!0})}`:"No sweeps yet"})]}),e.jsxs(w,{className:"p-4 pt-0 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Eligible"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${k&&k.eligibleUnscored>50?"text-warning":""}`,children:(k==null?void 0:k.eligibleUnscored)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"have description, awaiting score"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Need enrichment"}),e.jsx("p",{className:"text-xl font-bold mt-1",children:(k==null?void 0:k.blockedUnscored)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"missing description"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Users w/ backlog"}),e.jsx("p",{className:"text-xl font-bold mt-1",children:(k==null?void 0:k.usersWithBacklog)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"distinct users"})]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Runs (24h)"}),e.jsx("p",{className:"text-xl font-bold mt-1",children:(k==null?void 0:k.runs24h)??0})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Enriched (24h)"}),e.jsx("p",{className:"text-xl font-bold mt-1 text-primary",children:(k==null?void 0:k.jobsEnriched24h)??0})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Scored (24h)"}),e.jsx("p",{className:"text-xl font-bold mt-1 text-[hsl(var(--success))]",children:(k==null?void 0:k.jobsScored24h)??0})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Errors (24h)"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${k&&k.errors24h>0?"text-destructive":""}`,children:(k==null?void 0:k.errors24h)??0})]})]})]})]}),(()=>{const g=S!=null&&S.lastRunAt?Date.now()-new Date(S.lastRunAt).getTime()>1296e5:!0,M=S&&S.over14d>0&&g;return e.jsxs(y,{className:"border-border",children:[e.jsxs(P,{className:"py-3 px-4 flex-row items-center justify-between space-y-0",children:[e.jsxs(T,{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(Pe,{className:"h-3.5 w-3.5 text-primary"}),"Cleanup Health",M&&e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-destructive"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:S!=null&&S.lastRunAt?`Last run: ${L(new Date(S.lastRunAt),{addSuffix:!0})}`:"No runs yet"})]}),e.jsxs(w,{className:"px-4 pb-4 pt-0 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:[e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Schedule"}),e.jsx("p",{className:"text-sm font-semibold mt-1",children:(S==null?void 0:S.schedule)??"Daily 20:00 UTC"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:S!=null&&S.lastStatus?e.jsxs(e.Fragment,{children:["Last status: ",e.jsx("span",{className:S.lastStatus==="succeeded"?"text-[hsl(var(--success))]":"text-destructive",children:S.lastStatus})]}):"no status"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Discovered total"}),e.jsx("p",{className:"text-xl font-bold mt-1",children:(S==null?void 0:S.discoveredTotal)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"rows in queue"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Runs (7d)"}),e.jsx("p",{className:"text-xl font-bold mt-1",children:(S==null?void 0:S.runs7d)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"successful sweeps"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Over 14 days"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${S&&S.over14d>0?"text-warning":""}
111`,children:(S==null?void 0:S.over14d)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"deleted on next sweep"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Per-user cap excess"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${S&&S.perUserCapExcess>0?"text-warning":""}`,children:(S==null?void 0:S.perUserCapExcess)??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"rows above 200/user"})]})]})]})]})})(),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[["all","errors","cron","manual"].map(g=>e.jsx(A,{size:"sm",variant:a===g?"default":"outline",className:"h-7 text-xs capitalize",onClick:()=>d(g),children:g},g)),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:["Showing ",Re.length," of ",$.length]})]}),e.jsxs(y,{className:"border-border",children:[e.jsx(P,{className:"py-3 px-4",children:e.jsx(T,{className:"text-sm font-semibold",children:"Recent Discovery Runs"})}),e.jsx(w,{className:"p-0",children:e.jsx(z,{className:"max-h-[600px]",children:e.jsxs(W,{children:[e.jsx(Q,{children:e.jsxs(E,{children:[e.jsx(N,{className:"text-xs",children:"When"}),e.jsx(N,{className:"text-xs",children:"User"}),e.jsx(N,{className:"text-xs",children:"Trigger"}),e.jsx(N,{className:"text-xs",children:"Status"}),e.jsx(N,{className:"text-xs",children:"Search"}),e.jsx(N,{className:"text-xs text-right",children:"Cards"}),e.jsx(N,{className:"text-xs text-right",children:"New"}),e.jsx(N,{className:"text-xs text-right",children:"Dup"}),e.jsx(N,{className:"text-xs text-right",children:"Skip"}),e.jsx(N,{className:"text-xs text-right",children:"Duration"}),e.jsx(N,{className:"text-xs",children:"Error"})]})}),e.jsxs(G,{children:[Re.map(g=>e.jsxs(E,{children:[e.jsx(p,{className:"text-xs text-muted-foreground whitespace-nowrap",children:L(new Date(g.started_at),{addSuffix:!0})}),e.jsx(p,{className:"text-xs truncate max-w-[160px]",title:g.user_email,children:g.user_email}),e.jsx(p,{className:"text-xs capitalize",children:g.trigger}),e.jsx(p,{children:Ts(g.status)}),e.jsx(p,{className:"text-xs truncate max-w-[160px]",title:g.search_name||"",children:g.search_name||"â"}),e.jsx(p,{className:"text-xs text-right",children:g.cards_found}),e.jsx(p,{className:"text-xs text-right text-[hsl(var(--success))] font-medium",children:g.jobs_inserted}),e.jsx(p,{className:"text-xs text-right text-muted-foreground",children:g.duplicates}),e.jsx(p,{className:"text-xs text-right text-muted-foreground",children:g.unsupported}),e.jsx(p,{className:"text-xs text-right text-muted-foreground",children:g.duration_ms?`${(g.duration_ms/1e3).toFixed(1)}s`:"â"}),e.jsx(p,{className:"text-xs text-destructive truncate max-w-[200px]",title:g.error_message||"",children:g.error_message||""})]},g.id)),Re.length===0&&e.jsx(E,{children:e.jsx(p,{colSpan:11,className:"text-center text-xs text-muted-foreground py-6",children:"No runs match this filter"})})]})]})})})]})]}),e.jsx(ee,{value:"funnel",className:"space-y-4 mt-4",children:(()=>{var g,M;return e.jsxs(y,{className:"border-border",children:[e.jsxs(P,{className:"py-3 px-4 flex-row items-center justify-between space-y-0",children:[e.jsxs(T,{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(Ie,{className:"h-3.5 w-3.5 text-primary"}),"Resolver Health",e.jsx("span",{className:"text-[10px] text-muted-foreground font-normal font-mono",children:"resolver.applykick.com"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-end",children:[e.jsxs(Ke,{children:[e.jsx(We,{asChild:!0,children:e.jsxs(A,{size:"sm",variant:"outline",className:"h-7 text-xs text-destructive hover:text-destructive",disabled:x.isPending,children:[e.jsx(Pe,{className:`h-3.5 w-3.5 mr-1.5 ${x.isPending?"animate-pulse":""}`}),"Wipe queue"]})}),e.jsxs(Qe,{children:[e.jsxs(Ge,{children:[e.jsx(Ve,{children:"Wipe funnel queue?"}),e.jsxs(He,{children:["This deletes all pending, resolved, and failed funnel rows",t!=null&&t.queue?` (${t.queue.pending}
111 pending · ${t.queue.resolved} resolved · ${t.queue.failed} failed)`:"",". Promoted rows are kept as the audit trail for the job queue. This cannot be undone."]})]}),e.jsxs(Je,{children:[e.jsx(Ze,{children:"Cancel"}),e.jsx(Xe,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{x.mutate(void 0,{onSuccess:b=>_.success(`Wiped ${b.deleted} funnel row${b.deleted===1?"":"s"}`),onError:b=>_.error(`Wipe failed: ${b.message}`)})},children:"Delete"})]})]})]}),e.jsx(Bt,{}),e.jsxs(A,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>{i()},disabled:n,children:[e.jsx(J,{className:`h-3.5 w-3.5 mr-1.5 ${n?"animate-spin":""}`}),"Re-check"]})]})]}),e.jsxs(w,{className:"px-4 pb-4 pt-0 space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-semibold",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-primary"}),"Promoted to Discover"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[((g=t==null?void 0:t.easyApply)==null?void 0:g.length)??0," jobs · ",((M=t==null?void 0:t.easyApply)==null?void 0:M.filter(b=>b.inDiscover).length)??0," in Discover"]}),e.jsxs(Ke,{children:[e.jsx(We,{asChild:!0,children:e.jsxs(A,{size:"sm",variant:"outline",className:"h-6 text-[11px] text-destructive hover:text-destructive px-2",disabled:u.isPending,children:[e.jsx(Pe,{className:`h-3 w-3 mr-1 ${u.isPending?"animate-pulse":""}`}),"Wipe"]})}),e.jsxs(Qe,{children:[e.jsxs(Ge,{children:[e.jsx(Ve,{children:"Wipe Discover tracking?"}),e.jsxs(He,{children:["This clears the resolved & promoted funnel rows that back this list",t!=null&&t.queue?` (${t.queue.resolved} resolved · ${t.queue.promoted} promoted)`:"",". It does not remove jobs already in the Discover queue. This cannot be undone."]})]}),e.jsxs(Je,{children:[e.jsx(Ze,{children:"Cancel"}),e.jsx(Xe,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{u.mutate(void 0,{onSuccess:b=>_.success(`Wiped ${b.deleted} tracking row${b.deleted===1?"":"s"}`),onError:b=>_.error(`Wipe failed: ${b.message}`)})},children:"Delete"})]})]})]})]})]}),(()=>{const b=(t==null?void 0:t.easyApply)??[];if(b.length===0)return e.jsx("p",{className:"text-[11px] text-muted-foreground py-2",children:"No jobs promoted to Discover yet."});const V=new Map;for(const I of b){const D=`${(I.title||"").trim().toLowerCase()}::${(I.company||"").trim().toLowerCase()}`;V.has(D)||V.set(D,[]),V.get(D).push(I)}const te=Array.from(V.values()).sort((I,D)=>new Date(D[0].updated_at).getTime()-new Date(I[0].updated_at).getTime());return e.jsx(z,{className:"h-56 rounded-md border border-border",children:e.jsx("div",{className:"divide-y divide-border",children:te.map(I=>{const D=I[0],Z=I.length,ce=I.filter(re=>re.inDiscover).length,qs=I.filter(re=>re.stage==="failed").length,Ue=ce===Z?"discover":qs===Z?"failed":"queued",Es=D.is_easy_apply?"Easy Apply":D.ats&&D.ats!=="unknown"?D.ats:"external";return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-xs",children:[(()=>{const re=D.linkedin_url||null,Be=e.jsxs(e.Fragment,{children:[D.title||"(untitled)",D.company?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",D.company]}):null,Z>1?e.jsxs("span",{className:"ml-1 text-[10px] text-muted-foreground",children:["à ",Z," locations"]}):null]});return re?e.jsx("a",{href:re,target:"_blank",rel:"noopener noreferrer",className:"flex-1 min-w-0 truncate hover:underline",children:Be}):e.jsx("span",{className:"flex-1 min-w-0 truncate",children:Be})})(),e.jsx(C,{variant:"outline",className:`text-[9px] px-1.5 py-0 h-4 shrink-0 capitalize ${D.is_easy_apply?"border-primary/40 text-primary":"border-border text-muted-foreground"}`,children:Es}),Ue==="discover"?e.jsxs("span",{className:"flex items-center gap-1 text-[10px] font-medium text-[hsl(var(--success))] shrink-0",children:[e.jsx(oe,{className:"h-3 w-3"})," In Discover"]}):Ue==="failed"?e.jsx("span",{className:"text-[10px] font-medium text-destructive shrink-0",children:"Failed"}):e.jsxs("span",{className:"text-[10px] font-medium text-[hsl(var(--warning,var(--muted-foreground)))] shrink-0",children:["Queued for Discover",Z>1?` (${ce}/${Z})`:""]}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 w-16 text-right",children:L(new Date(D.updated_at),{addSuffix:!1})})]},D.id)})})})})()]}),(t==null?void 0:t.queue)&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-2",children:[e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Classify"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${(t.queue.pendingClassification??0)>200?"text-warning":""}`,children:t.queue.pendingClassification??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"pending classification"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Resolve"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${t.queue.pending>200?"text-warning":""}`,children:t.queue.pending}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"external · pen
111ding resolve"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Resolved"}),e.jsx("p",{className:"text-xl font-bold mt-1 text-primary",children:t.queue.resolved})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Unresolved"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${(t.queue.unresolved??0)>0?"text-warning":""}`,children:t.queue.unresolved??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"no board match"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Promoted"}),e.jsx("p",{className:"text-xl font-bold mt-1 text-[hsl(var(--success))]",children:t.queue.promoted})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Skipped"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${(t.queue.skipped??0)>0?"text-muted-foreground":""}`,children:t.queue.skipped??0}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"non-approved ATS dropped"})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Failures"}),e.jsx("p",{className:`text-xl font-bold mt-1 ${(t.queue.realFailed??t.queue.failed)>0?"text-destructive":"text-[hsl(var(--success))]"}`,children:t.queue.realFailed??t.queue.failed}),t.queue.failedBreakdown&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[t.queue.failedBreakdown.http_404," dead · ",t.queue.failedBreakdown.http_429," throttled",t.queue.failedBreakdown.classify_failed>0?` · ${t.queue.failedBreakdown.classify_failed} classify`:"",t.queue.failedBreakdown.other>0?` · ${t.queue.failedBreakdown.other} other`:""]})]})]}),((t==null?void 0:t.apiHealth)||(t==null?void 0:t.cache))&&e.jsxs("div",{className:"rounded-md border border-border p-3 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"API Resolver (Stage 3) · LinkedIn Jobs Data API"}),(t==null?void 0:t.apiHealth)&&(()=>{const b=t.apiHealth.status,te={healthy:{cls:"border-[hsl(var(--success))]/40 text-[hsl(var(--success))]",label:"Healthy · 200 OK"},rate_limited:{cls:"border-destructive/50 text-destructive",label:"Throttled / quota reached"},auth_error:{cls:"border-destructive/50 text-destructive",label:"API key rejected"},degraded:{cls:"border-warning/50 text-warning",label:"Degraded"}}[b];return e.jsx(C,{variant:"outline",className:`text-[10px] ${te.cls}`,children:te.label})})()]}),(t==null?void 0:t.apiHealth)&&t.apiHealth.status!=="healthy"&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[t.apiHealth.status==="rate_limited"&&e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-destructive",children:t.apiHealth.counts.rate_limited})," job(s) waiting on rate limit / quota."]}),t.apiHealth.status==="auth_error"&&e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-destructive",children:t.apiHealth.counts.auth})," job(s) blocked â API key/plan rejected."]}),t.apiHealth.status==="degraded"&&e.jsx("span",{children:"API returning errors on some calls."}),t.apiHealth.lastErrorReason&&e.jsxs("span",{children:[" Last: ",e.jsx("span",{className:"font-mono",children:t.apiHealth.lastErrorReason}),t.apiHealth.lastErrorAt?` · ${L(new Date(t.apiHealth.lastErrorAt),{addSuffix:!0})}`:""]})]}),(t==null?void 0:t.apiHealth)&&e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[t.apiHealth.counts.rate_limited," rate-limited · ",t.apiHealth.counts.auth," auth · ",t.apiHealth.counts.http_other," http · ",t.apiHealth.counts.network," network · ",t.apiHealth.counts.no_url," no-url · ",t.apiHealth.counts.exhausted," exhausted"]}),(t==null?void 0:t.cache)&&e.jsxs("p",{className:"text-[11px] text-muted-foreground border-t border-border pt-2",children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Cache:"})," ",t.cache.companies," companies (",t.cache.nonApproved," non-approved · ",t.cache.approved," approved)"," ","· ~",e.jsx("span",{className:"font-semibold text-[hsl(var(--success))]",children:t.cache.savedCalls}
111)," API calls saved",t.cache.cachedSkips>0?` · ${t.cache.cachedSkips} skipped via cache`:""]})]}),(t==null?void 0:t.queue)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-muted-foreground -mt-1",children:[t.queue.failedBreakdown&&t.queue.failedBreakdown.unsupported>0&&e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:t.queue.failedBreakdown.unsupported})," dropped (unsupported ATS â working as designed)"]}),(t.queue.backlogStuck??0)>0&&e.jsxs("span",{children:[e.jsx("span",{className:`font-semibold ${(t.queue.backlogStuck??0)>100?"text-warning":"text-foreground"}`,children:t.queue.backlogStuck})," untouched in queue",t.queue.backlogOldest?` · oldest ${L(new Date(t.queue.backlogOldest),{addSuffix:!0})}`:""]})]}),(t==null?void 0:t.logs)&&t.logs.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1.5",children:"Latest activity (last 20)"}),e.jsx(z,{className:"h-64 rounded-md border border-border",children:e.jsx("div",{className:"divide-y divide-border",children:t.logs.map(b=>{const V=b.stage==="failed"&&b.last_reason==="unsupported",te=b.stage==="resolved"||b.stage==="promoted",I=V?"dropped":b.stage,D=b.stage==="resolved"?"text-primary":b.stage==="promoted"?"text-[hsl(var(--success))]":V?"text-muted-foreground":b.stage==="failed"?"text-destructive":"text-muted-foreground",Z=b.is_easy_apply?"Easy Apply":b.ats&&b.ats!=="unknown"?b.ats:"external",ce=b.last_reason&&!te&&b.last_reason!=="unsupported"?b.last_reason:V?"unsupported":null;return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-xs",children:[e.jsx("span",{className:`font-mono font-semibold w-20 shrink-0 ${D}`,children:I}),b.linkedin_job_id?e.jsxs("a",{href:`https://www.linkedin.com/jobs/view/${b.linkedin_job_id}/`,target:"_blank",rel:"noopener noreferrer",className:"flex-1 min-w-0 truncate hover:underline",children:[b.title||"(untitled)",b.company?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",b.company]}):null]}):e.jsxs("span",{className:"flex-1 min-w-0 truncate",children:[b.title||"(untitled)",b.company?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",b.company]}):null]}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 w-40 truncate text-right",title:b.user_email||void 0,children:b.user_email||"â"}),te?e.jsx(C,{variant:"outline",className:`text-[9px] px-1.5 py-0 h-4 shrink-0 capitalize ${b.is_easy_apply?"border-primary/40 text-primary":"border-[hsl(var(--success))]/40 text-[hsl(var(--success))]"}`,children:Z}):ce&&e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground shrink-0",children:ce}),b.attempts>0&&e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:["Ã",b.attempts]}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 w-16 text-right",children:L(new Date(b.updated_at),{addSuffix:!1})})]},b.id)})})})]})]})]})})()}),e.jsx(ee,{value:"intelligence",className:"space-y-4 mt-4",children:e.jsx(Gt,{})})]})})}export{ma as AdminPanel};
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.