1import{r as I,j as e,S as Y,z as Z,D as ee,F as se,G as te,s as p}from"./index-BemFr6U8.js";import{u as M}from"./useQuery-DTKw3BQf.js";import{A as ae}from"./AdminLayout-Dif4Acnh.js";import{F as ne}from"./FunnelChart-CakiA7qC.js";import{M as y}from"./MetricCard-DiXEk50B.js";import{T,a as B,b as _,c as m,d as F,e as c}from"./table-DOm0Otpc.js";import{S as O}from"./skeleton-k7o9rESh.js";import{B as D}from"./badge-BiIcst9e.js";import{B as ie}from"./building-2-BRDLqZIF.js";import{U as re}from"./users-DkGVXX12.js";import{U as oe}from"./user-check-DDbWgRZD.js";import{G as L}from"./graduation-cap-CEbVvphc.js";import{f as q}from"./formatDistanceToNow-CSEz7yxR.js";import"./shield-DrTblTXN.js";import"./layout-dashboard-5_jWpvNj.js";import"./use-mobile-1PH3TLH6.js";import"./trending-up-fLbaVcUG.js";import"./star-EoZPPjN6.js";import"./calendar-days-DDxMstXA.js";import"./users-round-CXGFpdCx.js";import"./download-zkv6R0-2.js";import"./bell-BsQvpV9Y.js";import"./index-mIuwLVBy.js";import"./zap-BGiY2302.js";import"./circle-check-big-pdnR18S4.js";import"./isAfter-CagysP8H.js";import"./en-US-Ca8fhmg7.js";import"./subDays-C8JG4QrU.js";import"./endOfMonth-j36o3Juj.js";const g=["invited","activated","started_onboarding","completed_profile","completed_assessment","coach_assigned","first_session_booked","completed_coaching_onboarding"],S={invited:"Invited",activated:"Activated account",started_onboarding:"Started onboarding",completed_profile:"Completed profile",completed_assessment:"Completed AI Career Assessment",coach_assigned:"Coach assigned",first_session_booked:"First session booked",completed_coaching_onboarding:"Completed coaching onboarding"};function Le(){const[f,C]=I.useState(null),{data:j,isLoading:U}=M({queryKey:["employer-companies"],queryFn:async()=>{const{data:t}=await p.from("b2b_upload_batches").select("company_name, created_at").order("created_at",{ascending:!1}),r=new Set,l=[];return(t??[]).forEach(o=>{r.has(o.company_name)||(r.add(o.company_name),l.push({name:o.company_name,latest:o.created_at}))}),l}});I.useEffect(()=>{!f&&j&&j.length>0&&C(j[0].name)},[j,f]);const{data:a,isLoading:G}=M({enabled:!!f,queryKey:["admin-employer-onboarding",f],queryFn:async()=>{const{data:t}=await p.from("b2b_upload_batches").select("id").eq("company_name",f),r=(t??[]).map(s=>s.id);if(r.length===0)return null;const{data:l}=await p.from("b2b_upload_rows").select("id, email, first_name, last_name, user_id, status, created_at, accepted_at").in("batch_id",r),o=l??[],h=o.map(s=>s.user_id).filter(Boolean),u=h.length?h:["00000000-0000-0000-0000-000000000000"],[{data:v},{data:P},{data:R},{data:H}]=await Promise.all([p.from("users").select("id, email, first_name, last_name, avatar_url, created_at").in("id",u),p.from("user_profiles").select("user_id, transition_stage, transition_timeline, bio, coach_id, onboarding_completed_at").in("user_id",u),p.from("assessment_results").select("user_id").in("user_id",u),p.from("coaching_sessions").select("user_id").in("user_id",u)]),K=new Map((v??[]).map(s=>[s.id,s])),V=new Map((P??[]).map(s=>[s.user_id,s])),$=new Set((R??[]).map(s=>s.user_id)),z=new Set((H??[]).map(s=>s.user_id)),b=o.map(s=>{const d=s.user_id?K.get(s.user_id):null,n=s.user_id?V.get(s.user_id):null,x=!!d,A={invited:!0,activated:x,started_onboarding:x&&!!(n!=null&&n.transition_stage||n!=null&&n.transition_timeline||n!=null&&n.bio),completed_profile:x&&!!(n!=null&&n.transition_stage&&(d!=null&&d.avatar_url)),completed_assessment:x&&$.has(s.user_id),coach_assigned:x&&!!(n!=null&&n.coach_id),first_session_booked:x&&z.has(s.user_id),completed_coaching_onboarding:x&&!!(n!=null&&n.onboarding_completed_at)};let E="invited";for(const w of g)if(A[w])E=w;else break;return{r:s,u:d,reached:A,latest:E}}),N={};g.forEach(s=>{N[s]=b.filter(d=>d.reached[s]).length});const Q=g.map(s=>({step:S[s],count:N[s]})),J=Date.now()-24*60*60*1e3,W=b.filter(s=>{var n;const d=((n=s.u)==null?void 0:n.created_at)||s.r.created_at;return!d||new Date(d).getTime()>=J?!1:s.latest==="invited"||s.latest==="activated"||s.latest==="started_onboarding"}).slice(0,100),k=s=>g.indexOf(s),X=b.filter(s=>s.reached.activated).sort((s,d)=>k(d.latest)-k(s.latest));return{funnel:Q,counts:N,total:b.length,stuck:W,activated:X}}}),i=a==null?void 0:a.counts;return e.jsx(ae,{children:e.jsxs("div",{className:"space-y-8 p-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"Employer Onboarding"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Members uploaded via Company Onboarding. Every stage is a percentage of Invited."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ie,{className:"w-5 h-5 text-muted-foreground"}),e.jsxs(Y,{value:f??void 0,onValueChange:C,children:[e.jsx(Z,{className:"w-[320px]",children:e.jsx(ee,{placeholder:U?"Loading companies...":"Select a company"})}),e.jsx(se,{children:(j??[]).map(t=>e.jsx(te,{value:t.name,children:t.name}
1,t.name))})]})]}),G||!a?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:Array.from({length:4}).map((t,r)=>e.jsx(O,{className:"h-32"},r))}),e.jsx(O,{className:"h-96"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(y,{icon:e.jsx(re,{className:"w-5 h-5"}),title:"Invited",value:(i==null?void 0:i.invited)??0,color:"hsl(238 87% 69%)",index:0}),e.jsx(y,{icon:e.jsx(oe,{className:"w-5 h-5"}),title:"Activated",value:(i==null?void 0:i.activated)??0,subtitle:i!=null&&i.invited?`${Math.round(i.activated/i.invited*100)}% of invited`:"",color:"hsl(160 84% 39%)",index:1}),e.jsx(y,{icon:e.jsx(L,{className:"w-5 h-5"}),title:"Coach Assigned",value:(i==null?void 0:i.coach_assigned)??0,color:"hsl(270 72% 60%)",index:2}),e.jsx(y,{icon:e.jsx(L,{className:"w-5 h-5"}),title:"Completed Coaching Onboarding",value:(i==null?void 0:i.completed_coaching_onboarding)??0,color:"hsl(38 92% 50%)",index:3})]}),e.jsx(ne,{data:(a==null?void 0:a.funnel)??[]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold text-foreground mb-4",children:["Activated Members Progress (",(a==null?void 0:a.activated.length)??0,")"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Everyone who has activated their account, with how far through onboarding they've reached."}),e.jsx("div",{className:"border rounded-xl overflow-hidden",children:e.jsxs(T,{children:[e.jsx(B,{children:e.jsxs(_,{children:[e.jsx(m,{children:"Name"}),e.jsx(m,{children:"Email"}),e.jsx(m,{children:"Activated"}),e.jsx(m,{className:"w-[220px]",children:"Progress"}),e.jsx(m,{children:"Current Stage"})]})}),e.jsxs(F,{children:[((a==null?void 0:a.activated)??[]).map(t=>{var o,h,u,v;const r=g.indexOf(t.latest),l=Math.round((r+1)/g.length*100);return e.jsxs(_,{children:[e.jsx(c,{className:"font-medium",children:[((o=t.u)==null?void 0:o.first_name)??t.r.first_name,((h=t.u)==null?void 0:h.last_name)??t.r.last_name].filter(Boolean).join(" ")||"-"}),e.jsx(c,{className:"text-muted-foreground",children:((u=t.u)==null?void 0:u.email)??t.r.email}),e.jsx(c,{className:"text-muted-foreground",children:(v=t.u)!=null&&v.created_at?q(new Date(t.u.created_at),{addSuffix:!0}):"-"}),e.jsx(c,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${l}%`,background:"linear-gradient(90deg, hsl(var(--primary)) 0%, hsl(var(--primary-glow)) 100%)"}})}),e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:[r+1,"/",g.length]})]})}),e.jsx(c,{children:e.jsx(D,{variant:"secondary",children:S[t.latest]})})]},t.r.id)}),(!(a!=null&&a.activated)||a.activated.length===0)&&e.jsx(_,{children:e.jsx(c,{colSpan:5,className:"text-center text-muted-foreground py-6",children:"No activated members yet."})})]})]})})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold text-foreground mb-4",children:["Stuck Members (",(a==null?void 0:a.stuck.length)??0,")"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Invited or activated over 24 hours ago but not yet past the main profile."}),e.jsx("div",{className:"border rounded-xl overflow-hidden",children:e.jsxs(T,{children:[e.jsx(B,{children:e.jsxs(_,{children:[e.jsx(m,{children:"Name"}),e.jsx(m,{children:"Email"}),e.jsx(m,{children:"Added"}),e.jsx(m,{children:"Current Stage"})]})}),e.jsxs(F,{children:[((a==null?void 0:a.stuck)??[]).map(t=>{var r,l,o,h;return e.jsxs(_,{children:[e.jsx(c,{className:"font-medium",children:[((r=t.u)==null?void 0:r.first_name)??t.r.first_name,((l=t.u)==null?void 0:l.last_name)??t.r.last_name].filter(Boolean).join(" ")||"-"}),e.jsx(c,{className:"text-muted-foreground",children:((o=t.u)==null?void 0:o.email)??t.r.email}),e.jsx(c,{className:"text-muted-foreground",children:q(new Date(((h=t.u)==null?void 0:h.created_at)??t.r.created_at),{addSuffix:!0})}),e.jsx(c,{children:e.jsx(D,{variant:"secondary",children:S[t.latest]}
1)})]},t.r.id)}),(!(a!=null&&a.stuck)||a.stuck.length===0)&&e.jsx(_,{children:e.jsx(c,{colSpan:4,className:"text-center text-muted-foreground py-6",children:"No stuck members."})})]})]})})]})]})]})})}export{Le 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.