1import{u as T,r as f,b as v,a as E,j as e,I as w,m as d,C,T as D,g as b,X as q,h as k,q as O,P as I,o as L}from"./index-u0HMC9Vb.js";import{S as z}from"./switch-zpySaZsg.js";import"./index-BegspP2X.js";const K=["pending","student","mentor","team","admin"],M=["not_enrolled","pending","approved"],$={pending:"bg-amber-100 text-amber-700",student:"bg-blue-100 text-blue-700",mentor:"bg-purple-100 text-purple-700",team:"bg-teal-100 text-teal-700",admin:"bg-stone-800 text-white"},F=["SORA","AERO","ONYX","NOVA"],Q=["in_progress","eligible","graduated"],U=["discovering","exploring","refining","executing","directing"];function B({course:n,enrollment:s,profileId:g,onRefresh:m}){const u=(s==null?void 0:s.status)==="active"||(s==null?void 0:s.status)==="completed",[p,x]=f.useState(!1),l=async r=>{x(!0),s?await d.entities.Enrollment.update(s.id,{status:r?"active":"locked"}):await d.entities.Enrollment.create({student_profile_id:g,course_id:n.id,status:r?"active":"locked"}),x(!1),m()};return e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-stone-800",children:[n.code," â ",n.title]}),e.jsx("p",{className:`text-[10px] mt-0.5 ${(s==null?void 0:s.status)==="completed"?"text-lime-600":(s==null?void 0:s.status)==="active"?"text-blue-600":"text-stone-400"}`,children:(s==null?void 0:s.status)||"no enrollment"})]}),e.jsx(z,{checked:u,onCheckedChange:l,disabled:p})]})}function W({user:n,profile:s,courses:g,cohorts:m,onSave:u,onCancel:p,isSaving:x}){const[l,r]=f.useState({...s}),{data:j=[],refetch:h}=v({queryKey:["enrollments-admin",s.id],queryFn:()=>d.entities.Enrollment.filter({student_profile_id:s.id}),enabled:!!s.id}),c=[n.first_name,n.last_name].filter(Boolean).join(" ")||n.full_name||n.email;return e.jsxs(C,{className:"p-5 mb-2 border-0 bg-white shadow-sm",style:{borderRadius:12},children:[e.jsxs("p",{className:"text-sm font-semibold text-stone-900 mb-4",children:["Editing: ",c]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Primary TRA"}),e.jsxs("select",{value:l.primary_tra||"",onChange:t=>r(i=>({...i,primary_tra:t.target.value})),className:"w-full h-9 rounded-lg border border-stone-200 bg-[#F3F1EA] px-3 text-sm focus:outline-none",children:[e.jsx("option",{value:"",children:"â"}),F.map(t=>e.jsx("option",{value:t,children:t},t))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Secondary TRA"}),e.jsxs("select",{value:l.secondary_tra||"",onChange:t=>r(i=>({...i,secondary_tra:t.target.value})),className:"w-full h-9 rounded-lg border border-stone-200 bg-[#F3F1EA] px-3 text-sm focus:outline-none",children:[e.jsx("option",{value:"",children:"â"}),F.map(t=>e.jsx("option",{value:t,children:t},t))]})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:["self_score","other_score","synthesis_score"].map(t=>e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs text-stone-500 mb-1 block capitalize",children:[t.replace("_score","")," Score"]}),e.jsx(w,{type:"number",min:0,max:10,value:l[t]||0,onChange:i=>r(S=>({...S,[t]:Number(i.target.value)})),className:"bg-[#F3F1EA] border-stone-200 rounded-lg h-9 text-sm"})]},t))}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Cohort"}),e.jsxs("select",{value:l.cohort_id||"",onChange:t=>r(i=>({...i,cohort_id:t.target.value})),className:"w-full h-9 rounded-lg border border-stone-200 bg-[#F3F1EA] px-3 text-sm focus:outline-none",children:[e.jsx("option",{value:"",children:"â None â"}),m.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Graduation Status"}),e.jsx("select",{value:l.graduation_status||"in_progress",onChange:t=>r(i=>({...i,graduation_status:t.target.value})),className:"w-full h-9 rounded-lg border border-stone-200 bg-[#F3F1EA] px-3 text-sm focus:outline-none",children:Q.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Studio Access"}),e.jsx("select",{value:l.enrollment_status||"not_enrolled",onChange:t=>r(i=>({...i,enrollment_status:t.target.value})),className:"w-full h-9 rounded-lg border border-stone-200 bg-[#F3F1EA] px-3 text-sm focus:outline-none",children:M.map(t=>e.jsx("option",{value:t,children:t},t))}),e.jsx("p",{className:"text-[10px] text-stone-400 mt-1",children:"approved / pending = access granted · not_enrolled = blocked"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Bio"}),e.jsx(D,{value:l.bio||"",onChange:t=>r(i=>({...i,bio:t.target.value})),className:"bg-[#F3F1EA] border-stone-200 rounded-lg text-sm resize-none",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Location"}),e.jsx(w,{type:"text",value:l.location||"",onChange:t=>r(i=>({...i,location:t.target.value})),className:"bg-[#F3F1EA] border-stone-200 rounded-lg h-9 text-sm",placeholder:"City, Country"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-stone-500 mb-1 block",children:"Entry Level"}),e.jsxs("select",{value:l.entry_level||"",onChange:t=>r(i=>({...i,entry_level:t.target.value})),className:"w-full h-9 rounded-lg border border-stone-200 bg-[#F3F1EA] px-3 text-sm focus:outline-none",children:[e.jsx("option",{value:"",children:"â"}),U.map(t=>e.jsx("option",{value:t,children:t.replace(/_/g," ")},t))]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-stone-500 mb-2",children:"Course Acce
1ss"}),e.jsxs("div",{className:"bg-[#F3F1EA] rounded-xl px-4 divide-y divide-stone-200",children:[g.map(t=>e.jsx(B,{course:t,enrollment:j.find(i=>i.course_id===t.id),profileId:s.id,onRefresh:h},t.id)),g.length===0&&e.jsx("p",{className:"text-xs text-stone-400 py-3 text-center",children:"No courses found"})]})]})]}),e.jsxs("div",{className:"flex gap-2 mt-4 justify-end",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:p,className:"rounded-lg text-xs gap-1",children:[e.jsx(q,{className:"w-3 h-3"})," Cancel"]}),e.jsxs(b,{size:"sm",onClick:()=>u(l),disabled:x,className:"bg-stone-900 hover:bg-stone-800 text-white rounded-lg text-xs gap-1",children:[e.jsx(k,{className:"w-3 h-3"})," Save"]})]})]})}function P({user:n,profile:s,onRoleChange:g,onEditProfile:m,onDeleteProfile:u,onCreateProfile:p,isPending:x}){const[l,r]=f.useState(!1),j=[n.first_name,n.last_name].filter(Boolean).join(" ")||n.full_name||n.email,h=n.role||"pending";return e.jsx(C,{className:`p-4 border-0 ${x?"bg-amber-50":"bg-[#ECE8DF]"}`,style:{borderRadius:10},children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-stone-200 flex items-center justify-center flex-shrink-0 overflow-hidden",children:s!=null&&s.avatar_url?e.jsx("img",{src:s.avatar_url,alt:"",className:"w-full h-full object-cover"}):e.jsx(O,{className:"w-4 h-4 text-stone-400",strokeWidth:1.5})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-stone-900 truncate",children:j}),e.jsx("p",{className:"text-[10px] text-stone-400 truncate",children:n.email}),s&&e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[s.student_id&&e.jsx("span",{className:"text-[9px] font-meta uppercase tracking-widest px-1.5 py-0.5 bg-blue-100 text-blue-700 border border-blue-300",children:s.student_id}),s.primary_tra&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-stone-200 text-stone-600 rounded-full",children:s.primary_tra}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${s.graduation_status==="graduated"?"bg-lime-100 text-lime-700":s.graduation_status==="eligible"?"bg-amber-100 text-amber-700":"bg-stone-100 text-stone-500"}`,children:s.graduation_status||"in_progress"}),s.self_score!=null&&e.jsxs("span",{className:"text-[10px] text-stone-400",children:[s.self_score," / ",s.other_score," / ",s.synthesis_score]})]}),(s==null?void 0:s.location)&&e.jsxs("p",{className:"text-[9px] text-stone-400 mt-1",children:["ð ",s.location]}),(s==null?void 0:s.entry_level)&&e.jsxs("p",{className:"text-[9px] text-stone-400",children:["Process: ",e.jsx("span",{className:"font-medium capitalize",children:s.entry_level.replace(/_/g," ")})]})]}),e.jsxs("div",{className:"relative flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-medium hidden sm:inline ${$[h]||"bg-stone-100 text-stone-500"}`,children:h}),e.jsx(b,{size:"sm",variant:x?"default":"outline",className:`text-xs rounded-lg h-7 ${x?"bg-stone-900 hover:bg-stone-800 text-white":""}`,onClick:()=>r(c=>!c),children:x?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"w-3 h-3 mr-1"})," Approve"]}):"Role"}),l&&e.jsx("div",{className:"absolute right-0 top-8 z-20 bg-white border border-stone-200 rounded-xl shadow-lg py-1 min-w-[120px]",children:K.filter(c=>c!==h).map(c=>e.jsx("button",{onClick:()=>{g(c),r(!1)},className:"w-full text-left px-4 py-2 text-xs text-stone-700 hover:bg-stone-50 capitalize",children:c},c))}),s?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"icon",variant:"ghost",className:"w-7 h-7 rounded-lg",onClick:m,children:e.jsx(I,{className:"w-3.5 h-3.5 text-stone-400",strokeWidth:1.5})}),e.jsx(b,{size:"icon",variant:"ghost",className:"w-7 h-7 rounded-lg",onClick:()=>u(s.id),children:e.jsx(L,{className:"w-3.5 h-3.5 text-red-400",strokeWidth:1.5})})]}):e.jsx(b,{size:"sm",variant:"outline",className:"text-xs rounded-lg h-7",onClick:p,children:"+ Profile"})]})]})})}function H(){const n=T(),[s,g]=f.useState(""),[m,u]=f.useState(null),{data:p=[],isLoading:x}=v({queryKey:["all-users"],queryFn:()=>d.entities.User.list("-created_date",200)}),{data:l=[]}=v({queryKey:["tRESDAProfiles"],queryFn:()=>d.entities.TRESDAProfile.list("-created_date",100)}),{data:r=[]}=v({queryKey:["courses"],queryFn:()=>d.entities.Course.filter({},"order")}),{data:j=[]}=v({queryKey:["cohorts"],queryFn:()=>d.entities.Cohort.list("name")}
1),h=()=>`TR-00${Math.floor(1e3+Math.random()*9e3)}`,c=E({mutationFn:async({userId:a,role:o})=>{await d.entities.User.update(a,{role:o}),["student","mentor","team"].includes(o)&&(await d.entities.TRESDAProfile.filter({user_id:a})).length===0&&await d.entities.TRESDAProfile.create({user_id:a,student_id:h()})},onSuccess:()=>{n.invalidateQueries({queryKey:["all-users"]}),n.invalidateQueries({queryKey:["tRESDAProfiles"]})}}),t=E({mutationFn:({profileId:a,data:o})=>d.entities.TRESDAProfile.update(a,o),onSuccess:()=>{n.invalidateQueries({queryKey:["tRESDAProfiles"]}),u(null)}}),i=E({mutationFn:a=>d.entities.TRESDAProfile.delete(a),onSuccess:()=>n.invalidateQueries({queryKey:["tRESDAProfiles"]})}),A=p.map(a=>({...a,profile:l.find(o=>o.user_id===a.id)})).filter(a=>s?`${a.first_name||""} ${a.last_name||""} ${a.email||""}`.toLowerCase().includes(s.toLowerCase()):!0),y=A.filter(a=>!a.role||a.role==="pending"),_=A.filter(a=>a.role&&a.role!=="pending"),N=l.find(a=>a.id===m),R=N?p.find(a=>a.id===N.user_id):null;return e.jsxs("div",{className:"p-5 lg:px-10 max-w-3xl mx-auto",children:[e.jsx("style",{children:"@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;500;600;700&display=swap'); * { font-family: 'Inter Tight', 'Inter', sans-serif; }"}),e.jsxs("header",{className:"mb-6",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.35em] text-stone-400 mb-2",children:"Admin"}),e.jsx("h1",{className:"text-2xl font-bold text-stone-900",children:"Users & Directory"}),e.jsx("p",{className:"text-stone-500 text-sm mt-1",children:"Manage all users, roles, profiles, and course access in one place."})]}),e.jsx(w,{placeholder:"Search by name or email...",value:s,onChange:a=>g(a.target.value),className:"mb-6 bg-[#ECE8DF] border-0 rounded-xl h-9 text-sm"}),m&&N&&R&&e.jsx(W,{user:R,profile:N,courses:r,cohorts:j,onSave:a=>t.mutate({profileId:m,data:a}),onCancel:()=>u(null),isSaving:t.isPending}),x?e.jsx("p",{className:"text-sm text-stone-400",children:"Loading..."}):e.jsxs(e.Fragment,{children:[y.length>0&&e.jsxs("div",{className:"mb-8",children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-widest text-stone-400 mb-3",children:["Awaiting Approval (",y.length,")"]}),e.jsx("div",{className:"space-y-2",children:y.map(a=>e.jsx(P,{user:a,profile:a.profile,isPending:!0,onRoleChange:o=>c.mutate({userId:a.id,role:o}),onEditProfile:()=>{var o;return u((o=a.profile)==null?void 0:o.id)},onDeleteProfile:i.mutate,onCreateProfile:()=>d.entities.TRESDAProfile.create({user_id:a.id,student_id:h()}).then(()=>n.invalidateQueries({queryKey:["tRESDAProfiles"]}))},a.id))})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-widest text-stone-400 mb-3",children:["All Members (",_.length,")"]}),_.length===0?e.jsx(C,{className:"p-8 border-0 bg-[#ECE8DF] text-center",style:{borderRadius:10},children:e.jsx("p",{className:"text-sm text-stone-500",children:"No active members yet."})}):e.jsx("div",{className:"space-y-2",children:_.map(a=>e.jsx(P,{user:a,profile:a.profile,onRoleChange:o=>c.mutate({userId:a.id,role:o}),onEditProfile:()=>{var o;return u((o=a.profile)==null?void 0:o.id)},onDeleteProfile:i.mutate,onCreateProfile:()=>d.entities.TRESDAProfile.create({user_id:a.id,student_id:h()}).then(()=>n.invalidateQueries({queryKey:["tRESDAProfiles"]}))},a.id))})]})]})]})}export{H 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.