1import{j as e}from"./state-DKBP_IF5.js";import{r as c,L as U}from"./react-vendor-Unhn4PzF.js";import{t as a}from"./ui-Dw3dkPmY.js";import{a as _,e as x}from"./index-Br3_ARw7.js";import{r as N,A as L,U as M,a as D}from"./UserEditModal-C_PEf0oC.js";import{A as b}from"./AdminPageChrome-TdsAIsqV.js";import{s as o}from"./Admin.module-DFfqls-e.js";import"./charts-D5dg506X.js";import"./forms-GD8l5aEM.js";window.CESIUM_BASE_URL="/cesium/";const R=/^[=+\-@]/;function z(s){const n=R.test(s)?`'${s}`:s;return/[",\r\n]/.test(n)?`"${n.replace(/"/g,'""')}"`:n}function C(s,n="No"){return s===void 0?n:s?"Yes":"No"}function F(s){if(!s)return"";const n=new Date(s);return Number.isNaN(n.getTime())?"":n.toISOString().slice(0,10)}function P(s){const n=_[s.agent_type]?.name||s.agent_type;return s.unlimited_queries?`${n} (unlimited)`:s.query_limit!=null?`${n} (${s.queries_used??0}/${s.query_limit})`:n}function I(s,{includeOrgColumn:n=!0}={}){const l=["ID","Name","Email","Email verified","Company","Company size","Job title","Country","Role","Status","Queries","Queries source","Plan",...n?["Organizations"]:[],"Agents","Joined","Marketing consent"],u=s.map(t=>{const d=N(t),p=t.organizations?.length?t.organizations:t.organization_id?[{id:t.organization_id,name:t.organization_name||`Org #${t.organization_id}`}]:[];return[String(t.id),t.full_name,t.username,t.email_verified===void 0?"":C(t.email_verified),t.company_name??"",t.company_size??"",t.job_title??"",t.country??"",t.role,t.is_active?"Active":"Inactive",String(d.count),d.isPlanFallback?"Plan-billed":"Saved messages",t.plan_type??"free",...n?[p.map(f=>f.name).join("; ")]:[],(t.agent_access??[]).map(P).join("; "),F(t.created_at),C(t.marketing_consent)]});return[l,...u].map(t=>t.map(d=>z(d)).join(",")).join(`\r 2`)}function T(s,n){const l=new Blob(["\uFEFF"+s],{type:"text/csv;charset=utf-8;"}),u=URL.createObjectURL(l),t=document.createElement("a");t.href=u,t.download=n,document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(u)}function Y(){const[s,n]=c.useState([]),[l,u]=c.useState(0),[t,d]=c.useState(!0),[p,f]=c.useState(null),[j,y]=c.useState(null),[g,w]=c.useState([]);c.useEffect(()=>{h()},[]);const h=async({showLoading:i=!0}={})=>{try{i&&d(!0);const[r,m]=await Promise.all([x.getUsers(),x.getPendingUsers()]);n(r),u(m.length)}catch(r){a.error(r instanceof Error?r.message:"Failed to load users")}finally{i&&d(!1)}},A=()=>h({showLoading:!1}),k=async i=>{try{await x.toggleUserStatus(i),a.success("User status updated"),h()}catch(r){a.error(r instanceof Error?r.message:"Failed to toggle user status")}},S=async(i,r)=>{if(confirm(`Are you sure you want to delete ${r}?`))try{await x.deleteUser(i),a.success(`${r} has been deleted`),h()}catch(m){a.error(m instanceof Error?m.message:"Failed to delete user")}},E=async(i,r)=>{const m=_[r]?.name||r;if(confirm(`Revoke access to ${m} for ${i.full_name}?`))try{await x.revokeAgentAccess(i.id,r),a.success(`Revoked access to ${m}`),h()}catch(v){a.error(v instanceof Error?v.message:"Failed to revoke access")}},$=c.useCallback(()=>{if(g.length===0){a.error("No users to export in the current view");return}const i=new Date().toISOString().slice(0,10);T(I(g),`solar-intelligence-users-${i}.csv`),a.success(`Exported ${g.length} user${g.length===1?"":"s"}`)},[g]);return t?e.jsxs("div",{className:o.adminContainer,children:[e.jsx(b,{}),e.jsx("p",{children:"Loading..."})]}):e.jsxs("div",{className:o.adminContainer,children:[e.jsx(b,{}),e.jsxs("div",{className:o.adminHeader,children:[e.jsxs("h1",{className:o.adminTitle,children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),"User Management"]}),e.jsxs("div",{className:o.adminActions,children:[e.jsxs(U,{to:"/admin/users/create",className:`${o.btn} ${o.btnPrimary}`,children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"8.5",cy:"7",r:"4"}),e.jsx("line",{x1:"20",y1:"8",x2:"20",y2:"14"}),e.jsx("line",{x1:"23",y1:"11",x2:"17",y2:"11"})]}),"Create User"]}),e.jsxs("button",{type:"button",className:`${o.btn} ${o.btnSecondary}`,onClick:$,disabled:g.length===0,title:"Download the users currently shown, as CSV",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Export"]})]})]}),l>0&&e.jsxs("div",{className:`${o.alert} ${o.alertWarning}`,children:[e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsxs("span",{children:["There ",l===1?"is":"are"," ",e.jsx("strong",{children:l})," pending user",l!==1?"s":""," awaiting approval."," ",e.jsx(U,{to:"/admin/users/pending",style:{textDecoration:"underline",fontWeight:600},children:"View pending users"})]})]}),e.jsx(L,{users:s,onEdit:f,onManageAgents:y,onToggleStatus:i=>k(i.id),onDelete:i=>S(i.id,i.full_name),onRevokeAgent:E,onVisibleUsersChange:w}),p&&e.jsx(M,{user:p,onClose:()=>f(null),onSaved:h}),j&&e.jsx(D,{user:j,onClose:()=>y(null),onChanged:A})]})}
2export{Y 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.