1import{r as o,j as e}from"./vendor-BwygqmH8.js";import{u as U,s as b}from"./index-BqHqKq3I.js";import{aN as J,ac as H,bf as q,ax as K,h as Y,a5 as G,am as Q,f as V,p as X}from"./icons-B7bQwT6M.js";import"./monitoring-DqjV4dpj.js";import"./deps-D_AQaZss.js";import"./supabase-BM56svY1.js";const k=[{id:"admin",label:"Admin",Icon:q,hint:"Full access"},{id:"cofounder",label:"Co-founder",Icon:K,hint:"Full access + governance"},{id:"sales",label:"Sales",Icon:Y,hint:"CRM, dialer + outbound"},{id:"marketing",label:"Marketing",Icon:G,hint:"Social, broadcasts, brand"},{id:"customer_service",label:"Customer Support",Icon:Q,hint:"Inbound support inbox"}],j=Object.fromEntries(k.map(n=>[n.id,n]));function re(){const{profile:n}=U(),r=n==null?void 0:n.team_id,[c,m]=o.useState(null),[u,l]=o.useState(null),[p,s]=o.useState(!1),[g,_]=o.useState(""),[w,I]=o.useState(""),[z,W]=o.useState("admin"),[h,C]=o.useState(!1),[R,E]=o.useState(null);async function f(t,d){var M;const{data:a}=await b.auth.getSession(),L=(M=a==null?void 0:a.session)==null?void 0:M.access_token,P=`${b.supabaseUrl}/functions/v1/admin-tenant-manager`,v=await fetch(P,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${L}`,apikey:b.supabaseKey},body:JSON.stringify({action:t,...d})}),A=await v.text();let i;try{i=JSON.parse(A)}catch{i={error:A}}if(!v.ok||!(i!=null&&i.ok)){const D=i!=null&&i.stage?` [stage: ${i.stage}]`:"";throw new Error(((i==null?void 0:i.error)||`HTTP ${v.status}`)+D)}return i}async function x(){if(!r){m([]);return}l(null);try{const t=await f("list_operators",{team_id:r});m(t.operators||[])}catch(t){l((t==null?void 0:t.message)||String(t)),m([])}}o.useEffect(()=>{x()},[r]);async function $(t){var d;if(t.preventDefault(),!!g.trim()){C(!0),E(null),l(null);try{const a=await f("invite_operator",{team_id:r,email:g.trim().toLowerCase(),full_name:w.trim()||null,operator_seat:z});E(`${a.email} added as ${((d=j[a.operator_seat])==null?void 0:d.label)||a.operator_seat}. `+(a.inbox_address?`Inbox: ${a.inbox_address}. `:"")+(a.action_link?"Sign-in link generated.":"Magic link generation failed; they can sign in via /login.")),_(""),I(""),await x()}catch(a){l((a==null?void 0:a.message)||String(a))}finally{C(!1)}}}async function N(t,d){s(!0),l(null);try{await f("update_operator_seat",{team_id:r,user_id:t,operator_seat:d}),await x()}catch(a){l((a==null?void 0:a.message)||String(a))}finally{s(!1)}}async function T(t,d){if(confirm(`Remove ${d} from the platform team? They lose admin access immediately.`)){s(!0),l(null);try{await f("remove_operator",{team_id:r,user_id:t}),await x()}catch(a){l((a==null?void 0:a.message)||String(a))}finally{s(!1)}}}const O=o.useMemo(()=>(c||[]).filter(t=>t.team_role==="owner"),[c]),F=o.useMemo(()=>(c||[]).filter(t=>t.team_role!=="owner"),[c]);return c===null?e.jsxs("div",{style:{padding:40,textAlign:"center",color:"var(--muted)"},children:[e.jsx(J,{size:20,className:"spin"})," Loading operator teamâ¦"]}):e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:16,fontSize:13,color:"var(--muted)",lineHeight:1.6},children:["Members of the ",e.jsx("strong",{style:{color:"var(--text)"},children:"REoperative.ai Admin"})," team can sign in to ",e.jsx("code",{children:"/admin"})," and run the SaaS with you. The seat gates what they see: ",e.jsx("strong",{style:{color:"var(--text)"},children:"Sales / Marketing / Support"})," land on their own workspace, while ",e.jsx("strong",{style:{color:"var(--text)"},children:"Admin / Co-founder"})," get full governance access."]}),u&&e.jsx("div",{className:"card",style:{padding:12,marginBottom:12,background:"var(--red-bg, rgba(239,68,68,.1))",color:"var(--red)",fontSize:12},children:u}),R&&e.jsx("div",{className:"card",style:{padding:12,marginBottom:12,background:"rgba(34,197,94,.1)",color:"#16a34a",fontSize:12},children:R}),e.jsxs("form",{onSubmit:$,className:"card",style:{padding:18,marginBottom:20},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:12,display:"flex",alignItems:"center",gap:6},children:[e.jsx(H,{size:14})," Invite an operator"]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0,2fr) minmax(0,2fr) minmax(0,1.5fr) auto",gap:10,alignItems:"end"},children:[e.jsxs("div",{children:[e.jsx("label",{style:y,children:"Email"}),e.jsx("input",{type:"email",required:!0,className:"field-input",value:g,onChange:t=>_(t.target.value),placeholder:"[email protected]",style:S})]}),e.jsxs("div",{children:[e.jsx("label",{style:y,children:"Full name (optional)"}),e.jsx("input",{className:"field-input",value:w,onChange:t=>I(t.target.value),placeholder:"Jane Doe",style:S})]}),e.jsxs("div",{children:[e.jsx("label",{style:y,children:"Seat type"}),e.jsx("select",{className:"field-input",value:z,onChange:t=>W(t.target.value),style:S,children:k.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))})]}),e.jsx("button",{type:"submit",disabled:h||!g.trim(),style:{padding:"8px 14px",borderRadius:8,background:"#80bf42",color:"#fff",border:"none",fontWeight:700,fontSize:13,cursor:h?"wait":"pointer",opacity:h?.6:1,whiteSpace:"nowrap",height:36},children:h?"Invitingâ¦":"Send invite"})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[O.map(t=>e.jsx(B,{row:t,isOwner:!0,onUpdateSeat:N,onRemove:T,busy:p},t.user_id)),F.map(t=>e.jsx(B,{row:t,onUpdateSeat:N,onRemove:T,busy:p},t.user_id))]})]})}function B({row:n,isOwner:r,onUpdateSeat:c,onRemove:m,busy:u}){const p=(j[n.operator_seat]||j.admin).Icon;return e.jsxs("div",{className:"card",style:{padding:14,display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"rgba(128,191,66,.14)",color:"#80bf42",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(p,{size:15,strokeWidth:2.2})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:[n.full_name||n.email,r&&e.jsx("span",{style:{marginLeft:8,fontSize:10,fontWeight:700,padding:"2px 6px",borderRadius:4,background:"var(--gold)",color:"#fff"},children:"OWNER"})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--muted)",marginTop:2},children:[e.jsx(V,{size:11,style:{verticalAlign:-1,marginRight:4}}),n.email]})]}),e.jsx("select",{disabled:r||u,value:n.operator_seat||"admin",onChange:s=>c(n.user_id,s.target.value),style:{appearance:"none",WebkitAppearance:"none",MozAp
1pearance:"none",flexShrink:0,width:168,height:34,padding:"0 30px 0 11px",borderRadius:8,border:"1px solid var(--b2)",background:"var(--bg)",color:"var(--text)",fontSize:12.5,fontWeight:600,fontFamily:"inherit",cursor:r||u?"default":"pointer",opacity:r?.55:1,backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23889' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")`,backgroundRepeat:"no-repeat",backgroundPosition:"right 10px center"},children:k.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))}),!r&&e.jsxs("button",{onClick:()=>m(n.user_id,n.full_name||n.email),disabled:u,title:"Remove from team",style:{display:"inline-flex",alignItems:"center",gap:4,padding:"6px 10px",borderRadius:6,background:"transparent",color:"var(--red)",border:"1px solid var(--b2)",fontSize:12,cursor:u?"wait":"pointer"},children:[e.jsx(X,{size:12})," Remove"]})]})}const y={display:"block",fontSize:10,fontWeight:700,color:"var(--muted)",textTransform:"uppercase",letterSpacing:.5,marginBottom:4},S={width:"100%",padding:"8px 10px",fontSize:13,borderRadius:6,border:"1px solid var(--b2)",background:"var(--bg)",color:"var(--text)",height:36,boxSizing:"border-box"};export{re 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.