1import{T as We,U as Me,V as ke,f as Ne,r as u,j as s,B as V,g as w}from"./index-KmHFZaHn.js";import{M as Oe,P as ce,I as G,D as qe,T as Be,y as E}from"./mainLayoutView-DGhcKp9N.js";import{A as _e}from"./ArrowBack-AtIT8wRC.js";import{E as $e}from"./Edit-CQaUMa8N.js";import{r as Ve}from"./hooks-BDLN7iv0.js";import{C as Ge}from"./Container-n4wGPU_F.js";import{B as A}from"./Button-C8Sb69MD.js";import{C as He,a as Ye}from"./CardContent-QaB033Do.js";import{C as Ke}from"./CardHeader-iKTBqFz0.js";import{A as ue}from"./Alert-CU_N5d6i.js";import{T as Qe,a as me}from"./Tabs-C3wiiuzn.js";import{G as j}from"./Grid-C11CGnRI.js";import{T as p}from"./TextField-qpYpiY5v.js";import{M as z}from"./MenuItem-Cls-ng5d.js";import{C as H}from"./CircularProgress-BoPAzVWQ.js";import{T as he}from"./TableContainer-4dL7wXGE.js";import{T as fe}from"./Table-DNa2H64H.js";import{T as xe}from"./TableHead-H8cK9VTO.js";import{T as P,a as m,b as je}from"./TableRow-x087f3a9.js";import{D as Xe,a as Ze,b as es}from"./DialogTitle-B1crsy3x.js";import{F as ss,S as rs}from"./Switch-CLH1qPsX.js";import{D as ts}from"./DialogActions-Dkl5-rA1.js";import"./useThemeProps-CGlgU7Kq.js";import"./useSlot-C-SNmkmh.js";import"./Menu-C17gbmyB.js";import"./Stack-H-AdBRS9.js";var T={},ge;function as(){if(ge)return T;ge=1;var a=We();Object.defineProperty(T,"__esModule",{value:!0}),T.default=void 0;var d=a(Ve()),y=Me();return T.default=(0,d.default)((0,y.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6zM19 4h-3.5l-1-1h-5l-1 1H5v2h14z"}),"Delete"),T}var is=as();const pe=ke(is),L=["ias","sitephoto","mapcard","report"],W=["viewer","editor","admin"],b=(a,d)=>a?.response?.data?.message||a?.response?.data?.error||d,ye=()=>`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Y=a=>{const d=a.trim().toLowerCase();return d==="superadmin"?"admin":d},K=a=>a.trim().toUpperCase(),Ce=a=>{const d=String(a.category??"").trim().toLowerCase(),y=K(String(a.jur??"")),o=Y(String(a.role??"")),i=String(a.username??"").trim();return!i||!d||!y||!o||!L.includes(d)||!W.includes(o)||y!=="*"&&y.length!==2?null:{username:i,category:d,jur:y,role:o}},ns=a=>({localId:ye(),username:a.username,category:String(a.category??"").toLowerCase(),jur:String(a.jur??""),role:String(a.role??"").toLowerCase(),originalCategory:String(a.category??"").toLowerCase(),originalJur:String(a.jur??""),isNew:!1}),os=a=>{const d=new Map;a.forEach(i=>{const C=Ce(i);if(!C)return;const l=C.username.toLowerCase();d.has(l)||d.set(l,new Set),d.get(l).add(C.jur)});const y={};d.forEach((i,C)=>{y[C]=Array.from(i).sort((l,R)=>l==="*"?-1:R==="*"?1:l.localeCompare(R))});const o=Array.from(new Set(Object.values(y).flat())).sort((i,C)=>i==="*"?-1:C==="*"?1:i.localeCompare(C));return{userJurAccess:y,jurOptions:o}},zs=()=>{const a=Ne(),[d,y]=u.useState(0),[o,i]=u.useState(!1),[C,l]=u.useState(""),[R,k]=u.useState([]),[N,Q]=u.useState([]),[we,X]=u.useState(!1),[M,Z]=u.useState({username:"",jur:""}),[be,ee]=u.useState({}),[ve,se]=u.useState([]),[h,U]=u.useState({username:"",jur:"",password:"",confirmPassword:""}),[n,re]=u.useState(null),[Se,O]=u.useState(!1),[Pe,q]=u.useState(!1),[te,g]=u.useState(""),[F,ae]=u.useState(!1),[D,J]=u.useState({password:"",confirmPassword:""}),[ie,v]=u.useState([]),Ue=async()=>{try{const r=(await w.getCountyNameYears()).data?.data??[],t=new Map;r.forEach(c=>{const x=String(c.jur??"").trim();x&&(t.has(x)||t.set(x,{jur:x,name:c.name?.trim()||x}))});const f=Array.from(t.values()).sort((c,x)=>c.jur.localeCompare(x.jur));Q(f),f.length>0&&U(c=>c.jur?c:{...c,jur:f[0].jur})}catch{Q([])}},B=async()=>{try{X(!0),l("");const e=await w.getUsers();k(e)}catch(e){l(b(e,"Failed to load users"))}finally{X(!1)}},I=async()=>{try{const r=(await w.listPermissions()).data?.data??[],{userJurAccess:t,jurOptions:f}=os(r);ee(t),se(f)}catch(e){ee({}),se([]),l(b(e,"Failed to load user jurisdiction filters"))}},Ae=async()=>{const e=h.username.trim(),r=h.jur.trim();if(h.password!==h.confirmPassword){l("Passwords do not match");return}if(!e||!h.password){l("Username and password are required");return}if(!r){l("Jurisdiction is required");return}if(r.length!==2){l("Jurisdiction must be a 2-character code");return}i(!0),l("");try{await w.registerUser({username:e,jur:r,password:h.password,passwordVerify:h.confirmPassword}),E.success("User registered successfully"),await Promise.all([B(),I()]),U({username:"",jur:r,password:"",confirmPassword:""})}catch(t){l(b(t,"Failed to register user"))}finally{i(!1)}},De=async e=>{if(window.confirm(`Are you sure you want to delete user "${e.username}"?`))try{i(!0),l(""),await w.deleteUser(e.username),k(r=>r.filter(t=>t.username!==e.username)),await I(),E.success("User deleted successfully"),n?.username===e.username&&O(!1)}catch(r){l(b(r,"Failed to delete user"))}finally{i(!1)}},Ie=e=>{const r=e.category.trim().toLowerCase(),t=K(e.jur),f=Y(e.role);return!r||!t||!f?"Category, jurisdiction, and role are required for each permission.":L.includes(r)?W.includes(f)?t!=="*"&&t.length!==2?"Jurisdiction must be '*' or a 2-character code.":null:`Role must be one of: ${W.join(", ")}`:`Category must be one of: ${L.join(", ")}`},Ee=async e=>{re(e),ae(e.is_admin),J({password:"",confirmPassword:""}),v([]),g(""),O(!0),q(!0);try{const f=((await w.listPermissions()).data?.data??[]).filter(x=>String(x?.username??"").trim().toLowerCase()===e.username.trim().toLowerCase()),c=new Map;f.forEach(x=>{const S=Ce({...x,username:x?.username||e.username});if(!S)return;const de=`${S.category}|${S.jur}`;
1c.has(de)||c.set(de,S)}),v(Array.from(c.values()).map(ns))}catch(r){g(b(r,"Failed to load user permissions"))}finally{q(!1)}},ne=()=>{O(!1),g(""),q(!1),J({password:"",confirmPassword:""}),v([])},Re=async()=>{if(n)try{i(!0),g(""),await w.setUserAdmin(n.username,F),k(e=>e.map(r=>r.username===n.username?{...r,is_admin:F}:r)),re(e=>e&&{...e,is_admin:F}),E.success(`User ${n.username} ${F?"granted":"revoked"} admin access`)}catch(e){g(b(e,"Failed to update admin status"))}finally{i(!1)}},Fe=async()=>{if(n){if(!D.password){g("Please enter a new password.");return}if(D.password!==D.confirmPassword){g("Passwords do not match.");return}try{i(!0),g(""),await w.updateUserPassword(n.username,D.password),J({password:"",confirmPassword:""}),E.success("Password updated successfully")}catch(e){g(b(e,"Failed to update password"))}finally{i(!1)}}},Je=()=>{n&&v(e=>[...e,{localId:ye(),username:n.username,category:L[0],jur:N[0]?.jur??"*",role:W[0],originalCategory:null,originalJur:null,isNew:!0}])},_=(e,r,t)=>{v(f=>f.map(c=>c.localId===e?{...c,[r]:t}:c))},ze=async e=>{if(!n)return;const r=e.category.trim().toLowerCase(),t=K(e.jur),f=Y(e.role),c=Ie({category:r,jur:t,role:f});if(c){g(c);return}try{i(!0),g(""),!e.isNew&&e.originalCategory&&e.originalJur&&(e.originalCategory!==r||e.originalJur!==t)&&await w.deletePermission(n.username,e.originalCategory,e.originalJur),await w.upsertPermission({username:n.username,category:r,jur:t,role:f}),v(x=>x.map(S=>S.localId===e.localId?{...S,username:n.username,category:r,jur:t,role:f,originalCategory:r,originalJur:t,isNew:!1}:S)),await I(),E.success("Permission saved")}catch(x){g(b(x,"Failed to save permission"))}finally{i(!1)}},Te=async e=>{if(n){if(e.isNew){v(r=>r.filter(t=>t.localId!==e.localId));return}if(window.confirm(`Delete permission ${e.category}/${e.jur} for ${n.username}?`))try{i(!0),g(""),await w.deletePermission(n.username,e.originalCategory||e.category,e.originalJur||e.jur),v(r=>r.filter(t=>t.localId!==e.localId)),await I(),E.success("Permission deleted")}catch(r){g(b(r,"Failed to delete permission"))}finally{i(!1)}}},Le=(e,r)=>{y(r),l(""),r===1&&(B(),I())};u.useEffect(()=>{B(),Ue(),I()},[]);const oe=M.username.trim().toLowerCase(),$=M.jur,le=R.filter(e=>{if(oe&&!e.username.toLowerCase().includes(oe))return!1;if(!$)return!0;const r=be[e.username.toLowerCase()]??[];return $==="*"?r.includes("*"):r.includes($)||r.includes("*")});return s.jsxs(Oe,{children:[s.jsxs(Ge,{maxWidth:"lg",sx:{py:4},children:[s.jsx(A,{startIcon:s.jsx(_e,{}),onClick:()=>a("/dashboard"),sx:{mb:3},children:"Back to Dashboard"}),s.jsxs(He,{children:[s.jsx(Ke,{title:"User Management"}),s.jsxs(Ye,{children:[C&&s.jsx(ue,{severity:"error",sx:{mb:2},onClose:()=>l(""),children:C}),s.jsx(V,{sx:{borderBottom:1,borderColor:"divider",mb:3},children:s.jsxs(Qe,{value:d,onChange:Le,children:[s.jsx(me,{label:"Register New User"}),s.jsx(me,{label:"Manage Users"})]})}),d===0&&s.jsxs(j,{container:!0,spacing:2,children:[s.jsx(j,{item:!0,xs:12,children:s.jsx(p,{label:"Username",fullWidth:!0,value:h.username,onChange:e=>U({...h,username:e.target.value}),disabled:o})}),s.jsx(j,{item:!0,xs:12,children:N.length===0?s.jsx(p,{label:"Jurisdiction",fullWidth:!0,value:h.jur,onChange:e=>U({...h,jur:e.target.value}),disabled:o,helperText:"Enter a 2-character jurisdiction code"}):s.jsx(p,{label:"Jurisdiction",select:!0,fullWidth:!0,value:h.jur,onChange:e=>U({...h,jur:e.target.value}),disabled:o,helperText:"Required 2-character jurisdiction code",children:N.map(e=>s.jsxs(z,{value:e.jur,children:[e.jur," - ",e.name]},e.jur))})}),s.jsx(j,{item:!0,xs:12,sm:6,children:s.jsx(p,{label:"Password",type:"password",fullWidth:!0,value:h.password,onChange:e=>U({...h,password:e.target.value}),disabled:o})}),s.jsx(j,{item:!0,xs:12,sm:6,children:s.jsx(p,{label:"Confirm Password",type:"password",fullWidth:!0,value:h.confirmPassword,onChange:e=>U({...h,confirmPassword:e.target.value}),disabled:o})}),s.jsx(j,{item:!0,xs:12,children:s.jsx(A,{variant:"contained",fullWidth:!0,onClick:Ae,disabled:o,children:o?s.jsx(H,{size:24}):"Register User"})})]}),d===1&&s.jsxs(s.Fragment,{children:[s.jsxs(j,{container:!0,spacing:2,sx:{mb:2},children:[s.jsx(j,{item:!0,xs:12,md:6,children:s.jsx(p,{label:"Filter by username",fullWidth:!0,value:M.username,onChange:e=>Z(r=>({...r,username:e.target.value}))})}),s.jsx(j,{item:!0,xs:12,md:6,children:s.jsxs(p,{label:"Filter by jurisdiction access",
1select:!0,fullWidth:!0,value:M.jur,onChange:e=>Z(r=>({...r,jur:e.target.value})),children:[s.jsx(z,{value:"",children:"All jurisdictions"}),ve.map(e=>s.jsx(z,{value:e,children:e==="*"?"* (all jurisdictions)":e},e))]})})]}),s.jsx(he,{component:ce,children:s.jsxs(fe,{children:[s.jsx(xe,{children:s.jsxs(P,{sx:{backgroundColor:"#f5f5f5"},children:[s.jsx(m,{children:"Username"}),s.jsx(m,{children:"Admin"}),s.jsx(m,{align:"right",children:"Actions"})]})}),s.jsx(je,{children:we?s.jsx(P,{children:s.jsx(m,{colSpan:3,align:"center",sx:{py:3},children:s.jsx(H,{size:24})})}):R.length===0?s.jsx(P,{children:s.jsx(m,{colSpan:3,align:"center",sx:{py:3},children:"No users found"})}):le.length===0?s.jsx(P,{children:s.jsx(m,{colSpan:3,align:"center",sx:{py:3},children:"No users match the current filters"})}):le.map(e=>s.jsxs(P,{children:[s.jsx(m,{children:e.username}),s.jsx(m,{children:e.is_admin?"Yes":"No"}),s.jsxs(m,{align:"right",children:[s.jsx(G,{size:"small",title:"Edit User",onClick:()=>Ee(e),children:s.jsx($e,{fontSize:"small"})}),s.jsx(G,{size:"small",title:"Delete User",onClick:()=>De(e),children:s.jsx(pe,{fontSize:"small"})})]})]},e.id))})]})})]})]})]})]}),s.jsxs(Xe,{open:Se,onClose:ne,maxWidth:"lg",fullWidth:!0,children:[s.jsxs(Ze,{sx:{px:3,pt:3,pb:1.5},children:["Edit User: ",n?.username||""]}),s.jsxs(es,{sx:{pt:1,px:3,pb:2},children:[te&&s.jsx(ue,{severity:"error",sx:{mb:2},onClose:()=>g(""),children:te}),Pe?s.jsx(V,{display:"flex",justifyContent:"center",sx:{py:4},children:s.jsx(H,{})}):s.jsxs(s.Fragment,{children:[s.jsxs(j,{container:!0,spacing:2.5,sx:{mb:2.5},children:[s.jsx(j,{item:!0,xs:12,md:4,children:s.jsx(p,{label:"Username",fullWidth:!0,value:n?.username||"",disabled:!0})}),s.jsx(j,{item:!0,xs:12,md:4,children:s.jsx(ss,{control:s.jsx(rs,{checked:F,onChange:e=>ae(e.target.checked)}),label:"Global Admin"})}),s.jsx(j,{item:!0,xs:12,md:4,sx:{display:"flex",alignItems:"center"},children:s.jsx(A,{variant:"outlined",onClick:Re,disabled:o||!n,fullWidth:!0,children:"Save Admin Status"})}),s.jsx(j,{item:!0,xs:12,md:6,children:s.jsx(p,{label:"New Password",type:"password",fullWidth:!0,value:D.password,onChange:e=>J(r=>({...r,password:e.target.value})),disabled:o})}),s.jsx(j,{item:!0,xs:12,md:6,children:s.jsx(p,{label:"Confirm New Password",type:"password",fullWidth:!0,value:D.confirmPassword,onChange:e=>J(r=>({...r,confirmPassword:e.target.value})),disabled:o})}),s.jsx(j,{item:!0,xs:12,children:s.jsx(A,{variant:"outlined",onClick:Fe,disabled:o||!n,children:"Update Password"})})]}),s.jsx(qe,{sx:{mb:2.5}}),s.jsxs(V,{sx:{display:"flex",justifyContent:"space-between",mb:1.5},children:[s.jsx(Be,{variant:"h6",children:"RBAC Permissions"}),s.jsx(A,{variant:"contained",size:"small",onClick:Je,disabled:o||!n,children:"Add Permission"})]}),s.jsx(he,{component:ce,sx:{borderRadius:1},children:s.jsxs(fe,{size:"small",children:[s.jsx(xe,{children:s.jsxs(P,{children:[s.jsx(m,{children:"Category"}),s.jsx(m,{children:"Jurisdiction"}),s.jsx(m,{children:"Role"}),s.jsx(m,{align:"right",children:"Actions"})]})}),s.jsx(je,{children:ie.length===0?s.jsx(P,{children:s.jsx(m,{colSpan:4,align:"center",children:"No permissions defined for this user."})}):ie.map(e=>s.jsxs(P,{children:[s.jsx(m,{sx:{minWidth:150},children:s.jsx(p,{select:!0,size:"small",fullWidth:!0,value:e.category,onChange:r=>_(e.localId,"category",r.target.value),children:L.map(r=>s.jsx(z,{value:r,children:r},r))})}),s.jsx(m,{sx:{minWidth:160},children:s.jsx(p,{size:"small",fullWidth:!0,placeholder:"* or 2-char code",value:e.jur,onChange:r=>_(e.localId,"jur",r.target.value)})}),s.jsx(m,{sx:{minWidth:150},children:s.jsx(p,{select:!0,size:"small",fullWidth:!0,value:e.role,onChange:r=>_(e.localId,"role",r.target.value),children:W.map(r=>s.jsx(z,{value:r,children:r},r))})}),s.jsxs(m,{align:"right",sx:{whiteSpace:"nowrap"},children:[s.jsx(A,{size:"small",onClick:()=>ze(e),disabled:o,sx:{mr:1},children:"Save"}),s.jsx(G,{size:"small",title:"Delete Permission",onClick:()=>Te(e),disabled:o,children:s.jsx(pe,{fontSize:"small"})})]})]},e.localId))})]})})]})]}),s.jsx(ts,{sx:{px:3,pb:2,pt:.5},children:s.jsx(A,{onClick:ne,children:"Close"})})]})]})};export{zs as AdminUsersView}; 2//# sourceMappingURL=adminUsersView-CNk6mCCR.js.map
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.