1import{r as a,x as l,bj as x,p as t,v as c,T as d,a0 as E,a1 as y,ag as I,aZ as F,B as U,ey as z,N as B}from"./index-C9IH3k-2.js";import{S as M}from"./index-8jSYgZzf.js";import{R as $}from"./SaveOutlined-gwhZZcip.js";import{F as N}from"./Table-isZ0WXp4.js";import"./index-BOwvFOZJ.js";import"./TemplateUtil-D1DzmWLm.js";import"./Wrapper-ChjuDa3w.js";import"./HelperMethods-C-ewwU_x.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";const{Title:Z}=d,Y=()=>{const[g,p]=a.useState(!1),[S,m]=a.useState(!1),[j,w]=a.useState([]),[P,b]=a.useState([]),[r,u]=a.useState(null),[h,v]=a.useState("");a.useEffect(()=>{f()},[]);const f=async()=>{p(!0);try{const[s,e,i]=await Promise.all([l("/api/v1/admin/basicUser/permission/list"),l("/api/v1/admin/basicUser/role/list"),l("/api/v1/admin/basicUserPermission")]);w(s.data||{}),b(e.data||[]),u(i.data||null)}catch{x.error({title:"Error",description:"Failed to fetch permissions data"})}finally{p(!1)}},C=(s,e)=>{if(!r)return;const i=r.rolePermissions.map(n=>{if(n.role===s){const o=n.permissions||[],D=o.includes(e);return{...n,permissions:D?o.filter(A=>A!==e):[...o,e]}}return n});u({...r,rolePermissions:i})},L=(s,e)=>r&&r.rolePermissions.find(n=>n.role===s)?.permissions?.includes(e)||!1,R=async()=>{m(!0);try{await z("/api/v1/admin/basicUserPermission",{...r},!1),B.success("Permissions updated successfully"),f()}catch{x.error({title:"Error",description:"Failed to update permissions"})}finally{m(!1)}},T=[{title:"Permission",dataIndex:"permission",key:"permission",width:300,fixed:"left",render:(s,e)=>t.jsxs(c,{orientation:"vertical",size:0,children:[t.jsx(d.Text,{strong:!0,children:e.label}),e.description&&t.jsx(d.Text,{type:"secondary",style:{fontSize:"12px"},children:e.description})]})},...P.map(s=>({title:s.roleDisplay,dataIndex:s.role,key:s.role,align:"center",width:150,render:(e,i)=>t.jsx(M,{checked:L(s.role,i.key),onChange:()=>C(s.role,i.key)})}))],k=(j||[]).map(s=>({key:s.id,label:s.label,description:s.description,permission:s.label})).filter(s=>{const e=h.toLowerCase();return s.label.toLowerCase().includes(e)||s.key.toLowerCase().includes(e)||(s.description||"").toLowerCase().includes(e)});return t.jsxs(E,{gutter:[16,16],children:[t.jsx(y,{span:24,children:t.jsxs(c,{style:{width:"100%",justifyContent:"space-between"},children:[t.jsx(Z,{level:4,style:{margin:0},children:"Agents and Permissions"}),t.jsxs(c,{children:[t.jsx(I,{placeholder:"Search permissions...",prefix:t.jsx(F,{}),value:h,onChange:s=>v(s.target.value),style:{width:250},allowClear:!0}),t.jsx(U,{type:"primary",icon:t.jsx($,{}),loading:S,onClick:R,children:"Save Changes"})]})]})}),t.jsx(y,{span:24,children:t.jsx(N,{columns:T,dataSource:k,loading:g,pagination:!1,bordered:!0,scroll:{x:1200,y:600},size:"middle"})})]})};export{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.