1import{r as N,g as C,j as e,L as M}from"./index-B4UIvmS2.js";import{u as h}from"./useServerFn-D2PvN8Vp.js";import{u as w}from"./useQuery-BLyV68bu.js";import{u as v}from"./useMutation-BmEVjJJ4.js";import{P}from"./PageShell-Eyy4i_t0.js";import{a as D,b as L,c as F,d as E,r as K,e as Q,f as B}from"./cohorts.functions-DGJAxfRB.js";import"./auth-middleware-CdCe453W.js";function J(){const[n,l]=N.useState(null),m=h(B),u=h(Q),c=C(),{data:i,isLoading:g,error:b}=w({queryKey:["admin-cohorts"],queryFn:()=>m()}),[a,d]=N.useState({name:"",code:"",description:"",start_date:"",end_date:"",status:"active"}),r=v({mutationFn:s=>u({data:s}),onSuccess:()=>{c.invalidateQueries({queryKey:["admin-cohorts"]}),d({name:"",code:"",description:"",start_date:"",end_date:"",status:"active"})}});return e.jsxs(P,{children:[e.jsx("section",{className:"px-6 pt-20 pb-10",children:e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx(M,{to:"/admin",className:"text-xs font-semibold uppercase tracking-[0.3em] text-accent",children:"â Back to admin"}),e.jsx("h1",{className:"mt-4 font-serif text-5xl italic",children:"Cohorts"}),e.jsx("p",{className:"mt-4 max-w-2xl text-muted-foreground",children:"Plan cohorts, schedule sessions, add participants, record attendance."})]})}),n?e.jsx(I,{id:n,onBack:()=>l(null)}):e.jsx("section",{className:"px-6 pb-24",children:e.jsxs("div",{className:"mx-auto grid max-w-6xl gap-10 md:grid-cols-[1fr_360px]",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-serif text-3xl italic",children:"All cohorts"}),g&&e.jsx("p",{className:"mt-4 text-muted-foreground",children:"Loadingâ¦"}),b&&e.jsx("p",{className:"mt-4 text-destructive",children:"You don't have access. Ask an admin for the staff role."}),i&&i.cohorts.length===0&&e.jsx("p",{className:"mt-4 text-muted-foreground",children:"No cohorts yet. Create one â"}),i&&i.cohorts.length>0&&e.jsx("ul",{className:"mt-6 divide-y divide-border rounded-2xl border border-border-strong",children:i.cohorts.map(s=>e.jsxs("li",{className:"flex items-center justify-between gap-4 p-5 hover:bg-surface/40",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold uppercase tracking-[0.25em] text-accent",children:[s.code," · ",s.status]}),e.jsx("h3",{className:"mt-1 font-serif text-xl italic",children:s.name}),e.jsxs("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:[s.start_date," â ",s.end_date??"ongoing"]})]}),e.jsx("button",{onClick:()=>l(s.id),className:"rounded-full border border-border-strong px-4 py-1.5 text-xs font-semibold uppercase tracking-wide hover:border-accent hover:text-accent",children:"Manage â"})]},s.id))})]}),e.jsxs("aside",{className:"rounded-2xl border border-border-strong bg-surface/40 p-6",children:[e.jsx("h3",{className:"font-serif text-2xl italic",children:"New cohort"}),e.jsxs("form",{className:"mt-4 space-y-3",onSubmit:s=>{s.preventDefault(),r.mutate(a)},children:[e.jsx(x,{label:"Name",value:a.name,onChange:s=>d(o=>({...o,name:s}))}),e.jsx(x,{label:"Code",value:a.code,onChange:s=>d(o=>({...o,code:s})),placeholder:"MOTAP-2026-A"}),e.jsx(x,{label:"Start date",type:"date",value:a.start_date,onChange:s=>d(o=>({...o,start_date:s}))}),e.jsx(x,{label:"End date (optional)",type:"date",value:a.end_date,onChange:s=>d(o=>({...o,end_date:s}))}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-semibold uppercase tracking-[0.2em] text-muted-foreground",children:"Description"}),e.jsx("textarea",{rows:3,value:a.description,onChange:s=>d(o=>({...o,description:s.target.value})),className:"mt-2 w-full rounded-md border border-border-strong bg-background px-3 py-2 text-sm"})]}),e.jsx("button",{type:"submit",disabled:r.isPending,className:"w-full rounded-full bg-accent px-4 py-2 text-xs font-semibold uppercase tracking-wide text-accent-foreground hover:opacity-90 disabled:opacity-50",children:r.isPending?"Creatingâ¦":"Create cohort"}),r.isError&&e.jsx("p",{className:"text-xs text-destructive",children:r.error.message})]})]})]})})]})}function I({id:n,onBack:l}){const m=h(D),u=h(L),c=h(F),i=C(),{data:g,isLoading:b}=w({queryKey:["cohort",n],queryFn:()=>m({data:{id:n}})}),[a,d]=N.useState(""),[r,s]=N.useState({title:"",starts_at:"",ends_at:"",location:"",description:""}),o=v({mutationFn:t=>u({data:{cohort_id:n,user_id:t,role:"participant"}}),onSuccess:()=>{i.invalidateQueries({queryKey:["cohort",n]}),d("")}}),f=v({mutationFn:t=>c({data:{cohort_id:n,...t}}),onSuccess:()=>{i.invalidateQueries({queryKey:["cohort",n]}),s({title:"",starts_at:"",ends_at:"",location:"",description:""})}}),[y,S]=N.useState(null);if(b)return e.jsx("section",{className:"px-6 pb-24",children:e.jsx("div",{className:"mx-auto max-w-6xl text-muted-foreground",children:"Loadingâ¦"})});if(!g)return null;const{cohort:j,members:_,sessions:k,profiles:A}=g,q=new Map(A.map(t=>[t.id,t]));return e.jsx("section",{className:"px-6 pb-24",children:e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsx("button",{onClick:l,className:"text-xs font-semibold uppercase tracking-[0.3em] text-accent",children:"â All cohorts"}),e.jsxs("div",{className:"mt-4 flex items-baseline gap-4",children:[e.jsx("h2",{className:"font-serif text-4xl italic",children:j.name}),e.jsx("span",{className:"rounded-full bg-accent/10 px-3 py-1 text-xs uppercase tracking-wide text-accent",children:j.code})]}),e.jsxs("p",{className:"mt-2 text-xs uppercase tracking-wide text-muted-foreground",children:[j.start_date," â ",j.end_date??"ongoing"," · ",j.status]}),e.jsxs("div",{className:"mt-10 grid gap-10 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-serif text-2xl italic",children:["Members (",_.length,")"]}),e.jsxs("ul",{className:"mt-4 divide-y divide-border rounded-2xl border border-border-strong",children:[_.length===0&&e.jsx("li",{className:"p-4 text-sm text-muted-foreground",children:"No members yet."}),_.map(t=>e.jsx("li",{className:"flex items-center justify-between gap-3 p-4 text-sm",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:q.get(t.user_id)?.display_name??t.user_id.slice(0,8)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.role," · joined ",t.j
1oined_at]})]})},t.id))]}),e.jsxs("form",{className:"mt-4 flex gap-2",onSubmit:t=>{t.preventDefault(),a.trim()&&o.mutate(a.trim())},children:[e.jsx("input",{value:a,onChange:t=>d(t.target.value),placeholder:"Participant user ID (UUID)",className:"flex-1 rounded-md border border-border-strong bg-background px-3 py-2 text-sm"}),e.jsx("button",{type:"submit",disabled:o.isPending,className:"rounded-full bg-accent px-4 py-2 text-xs font-semibold uppercase tracking-wide text-accent-foreground hover:opacity-90 disabled:opacity-50",children:"Add"})]}),o.isError&&e.jsx("p",{className:"mt-2 text-xs text-destructive",children:o.error.message})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-serif text-2xl italic",children:["Sessions (",k.length,")"]}),e.jsxs("ul",{className:"mt-4 divide-y divide-border rounded-2xl border border-border-strong",children:[k.length===0&&e.jsx("li",{className:"p-4 text-sm text-muted-foreground",children:"No sessions scheduled."}),k.map(t=>e.jsxs("li",{className:"p-4 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[new Date(t.starts_at).toLocaleString()," · ",t.location??"â"]})]}),e.jsx("button",{onClick:()=>S(y===t.id?null:t.id),className:"rounded-full border border-border-strong px-3 py-1 text-xs hover:border-accent hover:text-accent",children:y===t.id?"Close":"Attendance"})]}),y===t.id&&e.jsx(U,{sessionId:t.id})]},t.id))]}),e.jsxs("form",{className:"mt-4 space-y-2 rounded-2xl border border-border bg-surface/40 p-4",onSubmit:t=>{t.preventDefault(),f.mutate(r)},children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-muted-foreground",children:"New session"}),e.jsx(x,{label:"Title",value:r.title,onChange:t=>s(p=>({...p,title:t}))}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(x,{label:"Starts",type:"datetime-local",value:r.starts_at,onChange:t=>s(p=>({...p,starts_at:t}))}),e.jsx(x,{label:"Ends",type:"datetime-local",value:r.ends_at,onChange:t=>s(p=>({...p,ends_at:t}))})]}),e.jsx(x,{label:"Location",value:r.location,onChange:t=>s(p=>({...p,location:t}))}),e.jsx("button",{type:"submit",disabled:f.isPending,className:"w-full rounded-full bg-accent px-4 py-2 text-xs font-semibold uppercase tracking-wide text-accent-foreground hover:opacity-90 disabled:opacity-50",children:f.isPending?"Schedulingâ¦":"Schedule session"}),f.isError&&e.jsx("p",{className:"text-xs text-destructive",children:f.error.message})]})]})]})]})})}function U({sessionId:n}){const l=h(E),m=h(K),u=C(),{data:c,isLoading:i}=w({queryKey:["session-attendance",n],queryFn:()=>l({data:{session_id:n}})}),g=v({mutationFn:a=>m({data:{session_id:n,...a}}),onSuccess:()=>u.invalidateQueries({queryKey:["session-attendance",n]})});if(i)return e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Loadingâ¦"});if(!c)return null;const b=new Map((c.attendance??[]).map(a=>[a.user_id,a]));return e.jsxs("div",{className:"mt-3 rounded-md border border-border bg-background/60 p-3",children:[(c.members??[]).length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No members in this cohort."}),e.jsx("ul",{className:"divide-y divide-border",children:(c.members??[]).map(a=>{const d=b.get(a.id);return e.jsxs("li",{className:"flex items-center justify-between gap-2 py-2 text-xs",children:[e.jsx("span",{className:"font-medium",children:a.display_name??a.id.slice(0,8)}),e.jsxs("div",{className:"flex items-center gap-2",children:[["present","late","excused","absent"].map(r=>{const s=d?.status===r;return e.jsx("button",{onClick:()=>g.mutate({user_id:a.id,status:r,hours:r==="present"||r==="late"?2:void 0}),className:s?"rounded-full bg-accent px-3 py-1 text-[10px] font-semibold uppercase tracking-wide text-accent-foreground":"rounded-full border border-border-strong px-3 py-1 text-[10px] uppercase tracking-wide hover:border-accent hover:text-accent",children:r},r)}),d?.hours!=null&&e.jsxs("span",{className:"text-muted-foreground",children:["· ",d.hours,"h"]})]})]},a.id)})})]})}
1function x({label:n,value:l,onChange:m,type:u="text",placeholder:c}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-semibold uppercase tracking-[0.2em] text-muted-foreground",children:n}),e.jsx("input",{type:u,value:l,onChange:i=>m(i.target.value),placeholder:c,className:"mt-1 w-full rounded-md border border-border-strong bg-background px-3 py-2 text-sm"})]})}export{J as component};
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.