1import{R as p,b,u as f,p as T,j as e,z as x,k as h,n as u,q as N}from"./index-CRToEYL8.js";import{L as k,T as S,S as M}from"./field-GAGfV8zy.js";import{P as L,a as P,b as $}from"./popover-menu-DitpGZdK.js";import{u as E}from"./confirm-CUU2gy6F.js";import{u as _}from"./useMembers-DPYdMwDD.js";import{u as z}from"./useTeams-IzgHsM7G.js";import{S as A,a as j,s as g,i as w}from"./SectionShell-eUmibLum.js";import{C as q}from"./check-OF12l-JJ.js";import{P as D}from"./plus-Cqb5CeTZ.js";import{U as O}from"./users-CIojquQq.js";import{T as R}from"./trash-DCugHQVu.js";import{X as F}from"./x-Bb6COv32.js";import{U as Q}from"./user-plus-DszRErsY.js";import"./search-FkOt3V6f.js";import"./chevron-down-DlCDVOPH.js";import"./index-BaHmauR5.js";async function U(s){return await p({method:"POST",url:"/teams",data:s,authorization:!0})}function K(){const s=b();return f({mutationFn:a=>U(a),onSuccess:()=>s.invalidateQueries({queryKey:["teams"]})})}async function I(s){await p({method:"DELETE",url:`/teams/${s}`,authorization:!0})}function G(){const s=b();return f({mutationFn:a=>I(a),onSuccess:()=>s.invalidateQueries({queryKey:["teams"]})})}async function W(s,a){return await p({method:"POST",url:`/teams/${s}/members`,data:{user_id:a},authorization:!0})}function X(){const s=b();return f({mutationFn:({id:a,userId:i})=>W(a,i),onSuccess:()=>s.invalidateQueries({queryKey:["teams"]})})}async function B(s,a){await p({method:"DELETE",url:`/teams/${s}/members/${a}`,authorization:!0})}function H(){const s=b();return f({mutationFn:({id:a,userId:i})=>B(a,i),onSuccess:()=>s.invalidateQueries({queryKey:["teams"]})})}const v=[{id:"slate",bg:"bg-slate-400",hex:"#94a3b8"},{id:"sky",bg:"bg-sky-500",hex:"#0ea5e9"},{id:"violet",bg:"bg-violet-500",hex:"#8b5cf6"},{id:"amber",bg:"bg-amber-500",hex:"#f59e0b"},{id:"emerald",bg:"bg-emerald-500",hex:"#10b981"},{id:"rose",bg:"bg-rose-500",hex:"#f43f5e"},{id:"indigo",bg:"bg-indigo-500",hex:"#6366f1"},{id:"teal",bg:"bg-teal-500",hex:"#14b8a6"}],y=v[0].hex;function pe(){const s=E(),a=T(t=>t.currentOrganization),i=z(),d=_(),o=K(),c=G(),l=i.data??[],r=d.data??[];function n(t){s?.show(`Delete the team "${t.name}"?`,async()=>{try{await x.promise(c.mutateAsync(t.id),{loading:"Deletingâ¦",success:"Team deleted",error:m=>h(m)})}catch{}})}return e.jsxs(A,{title:"Teams",description:`Group members of ${a?.name??"this workspace"} into named teams.`,children:[e.jsx(j,{eyebrow:"Create a team",description:"Give the team a name and a color, then add members below.",children:e.jsx(J,{pending:o.isPending,onSubmit:async(t,m)=>{try{return await x.promise(o.mutateAsync({name:t,color:m}),{loading:"Creatingâ¦",success:`Team "${t}" created`,error:C=>h(C)}),!0}catch{return!1}}})}),e.jsx(j,{eyebrow:"Teams",description:`${l.length} ${l.length===1?"team":"teams"} in this workspace.`,children:i.isPending?e.jsx("p",{className:"text-[11.5px] text-slate-400 py-2",children:"Loadingâ¦"}):l.length===0?e.jsx("p",{className:"text-[11.5px] text-slate-400 py-2",children:"No teams yet. Create one above."}):e.jsx("div",{className:"space-y-3",children:l.map(t=>e.jsx(V,{team:t,members:r,onDelete:()=>n(t)},t.id))})})]})}function J({pending:s,onSubmit:a}){const[i,d]=u.useState(""),[o,c]=u.useState(y);async function l(){const r=i.trim();if(!r){x.error("Enter a team name");return}await a(r,o)&&(d(""),c(y))}return e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{children:[e.jsx(k,{children:"Name"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-1.5 shrink-0",children:v.map(r=>e.jsx("button",{type:"button",onClick:()=>c(r.hex),"aria-label":`Use ${r.id}`,className:`size-5 rounded-full ${r.bg} flex items-center justify-center transition-transform hover:scale-110 ${r.hex.toLowerCase()===o.toLowerCase()?"ring-2 ring-offset-1 ring-slate-400":""}`,children:r.hex.toLowerCase()===o.toLowerCase()&&e.jsx(q,{className:"w-3 h-3 text-white"})},r.id))}),e.jsx(S,{value:i,onChange:d,placeholder:"Sales, Support, Foundersâ¦",onKeyDown:r=>{r.key==="Enter"&&(r.preventDefault(),l())},className:"flex-1 min-w-[160px]"}),e.jsxs("button",{type:"button",onClick:l,disabled:s||i.trim()==="",className:"h-7 px-2.5 rounded-md bg-slate-900 hover:bg-slate-800 text-white text-[12px] font-medium inline-flex items-center gap-1.5 transition-colors disabled:opacity-60 shrink-0",children:[s?e.jsx(N,{className:"w-3 h-3 animate-spin"}):e.jsx(D,{className:"w-3 h-3"}),"Create team"]})]})]})})}function V({team:s,members:a,onDelete:i}){const d=X(),o=H(),c=u.useMemo(()=>new Set(s.members.map(t=>t.user_id)),[s.members]),l=u.useMemo(()=>a.filter(t=>!c.has(t.user_id)),[a,c]);async function r(t){try{await x.promise(d.mutateAsync({id:s.id,userId:t}),{loading:"Addingâ¦",success:"Member added",error:m=>h(m)})}catch{}}async function n(t){try{await x.promise(o.mutateAsync({id:s.id,userId:t}),{loading:"Removingâ¦",success:"Member removed",error:m=>h(m)})}catch{}}return e.jsxs("div",{className:"rounded-md border border-slate-200 bg-white overflow-hidden",children:[e.jsxs("div",{className:"px-3 h-11 flex items-center gap-2.5 border-b border-slate-200",children:[e.jsx("span",{className:"size-2.5 rounded-full shrink-0",style:{backgroundColor:s.color||y}}),e.jsx("span",{className:"text-[13px] font-semibold text-slate-900 truncate",children:s.name}),e.jsxs("span",{className:"text-[11px] text-slate-400 inline-flex items-center gap-1 shrink-0",children:[e.jsx(O,{className:"w-3 h-3"}),s.members.length]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 shrink-0",children:[e.jsx(Y,{available:l,pending:d.isPending,onAdd:r}),e.jsx("button",{type:"button",onClick:i,"aria-label":"Delete team",title:"Delete team",className:"size-6 rounded text-slate-400 hover:text-red-600 hover:bg-red-50 inline-flex items-center justify-center transition-colors",children:e.jsx(R,{className:"w-3.5 h-3.5"})})]})]}),e.jsx("div",{className:"px-3 py-2.5",children:s.members.length===0?e.jsx("p",{className:"text-[11.5px] text-slate-400 py-1",children:"No members yet. Use Add member to assign s
1omeone."}):e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.members.map(t=>{const m=t.name?.trim()||g(t.email)||`user ${t.user_id.slice(0,8)}`;return e.jsxs("span",{className:"group inline-flex items-center gap-1.5 h-6 pl-1 pr-1.5 rounded-full border border-slate-200 bg-slate-50 text-[11.5px] text-slate-700",children:[e.jsx("span",{className:"size-4 rounded-full bg-white border border-slate-200 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-[8px] font-semibold text-slate-600",children:w(t.email,t.user_id)})}),e.jsx("span",{className:"truncate max-w-[160px]",children:m}),e.jsx("button",{type:"button",onClick:()=>n(t.user_id),disabled:o.isPending,"aria-label":`Remove ${m}`,className:"size-4 rounded-full text-slate-400 hover:text-red-600 hover:bg-red-100 inline-flex items-center justify-center transition-colors disabled:opacity-50",children:e.jsx(F,{className:"w-2.5 h-2.5"})})]},t.user_id)})})})]})}function Y({available:s,pending:a,onAdd:i}){const[d,o]=u.useState(!1),[c,l]=u.useState(""),r=u.useMemo(()=>{const n=c.trim().toLowerCase();return n?s.filter(t=>g(t.email).toLowerCase().includes(n)):s},[s,c]);return e.jsxs(L,{open:d,onOpenChange:o,align:"end",children:[e.jsx(P,{asChild:!0,children:e.jsxs("button",{type:"button",disabled:a,className:"h-6 px-2 rounded-md border border-slate-200 hover:border-slate-300 text-[11.5px] text-slate-700 hover:text-slate-900 inline-flex items-center gap-1 transition-colors disabled:opacity-60",children:[a?e.jsx(N,{className:"w-3 h-3 animate-spin"}):e.jsx(Q,{className:"w-3 h-3"}),"Add member"]})}),e.jsxs($,{minWidth:260,className:"max-w-[calc(100vw-2rem)] p-1.5",children:[e.jsx("div",{className:"px-1 pb-1.5",children:e.jsx(M,{value:c,onChange:l,placeholder:"Search membersâ¦",autoFocus:!0})}),r.length===0?e.jsx("p",{className:"px-2 py-3 text-[11.5px] text-slate-400 text-center",children:s.length===0?"Everyone is already on this team.":"No matches."}):e.jsx("div",{className:"max-h-56 overflow-y-auto",children:r.map(n=>{const t=g(n.email)||`(user ${n.user_id.slice(0,8)})`;return e.jsxs("button",{type:"button",onClick:()=>{o(!1),l(""),i(n.user_id)},className:"w-full px-1.5 py-1.5 rounded text-left hover:bg-slate-100 transition-colors flex items-center gap-2",children:[e.jsx("span",{className:"size-6 rounded-full bg-slate-100 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-[9px] font-semibold text-slate-600",children:w(n.email,n.user_id)})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[12px] text-slate-900 truncate leading-tight",children:t}),e.jsx("span",{className:"block text-[10px] text-slate-400 truncate font-mono leading-tight",children:n.user_id.slice(0,8)})]})]},n.user_id)})})]})]})}export{pe 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.