1import{u as ne,j as s,B as w}from"./index-C9VyRByS.js";import{r as n,aM as O,ap as P,al as ie,ao as re}from"./icons-Dk9ia89R.js";import{I as oe}from"./input-CPdsLOuT.js";import{S as A,a as F,b as _,c as G,d as D}from"./select-DRVFTakE.js";import{E as le}from"./error-note-DUDm2XNO.js";import{M as ce,m as de}from"./member-avatar-Dvpoz9Wg.js";import{S as U,j as me,a as k,b as N,e as ue,d as V}from"./settings-ui-16BZExpj.js";import"./index-DuU_63WQ.js";import"./index-4ZCr8EaA.js";import"./index-SqWoeikz.js";import"./index-Bhv3eNQI.js";import"./index-BfqoL0OZ.js";import"./switch-frdVQ2Np.js";const B=[{value:"member",label:"Member",hint:"Standard access to the workspace."},{value:"developer",label:"Developer",hint:"Member access plus API keys and webhooks."},{value:"owner",label:"Owner",hint:"Full access, including members and billing."}],H="h-8 rounded-lg border-0 bg-secondary px-2.5 text-[13px] font-medium shadow-none hover:bg-muted";function Ie(){var M;const{activeWorkspace:i,user:p,authFetch:l}=ne(),[c,d]=n.useState([]),[f,v]=n.useState([]),[y,J]=n.useState([]),[x,K]=n.useState(!1),[q,Q]=n.useState(!1),[m,g]=n.useState(""),[j,X]=n.useState("member"),[I,E]=n.useState(!1),[Y,b]=n.useState(!1),C=n.useRef(null),[$,o]=n.useState(""),[Z,W]=n.useState(!0),[ee,R]=n.useState(null);async function T(){if(i){try{const e=await l(`/api/workspaces/${i.id}/members`);if(e.ok){const t=await e.json();d(t.members),v(t.invites),J(t.customRoles||[]),K(t.isOwner),Q(!!t.viewerIsGhost)}}catch{}W(!1)}}n.useEffect(()=>{T()},[i==null?void 0:i.id]);const h=n.useMemo(()=>{const e=y.map(a=>({value:a.key,label:a.name,hint:a.description||"A custom role. Set what it can see under Permissions."})),t=B.filter(a=>a.value==="owner");return[...B.filter(a=>a.value!=="owner"),...e,...t]},[y]),z=e=>{var t;return((t=h.find(a=>a.value===e))==null?void 0:t.label)??e};async function L(){if(!m||!m.includes("@")){o("Please enter a valid email address");return}if(i){E(!0),o("");try{const e=await l(`/api/workspaces/${i.id}/invites`,{method:"POST",body:JSON.stringify({email:m,role:j})}),t=await e.json();e.ok?(g(""),b(!1),T()):o(t.error||"Failed to send invite")}catch{o("Network error")}E(!1)}}async function se(e){if(!i)return;const t=f;v(r=>r.filter(u=>u.id!==e)),(await l(`/api/workspaces/${i.id}/invites/${e}`,{method:"DELETE"})).ok||(v(t),o("Failed to revoke invitation"))}async function te(e){if(!i)return;const t=c;d(r=>r.filter(u=>u.id!==e)),(await l(`/api/workspaces/${i.id}/members/${e}`,{method:"DELETE"})).ok||(d(t),o("Failed to remove member"))}async function ae(e,t){if(!i)return;const a=c;d(u=>u.map(S=>S.id===e?{...S,role:t}:S)),(await l(`/api/workspaces/${i.id}/members/${e}/role`,{method:"PATCH",body:JSON.stringify({role:t})})).ok||(d(a),o("Failed to update role"))}return Z?s.jsxs("section",{className:U,children:[s.jsx("div",{className:"h-[52px] skeleton rounded-xl bg-muted"}),s.jsx("div",{className:"h-[140px] skeleton rounded-xl bg-muted"})]}):s.jsxs("section",{className:U,children:[x&&s.jsx(me,{children:s.jsxs(w,{size:"sm",onClick:()=>{b(!0),setTimeout(()=>{var e;return(e=C.current)==null?void 0:e.focus()},0)},className:"h-7 gap-1.5 px-3 text-[12px] font-medium tracking-normal [&_svg]:size-3.5",children:[s.jsx(O,{}),"Invite"]})}),$&&s.jsx(le,{children:$}),x&&Y&&s.jsx(k,{title:"Invite a member",description:(M=h.find(e=>e.value===j))==null?void 0:M.hint,action:s.jsx(w,{variant:"ghost",size:"sm",onClick:()=>{b(!1),g(""),o("")},className:"h-7 px-2.5 text-[12px] font-medium tracking-normal text-muted-foreground",children:"Cancel"}),children:s.jsx(N,{children:s.jsx("div",{className:"p-1",children:s.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5",children:[s.jsx(oe,{ref:C,type:"email",placeholder:"[email protected]",value:m,onChange:e=>{g(e.target.value),o("")},onKeyDown:e=>e.key==="Enter"&&L(),className:`${ue} min-w-0 flex-1`,"aria-label":"Email address to invite"}),s.jsxs(A,{value:j,onValueChange:X,children:[s.jsx(F,{className:`${H} w-[112px] shrink-0`,children:s.jsx(_,{})}),s.jsx(G,{children:h.map(e=>s.jsx(D,{value:e.value,className:"text-[13px]",children:e.label},e.value))})]}),s.jsxs(w,{size:"sm",onClick:L,disabled:I||!m,className:"h-8 shrink-0 gap-1.5 rounded-lg px-2.5 text-[12px] font-medium tracking-normal [&_svg]:size-3.5",children:[s.jsx(O,{}),I?"Sendingâ¦":"Invite"]})]})})})}),s.jsx(k,{title:`${c.length} ${c.length===1?"member":"members"}`,children:s.jsx(N,{children:c.map(e=>{const t=e.userId===(p==null?void 0:p.id),a=x&&(q||!t);return s.jsxs(V,{leading:s.jsx(ce,{email:e.email,avatarUrl:e.avatarUrl}),label:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"truncate",children:e.email}),t&&s.jsx("span",{className:"shrink-0 font-normal text-muted-foreground",children:"you"})]}),children:[a?s.jsxs(A,{value:e.role,onValueChange:r=>ae(e.id,r),children:[s.jsx(F,{className:`${H} w-[112px]`,children:s.jsx(_,{})}),s.jsx(G,{children:h.map(r=>s.jsx(D,{value:r.value,className:"text-[13px]",children:r.label},r.value))})]}):s.jsx("span",{className:"text-[13px] text-muted-foreground",children:z(e.role)}),a&&s.jsx("button",{type:"button",onClick:()=>te(e.id),"aria-label":`Remove ${e.email}`,className:"flex size-7 items-center justify-center rounded-md text-muted-foreground
1/50 transition-colors hover:bg-row-hover hover:text-destructive",children:s.jsx(P,{className:"size-3.5"})})]},e.id)})})}),f.length>0&&s.jsx(k,{title:"Pending invitations",description:"Each invite expires on its own. Copy the link if the email didn't arrive.",children:s.jsx(N,{children:f.map(e=>s.jsxs(V,{leading:s.jsx("span",{className:"flex size-7 shrink-0 items-center justify-center rounded-full border border-dashed border-border",children:s.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:de(e.email)})}),label:s.jsx("span",{className:"truncate text-muted-foreground",children:e.email}),description:`Invited as ${z(e.role)}`,children:[s.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/invite/${e.token}`),R(e.id),setTimeout(()=>R(null),2e3)},"aria-label":"Copy invitation link",className:"flex size-7 items-center justify-center rounded-md text-muted-foreground/50 transition-colors hover:bg-row-hover hover:text-foreground",children:ee===e.id?s.jsx(ie,{className:"size-3.5 text-emerald-500"}):s.jsx(re,{className:"size-3.5"})}),x&&s.jsx("button",{type:"button",onClick:()=>se(e.id),"aria-label":`Revoke invitation for ${e.email}`,className:"flex size-7 items-center justify-center rounded-md text-muted-foreground/50 transition-colors hover:bg-row-hover hover:text-destructive",children:s.jsx(P,{className:"size-3.5"})})]},e.id))})})]})}export{Ie as SettingsMembersPage};
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.