1import{ap as h,ew as H,aB as M,h as x,aD as i,q as e,D as X,t as J,df as G,w as Y,x as Z,cu as R,em as ee,dl as se,aE as g,ex as te,ey as ae,ez as re,E as $,an as ne,eA as ie,eB as le,X as z,eC as oe,eD as ce,eE as de,eq as me,eF as ue,ah as xe}from"./index-BiZh21pO.js";import{u as N}from"./useMutation-De6n0Lgb.js";import{S as A,a as q,b as L,c as Q,d as v}from"./select-CzBymVvq.js";import{D as pe,a as fe,b as he,c as E,e as je}from"./dropdown-menu-CMlUkvT7.js";import{A as ve,a as ge,b as Ne,c as be,d as ye,e as we,f as Ce,g as Se}from"./alert-dialog-DqDSlEsh.js";import{L as w}from"./label-CZT4tCBm.js";import{T as ke,a as _e,b as Fe,c as De}from"./tooltip-YZAdX5uO.js";import{I as Ie}from"./info-CHIWoIef.js";import{R as Ee}from"./rotate-cw-C1U78j6c.js";import{C as Re}from"./copy-BNKkeZpn.js";import{E as Me}from"./ellipsis-CbhuBAsq.js";import{P as Pe}from"./pencil-Cgizu50M.js";import"./index-BdQq_4o_.js";import"./index-DVYrm6bS.js";import"./index-Drpff6rI.js";import"./chevron-right-CZVp6Zj_.js";const V=["people","speakers","works","crm","broadcast","platform_preview"],Te=["platform_preview"];function B(s){return Te.includes(s)}const Ae={people:"People",speakers:"Speakers",works:"Works",crm:"CRM",broadcast:"Broadcast",platform_preview:"Participant preview"},U=V.filter(s=>!B(s)),qe=["super_admin","admin","operator","viewer"],P={super_admin:{label:"Super admin",default:"write",blurb:"Full write on People, Works, CRM, Broadcast. Only role with access to Internal Control (permissions, audit, financials, system).",control:!0},admin:{label:"Admin",default:"write",blurb:"Full write on People, Works, CRM, Broadcast. No Internal Control.",control:!1},operator:{label:"Operator",default:"write",blurb:"Full write on People, Works, CRM, Broadcast. No Internal Control. Same surface rights as admin today.",control:!1},viewer:{label:"Viewer",default:"read",blurb:"Read-only on all surfaces. Cannot create or edit anything.",control:!1}};function T(s){return s==="write"?"Write":s==="read"?"Read":"None"}function W({text:s}){return e.jsx(ke,{delayDuration:150,children:e.jsxs(_e,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex items-center text-muted-foreground hover:text-foreground","aria-label":"More info",children:e.jsx(Ie,{className:"h-3.5 w-3.5"})})}),e.jsx(De,{className:"max-w-xs text-xs leading-relaxed",children:s})]})})}function Le({open:s,onOpenChange:d}){const p=h(H),m=M(),[o,u]=x.useState(""),[t,c]=x.useState(""),[n,f]=x.useState(""),[l,j]=x.useState("operator"),[b,C]=x.useState(""),[_,a]=x.useState({}),[F,S]=x.useState(null),D=P[l],K=()=>{u(""),c(""),f(""),j("operator"),C(""),a({}),S(null)},I=N({mutationFn:()=>{const r={};for(const y of U){const k=_[y];k&&k!=="default"&&(r[y]=k)}return p({data:{email:o.trim(),first_name:t.trim()||void 0,last_name:n.trim()||void 0,initial_role:l,initial_permissions:r,note:b.trim()||void 0}})},onSuccess:r=>{i.success(r.pre_existing?"Magic link sent (account already existed)":"Invitation sent"),m.invalidateQueries({queryKey:["staff-invitations"]}),m.invalidateQueries({queryKey:["control-members"]}),K(),d(!1)},onError:r=>{const y=r?.message??"Unknown error";console.error("[InviteStaff] createStaffInvitation failed:",r),S(y),i.error(y)}});return e.jsx(X,{open:s,onOpenChange:d,children:e.jsxs(J,{className:"max-w-lg",children:[e.jsxs(G,{children:[e.jsx(Y,{children:"Invite staff"}),e.jsx(Z,{children:"They will receive an email link to set their password. They are automatically added as a team ticket holder on the current event."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:"invite-email",children:"Email"}),e.jsx(R,{id:"invite-email",type:"email",value:o,onChange:r=>u(r.target.value),placeholder:"[email protected]",autoComplete:"off"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:"invite-first-name",children:"First name"}),e.jsx(R,{id:"invite-first-name",value:t,onChange:r=>c(r.target.value),placeholder:"Jane",autoComplete:"given-name"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:"invite-last-name",children:"Last name"}),e.jsx(R,{id:"invite-last-name",value:n,onChange:r=>f(r.target.value),placeholder:"Doe",autoComplete:"family-name"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(w,{children:"Role"}),e.jsx(W,{text:"The role sets the default access level on every surface. Use overrides below to change access for a single surface."})]}),e.jsxs(A,{value:l,onValueChange:r=>j(r),children:[e.jsx(q,{className:"h-9",children:e.jsx(L,{})}),e.jsx(Q,{children:qe.map(r=>e.jsx(v,{value:r,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:r}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Default: ",T(P[r].default)," on all surfaces",P[r].control?" + Internal Control":""]})]})},r))})]}),e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-xs leading-relaxed",children:[e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Default access: "}),e.jsxs("span",{className:"font-medium text-foreground",children:[T(D.default)," on all surfaces"]}),D.control?e.jsx("span",{className:"ml-2 inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary",children:"Internal Control"}):null]}),e.jsx("p",{className:"text-muted-foreground",children:D.blurb})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(w,{children:"Per-surface overrides (optional)"}),e.jsx(W,{text:"Overrides replace the role default only for that surface. 'Role default' keeps it in sync with the role above."})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:U.map(r=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-20 text-muted-foreground",children:Ae[r]}),e.jsxs(A,{value:_[r]??"default",onValueChange:y=>a(k=>({...k,[r]:y})),children:[e.jsx(q,{className:"h-8 flex-1 text-xs",children:e.jsx(L,{})}),e.jsxs(Q,{children:[e.jsxs(v,{value:"default",children:["Role default (",T(D.default),")"]}),e.jsx(v,{value:"write",children:"Write"}),e.jsx(v,{value:"read",children:"Read"}),e.jsx(v,{value:"none",children:"None"})]})]})]},r))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(w,{htmlFor:"invite-note",children:"Note (internal, optional)"}),e.jsx(ee,{id:"invite-note",value:b,onChange:r=>C(r.target.value),rows:2})]})]}),e.jsxs(se,{children:[F?e.jsx("div",{className:"mr-auto max-w-[280px] rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:F}):null,e.jsx(g,{variant:"outline",onClick:()=>{K(),d(!1)},disabled:I.isPending,children:"Cancel"}),e.jsx(g,{onClick:()=>{S(null),I.mutate()},disabled:I.isPending||!o.trim()||!t.trim()||!n.trim(),children:I.isPending?"Sendingâ¦":"Send invitation"})]})]})})}const O={people:"People",speakers:"Speakers",works:"Works",crm:"CRM",broadcast:"Broadcast",platform_preview:"Participant preview"},Qe=V.filter(s=>!B(s));function Oe(s){switch(s){case"write":return"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/30";case"read":return"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/30";default:return"bg-muted text-muted-foreground border-border"}}function Be(s){return s.roles.length>0?"active":"paused"}function os(){const s=h(te),d=h(ae),p=h(re),m=M(),[o,u]=x.useState(!1),{data:t=[],isLoading:c}=$({queryKey:["control-members"],queryFn:()=>s(),staleTime:3e4}),{data:n=[]}=$({queryKey:["staff-invitations"],queryFn:()=>p(),staleTime:3e4}),f=N({mutationFn:l=>d({data:l}),onSuccess:()=>
1{i.success("Permission updated"),m.invalidateQueries({queryKey:["control-members"]})},onError:l=>i.error(l.message)});return e.jsxs("div",{className:"space-y-8 max-w-6xl",children:[e.jsx("header",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight",children:"Access"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Invite staff, manage per-surface permissions, pause or remove accounts. Every HQ account is automatically granted a team ticket on the current event."})]}),e.jsxs(g,{onClick:()=>u(!0),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"})," Invite staff"]})]})}),e.jsx(Ke,{invitations:n}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Members"}),c?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."}):t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No staff members yet."}):e.jsx("div",{className:"overflow-hidden rounded-xl border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-left text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 font-medium",children:"Member"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Roles"}),Qe.map(l=>e.jsx("th",{className:"px-2 py-2 font-medium",children:O[l]},l)),e.jsx("th",{className:"px-2 py-2 font-medium",children:O.platform_preview}),e.jsx("th",{className:"w-10 px-2 py-2"})]})}),e.jsx("tbody",{className:"divide-y",children:t.map(l=>e.jsx(Ue,{member:l,pending:f.isPending,onChange:(j,b)=>f.mutate({profile_id:l.profile_id,surface:j,level:b})},l.profile_id))})]})})]}),e.jsx(Le,{open:o,onOpenChange:u})]})}function Ke({invitations:s}){const d=h(ie),p=h(le),m=M(),o=N({mutationFn:t=>d({data:{id:t}}),onSuccess:()=>{i.success("Invitation resent"),m.invalidateQueries({queryKey:["staff-invitations"]})},onError:t=>i.error(t.message)}),u=N({mutationFn:t=>p({data:{id:t}}),onSuccess:()=>{i.success("Invitation revoked"),m.invalidateQueries({queryKey:["staff-invitations"]})},onError:t=>i.error(t.message)});return e.jsxs("section",{className:"space-y-3",children:[e.jsx("h2",{className:"text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Invitations"}),s.length===0?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No invitations yet. Click ",e.jsx("em",{children:"Invite staff"})," above to send the first one."]}):e.jsx("div",{className:"overflow-hidden rounded-xl border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-left text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 font-medium",children:"Email"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Role"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Invited by"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"px-4 py-2 font-medium",children:"Expires"}),e.jsx("th",{className:"w-32 px-4 py-2"})]})}),e.jsx("tbody",{className:"divide-y",children:s.map(t=>{const n=new Date(t.expires_at).getTime()<Date.now()&&t.status==="pending"?"expired":t.status;return e.jsxs("tr",{children:[e.jsxs("td",{className:"px-4 py-2.5",children:[e.jsx("div",{className:"font-medium",children:t.email}),t.full_name&&e.jsx("div",{className:"text-xs text-muted-foreground",children:t.full_name})]}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:"rounded-full border bg-muted px-2 py-0.5 text-[11px]",children:t.initial_role})}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-muted-foreground",children:t.invited_by_name??"-"}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx($e,{status:n})}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-muted-foreground",children:new Date(t.expires_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:t.status==="pending"?e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>o.mutate(t.id),disabled:o.isPending,title:"Resend invite email",children:e.jsx(Ee,{className:"h-3.5 w-3.5"})}),e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>{const f=typeof window<"u"?window.location.origin:"";navigator.clipboard.writeText(`${f}/auth/set-password?invite=${t.id}`),i.success("Set-password link copied")},title:"Copy set-password link",children:e.jsx(Re,{className:"h-3.5 w-3.5"})}),e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>u.mutate(t.id),disabled:u.isPending,title:"Revoke invitation",children:e.jsx(z,{className:"h-3.5 w-3.5"})})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"-"})})]},t.id)})})]})})]})}function $e({status:s}){const d=s==="pending"?"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/30":s==="accepted"?"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/30":s==="expired"?"bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30":"bg-muted text-muted-foreground border-border";return e.jsx("span",{className:`rounded-full border px-2 py-0.5 text-[11px] ${d}`,children:s})}function Ue({member:s,pending:d,onChange:p}){const m=h(oe),o=h(ce),u=h(de),t=M(),[c,n]=x.useState(null),f=Be(s),l=s.permissions.some(a=>a.surface==="platform_preview"&&a.source==="override"&&a.level!=="none"),j=()=>{t.invalidateQueries({queryKey:["control-members"]}),t.invalidateQueries({queryKey:["staff-invitations"]})},b=N({mutationFn:()=>m({data:{profile_id:s.profile_id}}),onSuccess:()=>{i.success("Member paused"),j()},onError:a=>i.error(a.message)}
1),C=N({mutationFn:()=>o({data:{profile_id:s.profile_id}}),onSuccess:()=>{i.success("Member resumed"),j()},onError:a=>i.error(a.message)}),_=N({mutationFn:a=>u({data:{profile_id:s.profile_id,hard:a}}),onSuccess:()=>{i.success("Member removed"),n(null),j()},onError:a=>i.error(a.message)});return e.jsxs("tr",{className:"align-top",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(We,{member:s,onSaved:j}),f==="paused"&&e.jsx("span",{className:"rounded-full border bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-700 dark:text-amber-300",children:"paused"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.email??s.profile_id})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex flex-wrap gap-1",children:s.roles.map(a=>e.jsx("span",{className:"rounded-full border bg-muted px-2 py-0.5 text-[11px]",children:a},a))})}),s.permissions.filter(a=>!B(a.surface)).map(a=>{const F=a.source==="override"?a.level:"default";return e.jsx("td",{className:"px-2 py-3",children:e.jsxs(A,{value:F,onValueChange:S=>p(a.surface,S),disabled:d,children:[e.jsx(q,{className:`h-8 w-full min-w-[100px] text-xs ${a.source==="override"?Oe(a.level):""}`,children:e.jsx(L,{})}),e.jsxs(Q,{children:[e.jsxs(v,{value:"default",children:["Default (",a.level,")"]}),e.jsx(v,{value:"write",children:"Write"}),e.jsx(v,{value:"read",children:"Read"}),e.jsx(v,{value:"none",children:"None"})]})]})},a.surface)}),e.jsx("td",{className:"px-2 py-3",children:e.jsx(me,{checked:l,disabled:d,"aria-label":`${O.platform_preview} for ${s.full_name??s.email??"this member"}`,onCheckedChange:a=>p("platform_preview",a?"read":"default")})}),e.jsxs("td",{className:"px-2 py-3 text-right",children:[e.jsxs(pe,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",children:e.jsx(Me,{className:"h-4 w-4"})})}),e.jsxs(he,{align:"end",children:[f==="active"?e.jsx(E,{onClick:()=>b.mutate(),disabled:b.isPending,children:"Pause member"}):e.jsx(E,{onClick:()=>C.mutate(),disabled:C.isPending,children:"Resume member"}),e.jsx(je,{}),e.jsx(E,{className:"text-destructive focus:text-destructive",onClick:()=>n("soft"),children:"Remove from staff"}),e.jsx(E,{className:"text-destructive focus:text-destructive",onClick:()=>n("hard"),children:"Delete account..."})]})]}),e.jsx(ve,{open:c!==null,onOpenChange:a=>!a&&n(null),children:e.jsxs(ge,{children:[e.jsxs(Ne,{children:[e.jsx(be,{children:c==="hard"?"Delete account permanently?":"Remove from staff?"}),e.jsx(ye,{children:c==="hard"?`This deletes the auth account for ${s.email??s.profile_id}. They will lose login access. Their team ticket is revoked.`:`Revokes all staff roles for ${s.email??s.profile_id}. Their HQ team ticket is revoked. They keep their auth account but lose HQ access.`})]}),e.jsxs(we,{children:[e.jsx(Ce,{children:"Cancel"}),e.jsx(Se,{onClick:()=>_.mutate(c==="hard"),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:c==="hard"?"Delete account":"Remove"})]})]})})]})]})}function We({member:s,onSaved:d}){const[p,m]=x.useState(!1),[o,u]=x.useState(s.full_name??""),t=h(ue),c=N({mutationFn:()=>{const n=o.trim().split(/\s+/);return t({data:{profile_id:s.profile_id,first_name:n[0]??"",last_name:n.slice(1).join(" ")}})},onSuccess:()=>{i.success("Name saved"),m(!1),d()},onError:n=>i.error(n.message)});return p?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(R,{autoFocus:!0,value:o,onChange:n=>u(n.target.value),onKeyDown:n=>{n.key==="Enter"&&o.trim()&&c.mutate(),n.key==="Escape"&&m(!1)},placeholder:"First Last",className:"h-7 w-44 text-sm"}),e.jsx(g,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",disabled:!o.trim()||c.isPending,onClick:()=>c.mutate(),"aria-label":"Save name",children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsx(g,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>m(!1),"aria-label":"Cancel",children:e.jsx(z,{className:"h-4 w-4"})})]}):e.jsxs("button",{type:"button",onClick:()=>{u(s.full_name??""),m(!0)},className:"group inline-flex items-center gap-1.5 text-left font-medium hover:underline",title:"Edit name",children:[s.full_name??e.jsx("span",{className:"text-muted-foreground",children:"Add name"}),e.jsx(Pe,{className:"h-3 w-3 opacity-0 transition-opacity group-hover:opacity-60"})]})}
1export{os 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.