1import{r as f,j as e}from"./ui-vendor-Da9uQuMW.js";import{q as y,x as ie,C as Te,S as D,B as b,X as B,t as le,aP as Pe,aE as oe,aF as ce,aD as de,aG as me,aK as E,aJ as Ee,K as U,z as k,d as K,D as V,m as q,bS as ue,H as xe,J as G,a as Le,b as Ie,as as Ae,ao as ae,a9 as Re,y as $e}from"./App-B1QN_3sS.js";import{B as p}from"./separator-CcGBAGgT.js";import{T as pe,a as he,b as _,c as w}from"./tabs-BqByVUA8.js";import{f as Oe,g as Be,h as Ue,i as Ke,j as Ve,k as qe,l as Ge,a as fe,m as Qe}from"./use-teams-BDmiO-rK.js";import{I as L}from"./input-Brt-l3Vp.js";import{D as Q,f as Xe,a as X,b as Y,c as Z,g as H,d as J}from"./dialog-ButUNZ7T.js";import{u as Ye,a as Ze}from"./use-infinite-scroll-CFIjmTyF.js";import{S as He}from"./scroll-area-BxLCDlQw.js";import{E as Je}from"./index-CmeDnPm-.js";import{g as We}from"./client.service-D2_Glw4E.js";import{c as es,a as W,u as ss}from"./utils-DxXc-Znk.js";import ge from"./search-BaKoX4JV.js";import{L as ts}from"./label-CRXglOZ-.js";import{T as je}from"./textarea-B_mMQ0HD.js";import{A as as}from"./avatar-initial-CyZJ-KX6.js";import{T as ne,A as ns,M as ee,u as rs,a as is,b as ls}from"./types-B48q0SCY.js";import Ne from"./sprout-BIGIeHyk.js";import se from"./graduation-cap-BdJ56ku8.js";import os from"./user-round-CZkhbYti.js";import cs from"./star-G7KQnEzf.js";import{S as ds}from"./triangle-alert-DXdl2qp5.js";import ms from"./crown-CiI6Ak6Z.js";import us from"./user-minus-CZO2U7WB.js";import te from"./chevron-left-hPFoVWSi.js";import{S as ve,a as be,b as ye,c as _e,d as O}from"./select-BU2kemPI.js";import we from"./file-DBJ5HMxc.js";import xs from"./mic-DxeWAAgP.js";import Ce from"./trash-2-YwIbSmcf.js";import{u as Fe,e as Se}from"./index.esm-CPxzRGRC.js";import{a as ze}from"./zod-CYT7bu3-.js";import{F as Me,a as C,b as F,c as S,d as z,e as M}from"./form-DjaFZy1J.js";import P from"./upload-CrZW8dSj.js";import ps from"./arrow-right-TeKjpFK8.js";import hs from"./paperclip-CTJK2aJl.js";import De from"./mail-DHQ-42xQ.js";import fs from"./clock-zntdStmR.js";import gs from"./rotate-cw-MNqIrryJ.js";import js from"./circle-x-BqbksTcX.js";import Ns from"./music-DQO3iVWJ.js";import vs from"./video-Dx8756Tl.js";import bs from"./pencil-Dl6ciUcf.js";import ys from"./network-Bsizegs3.js";import _s from"./folder-open-BS4Mk0X4.js";import{u as ws,p as Cs}from"./use-team-title-DzLfJEsZ.js";import"./icons-dynamic-vendor-Cqq8S-fy.js";import"./charts-vendor-DWyOgyj2.js";import"./team.service-BVSuLLCG.js";import"./master.service-CgJD5klq.js";import"./schemas-Co01wv4L.js";import"./chevron-down-BxT7zPmN.js";import"./chevron-up-Dwh8BAX2.js";import"./form-context-Bh2_V_Tz.js";import"./use-location-state-DCb-o99A.js";function Fs({selectedEmails:s,onToggle:a}){const[t,n]=f.useState(""),r=Number(Je.PAGING_SIZE),{data:m,isLoading:i,isFetchingNextPage:l,hasNextPage:o,fetchNextPage:d}=Ye({queryKey:y.teamContactsSearch(t),queryFn:({pageParam:c=0})=>We(r,c*r,t),getNextPageParam:(c,h)=>{const j=c.data.total||0;return h.length*r<j?h.length:void 0},initialPageParam:0}),u=Ze({hasNextPage:o,isFetchingNextPage:l,fetchNextPage:d}),x=(m?.pages.flatMap(c=>c.data.participants)??[]).filter(c=>!!c.cl_email);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ge,{className:"absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(L,{placeholder:"Search contactsâ¦",value:t,onChange:c=>n(c.target.value),className:"pl-8"})]}),e.jsx(He,{className:"h-48 rounded-md border",children:e.jsx("div",{className:"p-2 space-y-1",children:i?Array.from({length:4}).map((c,h)=>e.jsx(ie,{className:"h-10 w-full"},h)):x.length===0?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No contacts found"}):e.jsxs(e.Fragment,{children:[x.map(c=>{const h=s.includes(c.cl_email.toLowerCase());return e.jsxs("button",{type:"button",onClick:()=>a(c.cl_email.toLowerCase()),className:"flex w-full items-center gap-2 rounded-md p-2 text-left text-sm hover:bg-accent",children:[e.jsx("div",{className:es("flex size-4 shrink-0 items-center justify-center rounded border",h?"border-primary bg-primary text-primary-foreground":"border-input"),children:h&&e.jsx(Te,{className:"size-3"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:c.cl_name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:c.cl_email})]})]},c.cl_id)}),e.jsx("div",{ref:u,className:"h-1",children:l&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsx(D,{})})})]})})})]})}const Ss=/[\s,;]+/,zs=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function Ms(s){const a=s.split(Ss).map(r=>
1r.trim()).filter(Boolean),t=[],n=[];for(const r of a)zs.test(r)?t.push(r.toLowerCase()):n.push(r);return{valid:t,invalid:n}}function Ds({emails:s,onChange:a}){const[t,n]=f.useState(""),r=()=>{if(!t.trim())return;const{valid:i,invalid:l}=Ms(t);l.length>0&&le.error(l.length===1?`"${l[0]}" is not a valid email address.`:`${l.length} entries are not valid email addresses.`);const o=new Set(s);i.forEach(d=>o.add(d)),a(Array.from(o)),n(l.join(", "))},m=i=>{a(s.filter(l=>l!==i))};return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ts,{htmlFor:"invite-emails",children:"Email address"}),e.jsx(je,{id:"invite-emails",placeholder:"[email protected], [email protected]â¦",value:t,onChange:i=>n(i.target.value),onBlur:r,onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),r())},rows:2}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paste a list separated by commas, spaces, or new lines."}),s.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(i=>e.jsxs(b,{variant:"secondary",className:"gap-1 pr-1",children:[i,e.jsx("button",{type:"button",onClick:()=>m(i),className:"rounded-full hover:bg-muted-foreground/20",children:e.jsx(B,{className:"size-3"})})]},i))})]})}function ks({groupId:s}){const[a,t]=f.useState(!1),[n,r]=f.useState([]),m=Oe(s,{onSuccess:()=>{r([]),t(!1)}}),i=d=>{t(d),d||r([])},l=d=>{r(u=>u.includes(d)?u.filter(x=>x!==d):[...u,d])},o=()=>{if(n.length===0){le.error("Add at least one email address.");return}m.mutate({emails:n})};return e.jsxs(Q,{open:a,onOpenChange:i,children:[e.jsx(Xe,{asChild:!0,children:e.jsxs(p,{size:"sm",className:"gap-1.5",children:[e.jsx(Pe,{className:"size-4"}),"Invite"]})}),e.jsxs(X,{className:"sm:max-w-md",children:[e.jsxs(Y,{children:[e.jsx(Z,{children:"Invite Member"}),e.jsx(H,{children:"Enter or select the email of a user with a team license to invite them to this team."})]}),e.jsxs(pe,{defaultValue:"email",children:[e.jsxs(he,{className:"w-full",children:[e.jsx(_,{value:"email",className:"flex-1",children:"By email"}),e.jsx(_,{value:"contacts",className:"flex-1",children:"From contacts"})]}),e.jsx(w,{value:"email",children:e.jsx(Ds,{emails:n,onChange:r})}),e.jsx(w,{value:"contacts",children:e.jsx(Fs,{selectedEmails:n,onToggle:l})})]}),e.jsxs(J,{children:[e.jsx(p,{variant:"outline",onClick:()=>i(!1),children:"Cancel"}),e.jsx(p,{onClick:o,disabled:m.isPending,children:m.isPending?e.jsxs(e.Fragment,{children:[e.jsx(D,{}),"Sending..."]}):n.length>1?`Send ${n.length} Invitations`:"Send Invitation"})]})]})]})}const re={group_owner:ms,group_co_admin:ds,group_leader:cs,group_member:os,group_mentor:se,group_mentee:Ne},Ts={group_owner:"bg-amber-100 text-amber-800",group_co_admin:"bg-blue-100 text-blue-800",group_leader:"bg-emerald-100 text-emerald-800",group_member:"bg-gray-100 text-gray-700",group_mentor:"bg-purple-100 text-purple-800",group_mentee:"bg-teal-100 text-teal-800"};function Ps({member:s,currentRoleCode:a,onChangeRole:t,onRemove:n}){const r=a==="group_owner"||a==="group_co_admin",m=s.role_code==="group_owner",i=re[s.role_code],l=s.name||s.email;return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(as,{initial:l.charAt(0).toUpperCase(),className:"size-9"}),e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:l}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:s.email})]}),e.jsxs(b,{variant:"secondary",className:`shrink-0 gap-1 text-xs ${Ts[s.role_code]}`,children:[e.jsx(i,{className:"size-3"}),ne[s.role_code]]}),r&&!m&&e.jsxs(oe,{children:[e.jsx(ce,{asChild:!0,children:e.jsx(p,{variant:"ghost",size:"icon",className:"size-8 shrink-0",children:e.jsx(de,{className:"size-4"})})}),e.jsxs(me,{align:"end",children:[ns.filter(o=>o!==s.role_code).map(o=>{const d=re[o];return e.jsxs(E,{onClick:()=>t?.(s.user_id,o),children:[e.jsx(d,{className:"mr-2 size-4"}),"Set as ",ne[o]]},o)}),e.jsx(Ee,{}),e.jsxs(E,{className:"text-destructive focus:text-destructive",onClick:()=>n?.(s.user_id),children:[e.jsx(us,{className:"mr-2 size-4"}),"Remove from Team"]})]})]})]})}function Es({groupId:s,members:a,currentRoleCode:t}){const n=Be(s),r=Ue(s),m=(l,o)=>{n.mutate({memberUserId:l,role:o})},i=l=>{r.mutate(l)};return e.jsx("div",{className:"flex flex-col gap-2",children:a.map(l
1=>e.jsx(Ps,{member:l,currentRoleCode:t,onChangeRole:m,onRemove:i},l.user_id))})}const A=20;function Ls({groupId:s,members:a,currentRoleCode:t,canManage:n}){const[r,m]=f.useState(""),[i,l]=f.useState(1),o=f.useMemo(()=>{const c=r.trim().toLowerCase();return c?a.filter(h=>h.name?.toLowerCase().includes(c)||h.email.toLowerCase().includes(c)):a},[a,r]),d=Math.max(1,Math.ceil(o.length/A)),u=Math.min(i,d),x=o.slice((u-1)*A,u*A);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"relative w-full max-w-xs",children:[e.jsx(ge,{className:"pointer-events-none absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(L,{value:r,onChange:c=>{m(c.target.value),l(1)},placeholder:"Search by name or email",className:"pl-8"})]}),n&&e.jsx(ks,{groupId:s})]}),o.length===0?e.jsxs("p",{className:"rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground",children:['No members match "',r,'".']}):e.jsx(Es,{groupId:s,members:x,currentRoleCode:t}),d>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(p,{variant:"outline",size:"icon",className:"size-8",disabled:u===1,onClick:()=>l(c=>c-1),children:e.jsx(te,{className:"size-4"})}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Page ",u," of ",d]}),e.jsx(p,{variant:"outline",size:"icon",className:"size-8",disabled:u===d,onClick:()=>l(c=>c+1),children:e.jsx(U,{className:"size-4"})})]})]})}async function Is(s,a,t){const n=new FormData;return n.append("file",t.file),n.append("file_type",t.file_type),t.title&&n.append("title",t.title),t.description&&n.append("description",t.description),(await k.post(`/api/v1/mentor-files/groups/${s}/mentees/${a}/upload`,n)).data.data}async function As(s,a){const t=await k.get("/api/v1/mentor-files/mentor/files",{params:{group_id:s,...a}});return{...t.data.data,items:t.data.data.items.map(n=>({...n,download_url:W(n.download_url)}))}}async function Rs(s,a){const t=await k.get("/api/v1/mentor-files/mentee/files",{params:{group_id:s,...a}});return{...t.data.data,items:t.data.data.items.map(n=>({...n,download_url:W(n.download_url)}))}}async function $s(s){return(await k.delete(`/api/v1/mentor-files/shares/${s}`)).data}function Os(s,a){return K({queryKey:y.teamMentorFiles(s,a),queryFn:()=>As(s,a),enabled:!!s,placeholderData:V})}function Bs(s,a){return K({queryKey:y.teamMenteeFiles(s,a),queryFn:()=>Rs(s,a),enabled:!!s,placeholderData:V})}function Us(s,a,t){return q({mutationFn:n=>Is(s,a,n),successMessage:"File shared with mentee",invalidateKeys:[y.teamMentorFilesAll(),y.teamMenteeFilesAll()],onSuccess:t?.onSuccess})}function Ks(s){return q({mutationFn:a=>$s(a),successMessage:"File removed",invalidateKeys:[y.teamMentorFilesAll(),y.teamMenteeFilesAll()],onSuccess:s?.onSuccess})}const Vs={transcript:ue,recording:xs,document:we};function qs(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function Gs({file:s,counterpartLabel:a,onDelete:t,isDeleting:n}){const r=Vs[s.file_type];return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(r,{className:"size-5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:s.title||s.file_name}),e.jsx(b,{variant:"outline",className:"shrink-0 text-xs capitalize",children:ee[s.file_type]})]}),s.description&&e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:s.description}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[a&&e.jsxs(e.Fragment,{children:[a," · "]}),qs(s.size)," · ",xe(new Date(s.created_at),"MMM d, yyyy")]})]}),s.download_url&&e.jsx(p,{variant:"outline",size:"sm",className:"shrink-0",asChild:!0,children:e.jsx("a",{href:s.download_url,target:"_blank",rel:"noreferrer",children:"Download"})}),t&&e.jsx(p,{variant:"ghost",size:"icon",className:"size-8 shrink-0 text-destructive hover:text-destructive",disabled:n,onClick:()=>t(s.share_id),"aria-label":"Delete file",children:e.jsx(Ce,{className:"size-4"})})]})}const R=10;function Qs({groupId:s,currentRoleCode:a}){const t=a==="group_mentor",n=a==="group_mentee",[r,m]=f.useState(1),[i,l]=f.useState("all"),[o,d]=f.useState(null),u={limit:R,offset:(r-1)*R,file_type:i==="all"?void 0:i},x=Os(t?s:void 0,u),c=Bs(n?s:void 0,u),{data:h,isLoading:j}=t?x:c,g=Ks({onSuccess:()=>d(null)});if(!t&&!n)return null;const v=h?.items??[],ke=h?.total??0,I=Math.max(1,Math.ceil(ke/R));return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Files"}),e.jsxs(ve,{value:i,onValueChange:N=>{l(N),m(1)},children:[e.jsx(be,{className:"h-8 w-36 text-xs",children:e.jsx(ye,{})}),e.jsxs(_e,{children:[e.jsx(O,{value:"all",children:"All types"}
1),Object.entries(ee).map(([N,T])=>e.jsx(O,{value:N,children:T},N))]})]})]}),j?e.jsx("div",{className:"flex flex-col gap-2",children:Array.from({length:2}).map((N,T)=>e.jsx("div",{className:"h-16 w-full animate-pulse rounded-lg border bg-muted/40"},T))}):v.length===0?e.jsx("p",{className:"rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground",children:t?"You haven't shared any files with your mentees yet.":"No files have been shared with you yet."}):e.jsx("div",{className:"flex flex-col gap-2",children:v.map(N=>e.jsx(Gs,{file:N,counterpartLabel:t?N.mentee_name:N.mentor_name,onDelete:t?T=>d(T):void 0,isDeleting:g.isPending&&g.variables===N.share_id},N.share_id))}),I>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(p,{variant:"outline",size:"icon",className:"size-8",disabled:r===1,onClick:()=>m(N=>N-1),children:e.jsx(te,{className:"size-4"})}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Page ",r," of ",I]}),e.jsx(p,{variant:"outline",size:"icon",className:"size-8",disabled:r===I,onClick:()=>m(N=>N+1),children:e.jsx(U,{className:"size-4"})})]}),e.jsx(G,{open:!!o,onOpenChange:N=>!N&&d(null),title:"Delete File",description:"Are you sure you want to retract this file? The mentee will no longer be able to access it.",confirmLabel:"Delete",destructive:!0,isPending:g.isPending,onConfirm:()=>o&&g.mutate(o)})]})}function Xs(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function Ys({open:s,onOpenChange:a,groupId:t,menteeUserId:n,menteeName:r}){const m=f.useRef(null),[i,l]=f.useState(!1),o=Fe({resolver:ze(rs),defaultValues:{file_type:"document",title:"",description:""}}),d=Se({control:o.control,name:"file"}),u=Us(t,n,{onSuccess:()=>x()}),x=()=>{o.reset(),a(!1)},c=j=>{j||(x(),setTimeout(()=>{document.body.style.pointerEvents=""},0))},h=j=>{u.mutate(j)};return e.jsx(Q,{open:s,onOpenChange:c,children:e.jsxs(X,{className:"sm:max-w-md",children:[e.jsxs(Y,{children:[e.jsxs(Z,{children:["Upload File to ",r]}),e.jsx(H,{children:"Share a transcript, recording, or document directly with this mentee."})]}),e.jsx(Me,{...o,children:e.jsxs("form",{onSubmit:o.handleSubmit(h),className:"flex min-w-0 flex-col gap-4",children:[e.jsx(C,{control:o.control,name:"file",render:({field:{onChange:j}})=>e.jsxs(F,{className:"min-w-0",children:[e.jsx(S,{children:"File"}),e.jsx(z,{children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("input",{ref:m,type:"file",className:"hidden",onChange:g=>{const v=g.target.files?.[0];v&&j(v),g.target.value=""}}),d?e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(P,{className:"size-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:d.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Xs(d.size)})]}),e.jsx(p,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0","aria-label":"Remove file",onClick:()=>o.resetField("file"),children:e.jsx(B,{className:"size-4"})})]}):e.jsxs("div",{role:"button",tabIndex:0,"aria-label":"Choose or drop a file",onClick:()=>m.current?.click(),onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),m.current?.click())},onDragOver:g=>{g.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:g=>{g.preventDefault(),l(!1);const v=g.dataTransfer.files?.[0];v&&j(v)},className:`flex cursor-pointer flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 text-center transition ${i?"border-primary bg-primary/5":"border-muted-foreground/25 hover:border-primary hover:bg-muted/40"}`,children:[e.jsx(P,{className:"size-6 text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium",children:"Click to upload or drag and drop"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Any file type"})]})]})}),e.jsx(M,{})]})}),e.jsx(C,{control:o.control,name:"file_type",render:({field:j})=>e.jsxs(F,{children:[e.jsx(S,{children:"File Type"}),e.jsxs(ve,{value:j.value,onValueChange:j.onChange,children:[e.jsx(z,{children:e.jsx(be,{children:e.jsx(ye,{})})}),e.jsx(_e,{children:Object.entries(ee).map(([g,v])=>e.jsx(O,{value:g,children:v},g))})]}),e.jsx(M,{})]})}),e.jsx(C,{control:o.control,name:"title",render:({field:j})=>e.jsxs(F,{children:[e.jsxs(S,{children:["Title"," ",e.jsx("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(z,{children:e.jsx(L,{placeholder:"Display label for this file",...j})}),e.jsx(M,{})]})}),e.jsx(C,{control:o.control,name:"description",render:({field:j})=>e.jsxs(F,{children:[e.jsxs(S,{children:["Description"," ",e.jsx("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(z,{children:e.jsx(je,{placeholder:"A note for the mentee about this file",...j})}),e.jsx(M,{})]})}),e.jsxs(J,{className:"pt-2",children:[e.jsx(p,{type:"button",variant:"outline",onClick:x,disabled:u.isPending,children:"Cancel"}),e.jsx(p,{type:"submit",disabled:u.isPending,children:u.isPending?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-4 w-4"}),"Uploadingâ¦"]}):"Upload"})]})]})})]})})}function Zs({groupId:s,currentUserEmail:a}){const{data:t,isLoading:n}=Ke(s),r=t?.mentorships??[],[m,i]=f.useState(null);return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h3",{className:"text-sm font-semibold",children:"Mentorships"})}),n?e.jsx("div",{className:"flex flex-col gap-2",children:Array.from({length:2}).map((l,o)=>e.jsx("div",{className:"h-14 w-full animate-pulse rounded-lg border bg-muted/40"},o))}):r.length===0?e.jsxs("p",{className:"rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground",children:["No mentorâmentee relationships yet. Assign a member the"," ",e.jsx("span",{className:"font-medium",children:"Mentor"})," role and another the"," ",e.jsx("span",{className:"font-medium",children:"Mentee"})," role from the Members list - every mentor can then access all mentees in this group."]}):e.jsx("div",{className:"flex flex-col gap-2",children:r.map(l=>{const o=!!a&&l.mentor_email===a,d=l.mentee_name||l.mentee_email||"Unknown";return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 overflow-hidden",children:[e.jsxs("span",{className:"flex items-center gap-1.5 truncate text-sm font-medium",children:[e.jsx(se,{className:"size-4 shrink-0 text-purple-600"}),l.mentor_name||l.mentor_email||"Unknown"]}),e.jsx(ps,{className:"size-4 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"flex items-center gap-1.5 truncate text-sm",children:[e.jsx(Ne,{className:"size-4 shrink-0 text-teal-600"}),d]})]}),o&&e.jsx(p,{variant:"ghost",size:"icon",className:"size-8 shrink-0","aria-label":`Upload file to ${d}`,onClick:()=>i({menteeUserId:l.mentee_user_id,menteeName:d}),children:e.jsx(hs,{className:"size-4"})})]},l.id)})}),m&&e.jsx(Ys,{open:!!m,onOpenChange:l=>!l&&i(null),groupId:s,menteeUserId:m.menteeUserId,menteeName:m.menteeName})]})}function Hs(s){const a=new Map;for(const n of s){const r=a.get(n.email)??[];r.push(n),a.set(n.email,r)}const t=[];for(const[,n]of a){if(n.some(i=>i.accepted))continue;const m=n.reduce((i,l)=>new Date(i.invited_at)>
1=new Date(l.invited_at)?i:l);t.push(m)}return t.sort((n,r)=>new Date(r.invited_at).getTime()-new Date(n.invited_at).getTime()),t}function Js(s){return new Date(s)<new Date}function Ws({groupId:s}){const{data:a,isLoading:t}=Ve(s),[n,r]=f.useState(null),m=qe(s),i=Ge(s,{onSuccess:()=>r(null)}),l=f.useMemo(()=>Hs(a?.invites??[]),[a]);return t?e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Pending Invites"}),e.jsx("div",{className:"flex flex-col gap-2",children:Array.from({length:2}).map((o,d)=>e.jsx(ie,{className:"h-10 w-full rounded-lg"},d))})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Pending Invites"}),l.length===0?e.jsx("p",{className:"rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground",children:"No pending invites right now."}):e.jsx("div",{className:"flex flex-col gap-2",children:l.map(o=>{const d=Js(o.expires_at),u=m.isPending&&m.variables===o.id,x=i.isPending&&i.variables===o.id,c=u||x;return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(De,{className:"size-4 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"flex-1 truncate text-sm",children:o.email}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0",children:c?e.jsxs(b,{variant:"secondary",className:"gap-1 text-xs",children:[e.jsx(D,{className:"size-3"}),u?"Resending...":"Cancelling..."]}):e.jsxs(e.Fragment,{children:[e.jsxs(b,{variant:"secondary",className:"gap-1 text-xs bg-yellow-100 text-yellow-800",children:[e.jsx(fs,{className:"size-3"}),"Pending"]}),d&&e.jsx(b,{variant:"secondary",className:"text-xs bg-red-100 text-red-700",children:"Expired"})]})}),e.jsxs(oe,{children:[e.jsx(ce,{asChild:!0,children:e.jsx(p,{variant:"ghost",size:"icon",className:"size-8 shrink-0",disabled:c,children:c?e.jsx(D,{className:"size-4"}):e.jsx(de,{className:"size-4"})})}),e.jsxs(me,{align:"end",children:[d&&e.jsxs(E,{onClick:()=>m.mutate(o.id),children:[e.jsx(gs,{className:"mr-2 size-4"}),"Resend invitation"]}),e.jsxs(E,{className:"text-destructive focus:text-destructive",onSelect:()=>{setTimeout(()=>r(o),0)},children:[e.jsx(js,{className:"mr-2 size-4"}),"Cancel invitation"]})]})]})]},o.email)})}),e.jsx(G,{open:n!==null,onOpenChange:o=>!o&&r(null),title:"Cancel Invitation",description:`Are you sure you want to cancel the invitation for "${n?.email}"?`,confirmLabel:"Cancel Invitation",cancelLabel:"Keep it",destructive:!0,isPending:i.isPending,onConfirm:()=>n&&i.mutate(n.id)})]})}async function et(s,a){const t=await k.get(`/api/v1/files/teams/${s}`,{params:a});return{...t.data.data,items:t.data.data.items.map(n=>({...n,download_url:W(n.download_url)}))}}async function st(s,a){const t=new FormData;return t.append("file",a.file),t.append("owner_type","team"),t.append("owner_id",s),a.cl_name&&t.append("cl_name",a.cl_name),(await k.post("/api/v1/files",t)).data.data}function tt(s,a){return K({queryKey:y.teamFiles(s,a),queryFn:()=>et(s,a),enabled:!!s,placeholderData:V})}function at(s,a){return q({mutationFn:t=>st(s,t),successMessage:"File uploaded",invalidateKeys:[y.teamFilesAll()],onSuccess:a?.onSuccess})}const nt={document:ue,video:vs,audio:Ns};function rt(s){return s?s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`:"-"}function it({file:s}){const a=nt[s.file_type]??we,n=s.team_file_type==="mentor_file"?[s.mentor_name,s.mentee_name].filter(Boolean).join(" â "):s.uploaded_by_name;return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(a,{className:"size-5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:s.title||s.file_name}),e.jsx(b,{variant:"outline",className:"shrink-0 text-xs",children:is[s.team_file_type]})]}),s.description&&e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:s.description}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[n&&e.jsxs(e.Fragment,{children:[n," · "]}),rt(s.size)," · ",xe(new Date(s.created_at),"MMM d, yyyy")]})]}),s.download_url&&e.jsx(p,{variant:"outline",size:"sm",className:"shrink-0",asChild:!0,children:e.jsx("a",{href:s.download_url,target:"_blank",rel:"noreferrer",children:"Download"})})]})}function lt(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function ot({open:s,onOpenChange:a,groupId:t}){const n=f.useRef(null),[r,m]=f.useState(!1),i=Fe({resolver:ze(ls),defaultValues:{cl_name:""}}),l=Se({control:i.control,name:"file"}),o=at(t,{onSuccess:()=>d()}),d=()=>{i.reset(),a(!1)},u=x=>{o.mutate(x)};return e.jsx(Q,{open:s,onOpenChange:x=>!x&&d(),children:e.jsxs(X,{className:"sm:max-w-md",children:[e.jsxs(Y,{children:[e.jsx(Z,{children:"Upload Team File"}),e.jsx(H,{children:"Share a file with every member of this team."})]}),e.jsx(Me,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(u),className:"flex min-w-0 flex-col gap-4",children:[e.jsx(C,{control:i.control,name:"file",render:({field:{onCh
1ange:x}})=>e.jsxs(F,{className:"min-w-0",children:[e.jsx(S,{children:"File"}),e.jsx(z,{children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("input",{ref:n,type:"file",className:"hidden",onChange:c=>{const h=c.target.files?.[0];h&&x(h),c.target.value=""}}),l?e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border p-3",children:[e.jsx(P,{className:"size-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:l.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:lt(l.size)})]}),e.jsx(p,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0","aria-label":"Remove file",onClick:()=>i.resetField("file"),children:e.jsx(B,{className:"size-4"})})]}):e.jsxs("div",{role:"button",tabIndex:0,"aria-label":"Choose or drop a file",onClick:()=>n.current?.click(),onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),n.current?.click())},onDragOver:c=>{c.preventDefault(),m(!0)},onDragLeave:()=>m(!1),onDrop:c=>{c.preventDefault(),m(!1);const h=c.dataTransfer.files?.[0];h&&x(h)},className:`flex cursor-pointer flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 text-center transition ${r?"border-primary bg-primary/5":"border-muted-foreground/25 hover:border-primary hover:bg-muted/40"}`,children:[e.jsx(P,{className:"size-6 text-muted-foreground"}),e.jsx("p",{className:"text-sm font-medium",children:"Click to upload or drag and drop"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Any file type"})]})]})}),e.jsx(M,{})]})}),e.jsx(C,{control:i.control,name:"cl_name",render:({field:x})=>e.jsxs(F,{children:[e.jsxs(S,{children:["Display Name"," ",e.jsx("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(z,{children:e.jsx(L,{placeholder:"Label shown to the team",...x})}),e.jsx(M,{})]})}),e.jsxs(J,{className:"pt-2",children:[e.jsx(p,{type:"button",variant:"outline",onClick:d,disabled:o.isPending,children:"Cancel"}),e.jsx(p,{type:"submit",disabled:o.isPending,children:o.isPending?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-4 w-4"}),"Uploadingâ¦"]}):"Upload"})]})]})})]})})}const $=10;function ct({groupId:s}){const[a,t]=f.useState(1),[n,r]=f.useState(!1),m={limit:$,offset:(a-1)*$},{data:i,isLoading:l}=tt(s,m),o=i?.items??[],d=i?.total??0,u=i?.can_upload??!1,x=Math.max(1,Math.ceil(d/$));return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Team Files"}),u&&e.jsxs(p,{variant:"outline",size:"sm",className:"gap-1.5",onClick:()=>r(!0),children:[e.jsx(P,{className:"size-4"}),"Upload"]})]}),l?e.jsx("div",{className:"flex flex-col gap-2",children:Array.from({length:2}).map((c,h)=>e.jsx("div",{className:"h-16 w-full animate-pulse rounded-lg border bg-muted/40"},h))}):o.length===0?e.jsx("p",{className:"rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground",children:"No files have been shared with this team yet."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(it,{file:c},c.share_id??c.file_id))}),x>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(p,{variant:"outline",size:"icon",className:"size-8",disabled:a===1,onClick:()=>t(c=>c-1),children:e.jsx(te,{className:"size-4"})}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Page ",a," of ",x]}),e.jsx(p,{variant:"outline",size:"icon",className:"size-8",disabled:a===x,onClick:()=>t(c=>c+1),children:e.jsx(U,{className:"size-4"})})]}),e.jsx(ot,{open:n,onOpenChange:r,groupId:s})]})}function dt({teamId:s}){const a=Le(),{data:t,isLoading:n}=fe(s),r=Ie(x=>x.principal?.email),[m,i]=f.useState(!1),l=Qe({onSuccess:()=>a("/app/teams",{replace:!0})});if(n)return e.jsx(Ae,{title:"Loading team...",subtitle:"Fetching team details"});if(!t)return e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Team not found."});const d=t.all_member.find(x=>x.email===r)?.role_code,u=d==="group_owner"||d==="group_co_admin";return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"size-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:t.name})]}),u&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(p,{variant:"ghost",size:"icon",className:"size-8 shrink-0",onClick:()=>a(`/app/teams/${s}/edit`),"aria-label":"Edit team",children:e.jsx(bs,{className:"size-4"})}),e.jsx(p,{variant:"ghost",size:"icon",className:"size-8 shrink-0 text-destructive hover:text-destructive",onClick:()=>i(!0),"aria-label":"Delete team",children:e.jsx(Ce,{className:"size-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",className:"text-xs capitalize",children:t.status}),e.jsxs(b,{variant:"secondary",className:"text-xs",children:[t.all_member.length," ",t.all_member.length===1?"member":"members"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs(p,{variant:"outline",size:"sm",className:"w-fit gap-1.5",onClick:()=>a(`/app/teams/${s}
1/structure`),children:[e.jsx(ys,{className:"size-4"}),"View Org Structure"]})})]}),e.jsxs(pe,{defaultValue:"members",className:"w-full",children:[e.jsxs(he,{className:"w-full justify-start overflow-x-auto sm:w-fit",children:[e.jsxs(_,{value:"members",className:"gap-1.5",children:[e.jsx(ae,{className:"size-4"}),"Members"]}),e.jsxs(_,{value:"mentorship",className:"gap-1.5",children:[e.jsx(se,{className:"size-4"}),"Mentorship"]}),e.jsxs(_,{value:"files",className:"gap-1.5",children:[e.jsx(_s,{className:"size-4"}),"Files"]}),u&&e.jsxs(_,{value:"invites",className:"gap-1.5",children:[e.jsx(De,{className:"size-4"}),"Invites"]})]}),e.jsx(w,{value:"members",className:"pt-3",children:e.jsx(Ls,{groupId:s,members:t.all_member,currentRoleCode:d,canManage:u})}),e.jsx(w,{value:"mentorship",className:"pt-3",children:e.jsx(Zs,{groupId:s,members:t.all_member,canManage:u,currentUserEmail:r})}),e.jsxs(w,{value:"files",className:"space-y-6 pt-3",children:[e.jsx(ct,{groupId:s}),e.jsx(Qs,{groupId:s,currentRoleCode:d})]}),u&&e.jsx(w,{value:"invites",className:"pt-3",children:e.jsx(Ws,{groupId:s})})]}),e.jsx(G,{open:m,onOpenChange:i,title:"Delete Team",description:`Are you sure you want to delete "${t.name}"? This action cannot be undone.`,confirmLabel:"Delete",destructive:!0,isPending:l.isPending,onConfirm:()=>l.mutate(s)})]})}function ma(){const{id:s}=Re(),{setBreadcrumbs:a}=$e(),t=ws(s),{data:n}=fe(s),r=n?.name||t;return f.useEffect(()=>{n?.name&&s&&Cs(s,n.name)},[n?.name,s]),ss(r),f.useEffect(()=>{a([{label:"Teams",to:"/app/teams"},{label:r,to:`/app/teams/${s}`,isLast:!0}])},[a,s,r]),e.jsx("div",{className:"mx-auto flex w-full flex-col gap-4 px-4 py-3.5 pb-6",children:e.jsx(dt,{teamId:s})})}export{ma 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.