1import{c as d,v as P,r as l,j as e,C as $,a7 as q,b as r,a8 as F,a9 as Q,aa as O,ab as V,ac as B,ad as H}from"./index-CVfxS1CQ.js";import{u as K}from"./useSuspenseQuery-Bfea-Rl1.js";import{u as n}from"./useServerFn-BGg7aFF-.js";import{S as U}from"./search-C3REpWA5.js";import{f as j}from"./formatDistanceToNowStrict-83Q3LuZo.js";import{T as J}from"./trash-2-DcmCoGOl.js";import{M as W}from"./mail-Dn1mEaL1.js";import{f as X}from"./format-wW6SWvqV.js";import{X as G}from"./x-93Ke9l9O.js";const Y=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M4.929 4.929 19.07 19.071",key:"196cmz"}]],Z=d("ban",Y);const ee=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],te=d("key-round",ee);const se=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],ae=d("shield",se);const re=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],ne=d("user-plus",re),h=["super_admin","admin","editor","journalist","video_editor","social_manager","election_admin","recruitment_admin","hiring_manager","reviewer","contributor","viewer"],o={super_admin:"Super Admin",admin:"Administrator",editor:"Editor",journalist:"Journalist",video_editor:"Video Editor",social_manager:"Social Media Manager",election_admin:"Election Administrator",recruitment_admin:"Recruitment Admin",hiring_manager:"Hiring Manager",reviewer:"Reviewer",contributor:"Contributor",viewer:"Viewer"},y={super_admin:"Full control over everything, including team management.",admin:"Manage stories, videos, homepage, election and settings.",editor:"Edit and publish stories from any journalist.",journalist:"Write and publish their own stories.",video_editor:"Manage the /tv streaming hub and videos.",social_manager:"Manage breaking news and homepage highlights.",election_admin:"Manage the Election Control Center.",recruitment_admin:"Full recruitment access: vacancies, applicants and files.",hiring_manager:"Review applicants, change status and download files.",reviewer:"Review applications and leave internal notes only.",contributor:"Draft stories for editors to review.",viewer:"Read-only access to the newsroom."};function he(){const{data:g}=K(q),k=P(),N=n(F),w=n(H),_=n(Q),S=n(V),R=n(B),C=n(O),[c,b]=l.useState(""),[m,M]=l.useState("journalist"),[p,E]=l.useState(""),[f,v]=l.useState(!1),i=()=>k.invalidateQueries({queryKey:["admin","team"]});async function I(t){if(t.preventDefault(),!!c){v(!0);try{await N({data:{email:c.trim().toLowerCase(),role:m}}),r.success(`Invitation sent to ${c}`),b(""),await i()}catch(s){r.error(s.message)}finally{v(!1)}}}async function z(t,s){try{await _({data:{user_id:t,roles:[s]}}),r.success("Role updated"),await i()}catch(a){r.error(a.message)}}async function A(t,s){try{await S({data:{user_id:t,suspended:!s}}),r.success(s?"Account re-enabled":"Account suspended"),await i()}catch(a){r.error(a.message)}}async function L(t,s){if(confirm(`Remove ${s??"this user"} from the team? This can't be undone.`))try{await R({data:{user_id:t}}),r.success("Removed"),await i()}catch(a){r.error(a.message)}}async function T(t){try{await C({data:{email:t}}),r.success(`Password reset email sent to ${t}`)}catch(s){r.error(s.message)}}async function D(t){try{await w({data:{id:t}}),r.success("Invitation revoked"),await i()}catch(s){r.error(s.message)}}const x=g.members.filter(t=>!p||(t.email??"").toLowerCase().includes(p.toLowerCase())),u=g.invitations.filter(t=>t.status==="pending");return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{children:[e.jsx("p",{className:"font-[Inter] text-[11px] font-semibold uppercase tracking-[0.24em] text-ink-muted",children:"Newsroom"}),e.jsx("h1",{className:"mt-2 font-[Newsreader] text-[36px] font-[600] leading-none text-ink",children:"Team"}),e.jsx("p",{className:"mt-2 text-sm text-ink-muted",children:"Invite teammates, assign roles, and manage access to the CMS."})]}),e.jsxs("section",{className:"rounded-lg border border-rule bg-surface/40 p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-ink-muted",children:[e.jsx(ne,{className:"size-3.5"})," Invite a teammate"]}),e.jsxs("form",{onSubmit:I,className:"mt-4 flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-[240px]",children:[e.jsx("label",{className:"block text-[11px] font-medium uppercase tracking-[0.12em] text-ink-muted",children:"Email"}),e.jsx("input",{type:"email",required:!0,value:c,onChange:t=>b(t.target.value),placeholder:"[email protected]",className:"mt-1.5 w-full border border-rule bg-paper px-3 py-2 text-[14px] outline-none focus:border-ink"})]}),e.jsxs("div",{className:"w-[220px]",children:[e.jsx("label",{className:"block text-[11px] font-medium uppercase tracking-[0.12em] text-ink-muted",children:"Role"}),e.jsx("select",{value:m,onChange:t=>M(t.target.value),className:"mt-1.5 w-full border border-rule bg-paper px-3 py-2 text-[14px] outline-none focus:border-ink",children:h.map(t=>e.jsx("option",{value:t,children:o[t]},t))})]}),e.jsx("button",{type:"submit",disabled:f,className:"h-[38px] bg-ink px-5 text-[12px] font-semibold uppercase tracking-[0.14em] text-paper hover:bg-ink/85 disabled:opacity-50",children:f?"
1Sendingâ¦":"Send invite"})]}),e.jsx("p",{className:"mt-2 text-[12px] text-ink-muted",children:y[m]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4 flex items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-[Inter] text-[11px] font-semibold uppercase tracking-[0.18em] text-ink-muted",children:["Team members · ",x.length]}),e.jsx("h2",{className:"mt-1 font-[Newsreader] text-[22px] font-[600]",children:"Active accounts"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(U,{className:"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-ink-muted"}),e.jsx("input",{value:p,onChange:t=>E(t.target.value),placeholder:"Search emailâ¦",className:"border border-rule bg-paper py-1.5 pl-8 pr-3 text-[13px] outline-none focus:border-ink"})]})]}),e.jsxs("div",{className:"divide-y divide-rule border-y border-rule",children:[x.map(t=>{const s=t.roles[0]??"viewer";return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 py-4",children:[e.jsx("div",{className:"flex size-9 shrink-0 items-center justify-center rounded-full bg-ink text-[13px] font-semibold text-paper",children:(t.email??"?")[0]?.toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"truncate text-[14px] font-semibold text-ink",children:[t.email??"(no email)",t.suspended&&e.jsx("span",{className:"ml-2 border border-amber-500/40 bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-widest text-amber-700",children:"Suspended"})]}),e.jsxs("p",{className:"mt-0.5 text-[12px] text-ink-muted",children:[t.roles.map(a=>o[a]??a).join(" · "),t.last_sign_in_at&&e.jsxs(e.Fragment,{children:[" · Last active ",j(new Date(t.last_sign_in_at))," ago"]})]})]}),e.jsx("select",{value:s,onChange:a=>z(t.user_id,a.target.value),className:"border border-rule bg-paper px-2 py-1.5 text-[12px] outline-none focus:border-ink",children:h.map(a=>e.jsx("option",{value:a,children:o[a]},a))}),t.email&&e.jsxs("button",{onClick:()=>T(t.email),className:"inline-flex items-center gap-1 border border-rule px-2 py-1.5 text-[11px] font-semibold uppercase tracking-widest text-ink-muted hover:bg-surface",title:"Send password reset",children:[e.jsx(te,{className:"size-3"})," Reset"]}),e.jsxs("button",{onClick:()=>A(t.user_id,t.suspended),className:"inline-flex items-center gap-1 border border-rule px-2 py-1.5 text-[11px] font-semibold uppercase tracking-widest text-ink-muted hover:bg-surface",title:t.suspended?"Re-enable account":"Suspend account",children:[e.jsx(Z,{className:"size-3"})," ",t.suspended?"Enable":"Suspend"]}),e.jsxs("button",{onClick:()=>L(t.user_id,t.email),className:"inline-flex items-center gap-1 border border-red/30 px-2 py-1.5 text-[11px] font-semibold uppercase tracking-widest text-red hover:bg-red/5",title:"Remove from team",children:[e.jsx(J,{className:"size-3"})," Remove"]})]},t.user_id)}),x.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-ink-muted",children:"No members match."})]})]}),u.length>0&&e.jsxs("section",{children:[e.jsxs("div",{className:"mb-3",children:[e.jsxs("p",{className:"font-[Inter] text-[11px] font-semibold uppercase tracking-[0.18em] text-ink-muted",children:["Pending invitations · ",u.length]}),e.jsx("h2",{className:"mt-1 font-[Newsreader] text-[22px] font-[600]",children:"Awaiting acceptance"})]}),e.jsx("div",{className:"divide-y divide-rule border-y border-rule",children:u.map(t=>{const s=new Date(t.expires_at),a=s<new Date;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 py-3",children:[e.jsx(W,{className:"size-4 text-ink-muted"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[14px] font-medium text-ink",children:t.email}),e.jsxs("p",{className:"text-[12px] text-ink-muted",children:[o[t.role]??t.role," · Invited ",X(new Date(t.created_at),"MMM d")," ·"," ",a?e.jsx("span",{className:"text-red",children:"Expired"}):e.jsxs(e.Fragment,{children:["Expires ",j(s)]})]})]}),e.jsxs("button",{onClick:()=>D(t.id),className:"inline-flex items-center gap-1 border border-rule px-2 py-1.5 text-[11px] font-semibold uppercase tracking-widest text-ink-muted hover:bg-surface",children:[e.jsx(G,{className:"size-3"})," Revoke"]})]},t.id)})})]}),e.jsxs("section",{className:"rounded-lg border border-rule bg-surface/40 p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-ink-muted",children:[e.jsx(ae,{className:"size-3.5"})," Roles"]}),e.jsx("ul",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:h.map(t=>e.jsxs("li",{className:"border-l-2 border-ink/20 pl-3",children:[e.jsxs("p",{className:"text-[13px] font-semibold text-ink",children:[o[t],(t==="admin"||t==="super_admin")&&e.jsx($,{className:"ml-1 inline size-3 text-emerald-600"})]}),e.jsx("p",{className:"text-[12px] text-ink-muted",children:y[t]})]},t))})]})]})}export{he 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.