1import{r as n,j as s,e as u,k as p,f as j,h as N,b0 as k,s as r,Y as m}from"./index-BIqWDMxQ.js";const x=["queued","applying","submitted","blocked_needs_member","failed","duplicate_skipped","interview","rejected","withdrawn"],g=[{key:"applygenius_outbound_paused",label:"ApplyGenius outbound"},{key:"instinct_outbound_paused",label:"Instinct outbound"}],q=i=>i==null?"â":i==="engine"||i==="applygenius"?"ApplyGenius":i==="instinct"?"Instinct":i;function J(){const[i,v]=n.useState({});n.useState([]),n.useState(0),n.useState(0),n.useState("all");const[y,S]=n.useState([]),[_,w]=n.useState({});n.useState("all");const[f,C]=n.useState({}),E=async()=>{const e=await Promise.all(x.map(a=>r.from("member_auto_applications").select("id",{count:"exact",head:!0}).eq("status",a)));v(Object.fromEntries(x.map((a,t)=>[a,e[t].count??0])))},c=async()=>{const{data:e}=await r.from("member_auto_apply_settings").select("user_id,auto_apply_enabled,auto_apply_paused,auto_apply_daily_cap,preferred_engine").order("updated_at",{ascending:!1}).limit(100),a=e??[];if(S(a),a.length){const{data:t}=await r.from("profiles").select("id,full_name,email").in("id",a.map(l=>l.user_id));
1w(Object.fromEntries((t??[]).map(l=>[l.id,l.full_name||l.email||l.id])))}},h=async()=>{var t,l;const{data:e}=await r.from("app_settings").select("key,value").in("key",g.map(d=>d.key)),a={};for(const d of g){const b=((t=(e??[]).find(G=>G.key===d.key))==null?void 0:t.value)??null;let o=!1;try{o=((l=b?JSON.parse(b):null)==null?void 0:l.paused)===!0}catch{o=!1}a[d.key]=!o}C(a)};n.useEffect(()=>{E(),c(),h()},[]);const A=async(e,a)=>{const{error:t}=await r.from("app_settings").upsert({key:e,value:JSON.stringify({paused:!a})},{onConflict:"key"});t&&m.error(t.message),h()},O=async(e,a)=>{const{error:t}=await r.rpc("set_preferred_engine",{_user_id:e,_engine:a==="any"?null:a});t&&m.error(t.message),c()},P=async(e,a)=>{const{error:t}=await r.rpc("set_auto_apply_paused",{_paused:a,_user_id:e});if(t)return m.error(t.message);c()},I=n.useMemo(()=>e=>_[e]??e.slice(0,8),[_]);return s.jsxs("div",{className:"space-y-6 max-w-6xl",children:[s.jsx("h1",{className:"text-2xl font-bold",children:"Auto-apply"}),s.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-9 gap-3",children:x.map(e=>s.jsx(u,{children:s.jsxs(p,{className:"p-3",children:[s.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:e.replace(/_/g," ")}),s.jsx("p",{className:"text-xl font-bold tabular-nums",children:i[e]??0})]})},e))}),s.jsxs(u,{children:[s.jsx(j,{children:s.jsx(N,{className:"text-base",children:"Engine outbound"})}),s.jsx(p,{children:s.jsx("ul",{className:"divide-y divide-border",children:g.map(e=>s.jsxs("li",{className:"py-2 flex items-center justify-between gap-3",children:[s.jsx("span",{className:"text-sm font-medium",children:e.label}),s.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:f[e.key]===!1?"Paused":"Enabled"}),s.jsx(k,{checked:f[e.key]!==!1,onCheckedChange:a=>A(e.key,a),"aria-label":e.label})]})]},e.key))})})]}),s.jsxs(u,{children:[s.jsx(j,{children:s.jsx(N,{className:"text-base",children:"Members"})}),s.jsx(p,{children:y.length===0?s.jsx("p",{className:"text-sm text-muted-foreground",children:"No members have set up auto-apply yet."}):s.jsx("ul",{className:"divide-y divide-border",children:y.map(e=>s.jsxs("li",{className:"py-2 flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:I(e.user_id)}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.auto_apply_enabled?"Opted in":"Not opted in"," · cap ",e.auto_apply_daily_cap,"/day · engine: ",e.preferred_engine?q(e.preferred_engine):"any"]})]}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[s.jsxs("select",{"aria-label":"Engine assignment",className:"h-8 rounded-md border border-input bg-background px-2 text-xs",value:e.preferred_engine??"any",onChange:a=>O(e.user_id,a.target.value),children:[s.jsx("option",{value:"any",children:"Any engine"}),s.jsx("option",{value:"applygenius",children:"ApplyGenius"}),s.jsx("option",{value:"instinct",children:"Instinct"})]}),s.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:e.auto_apply_paused?"Paused":"Active"}),s.jsx(k,{checked:!e.auto_apply_paused,onCheckedChange:a=>P(e.user_id,!a),"aria-label":"Pause member"})]})]})]},e.user_id))})})]}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"Individual applications are worked from the one queue in Command Center."})]})}export{J as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.