import{iv as L,fH as e,A,bV as x,aD as l,ck as $,bU as B,gZ as U,i$ as O,bL as m,hi as W,iG as F,gH as T,iP as H,iQ as V,iF as q,hT as z,aZ as D,jG as G,gX as _,C as Q,$ as Z,cl as f,dI as K,fI as X,b as J,d2 as Y,dN as ee,b6 as se,dx as te,K as ne,ey as ae,ft as ie}from"./strapi-ye6TfKul.js";import{S as oe}from"./SearchInput-BQCQgGkW.js";import{u as le}from"./useAdminRoles-C08Egt77.js";import{s as re}from"./selectors-Br3dx8yO.js";const de=({id:s,name:a,description:n,usersCount:c,icons:u,rowIndex:j,canUpdate:g,cursor:h})=>{const{formatMessage:r}=L(),[,C]=u,d=r({id:"Roles.RoleRow.user-count",defaultMessage:"{number, plural, =0 {#  user} one {#  user} other {# users}}"},{number:c});return e.jsxs(A,{cursor:h,"aria-rowindex":j,onClick:g?C.onClick:void 0,children:[e.jsx(x,{maxWidth:"13rem",children:e.jsx(l,{ellipsis:!0,textColor:"neutral800",children:a})}),e.jsx(x,{maxWidth:"25rem",children:e.jsx(l,{ellipsis:!0,textColor:"neutral800",children:n})}),e.jsx(x,{children:e.jsx(l,{textColor:"neutral800",children:d})}),e.jsx(x,{children:e.jsx($,{justifyContent:"flex-end",onClick:i=>i.stopPropagation(),children:u.map((i,p)=>i?e.jsx(B,{paddingLeft:p===0?0:1,children:e.jsx(U,{...i,variant:"ghost"})},i.label):null)})})]},s)},ce=()=>{const{formatMessage:s}=L(),a=O(re),{formatAPIError:n}=W(),{toggleNotification:c}=F(),[u,j]=T.useState(!1),[{query:g}]=H(),{isLoading:h,allowedActions:{canCreate:r,canDelete:C,canRead:d,canUpdate:i}}=V(a.settings?.roles),{roles:p,refetch:w}=le({filters:g?._q?{name:{$containsi:g._q}}:void 0},{refetchOnMountOrArgChange:!0,skip:h||!d}),E=q(),[{roleToDelete:k},b]=T.useReducer(ge,ue),{post:P}=z(),y=async()=>{try{b({type:"ON_REMOVE_ROLES"}),await P("/admin/roles/batch-delete",{ids:[k]}),await w(),b({type:"RESET_DATA_TO_DELETE"})}catch(t){ie(t)&&c({type:"danger",message:n(t)})}},R=()=>E("new"),M=()=>j(t=>!t),S=t=>o=>{o.preventDefault(),o.stopPropagation(),t.usersCount?c({type:"info",message:s({id:"Roles.ListPage.notification.delete-not-allowed"})}):(b({type:"SET_ROLE_TO_DELETE",id:t.id}),M())},I=t=>o=>{o.preventDefault(),o.stopPropagation(),E(`duplicate/${t.id}`)},v=p.length+1,N=6;return h?e.jsx(m.Loading,{}):e.jsxs(m.Main,{children:[e.jsx(m.Title,{children:s({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:"Roles"})}),e.jsx(D.Header,{primaryAction:r?e.jsx(G,{onClick:R,startIcon:e.jsx(_,{}),size:"S",fullWidth:!0,children:s({id:"Settings.roles.list.button.add",defaultMessage:"Add new role"})}):null,title:s({id:"global.roles",defaultMessage:"roles"}),subtitle:s({id:"Settings.roles.list.description",defaultMessage:"List of roles"})}),d&&e.jsx(D.Action,{startActions:e.jsx(oe,{label:s({id:"app.component.search.label",defaultMessage:"Search for {target}"},{target:s({id:"global.roles",defaultMessage:"roles"})})})}),d&&e.jsx(D.Content,{children:e.jsxs(Q,{colCount:N,rowCount:v,footer:r?e.jsx(se,{cursor:"pointer",onClick:R,icon:e.jsx(_,{}),children:s({id:"Settings.roles.list.button.add",defaultMessage:"Add new role"})}):null,children:[e.jsx(Z,{children:e.jsxs(A,{"aria-rowindex":1,children:[e.jsx(f,{children:e.jsx(l,{variant:"sigma",textColor:"neutral600",children:s({id:"global.name",defaultMessage:"Name"})})}),e.jsx(f,{children:e.jsx(l,{variant:"sigma",textColor:"neutral600",children:s({id:"global.description",defaultMessage:"Description"})})}),e.jsx(f,{children:e.jsx(l,{variant:"sigma",textColor:"neutral600",children:s({id:"global.users",defaultMessage:"Users"})})}),e.jsx(f,{children:e.jsx(K,{children:s({id:"global.actions",defaultMessage:"Actions"})})})]})}),e.jsx(X,{children:p?.map((t,o)=>e.jsx(de,{cursor:"pointer",id:t.id,name:t.name,description:t.description,usersCount:t.usersCount,icons:[r&&{onClick:I(t),label:s({id:"app.utils.duplicate",defaultMessage:"Duplicate"}),children:e.jsx(J,{})},i&&{onClick:()=>E(t.id.toString()),label:s({id:"app.utils.edit",defaultMessage:"Edit"}),children:e.jsx(Y,{})},C&&{onClick:S(t),label:s({id:"global.delete",defaultMessage:"Delete"}),children:e.jsx(ee,{})}].filter(Boolean),rowIndex:o+2,canUpdate:i},t.id))})]})}),e.jsx(te.Root,{open:u,onOpenChange:M,children:e.jsx(ne,{onConfirm:y})})]})},ue={roleToDelete:null,showModalConfirmButtonLoading:!1,shouldRefetchData:!1},ge=(s,a)=>ae(s,n=>{switch(a.type){case"ON_REMOVE_ROLES":{n.showModalConfirmButtonLoading=!0;break}case"ON_REMOVE_ROLES_SUCCEEDED":{n.shouldRefetchData=!0,n.roleToDelete=null;break}case"RESET_DATA_TO_DELETE":{n.shouldRefetchData=!1,n.roleToDelete=null,n.showModalConfirmButtonLoading=!1;break}case"SET_ROLE_TO_DELETE":{n.roleToDelete=a.id;break}default:return n}}),me=()=>{const s=O(a=>a.admin_app.permissions.settings?.roles.read);return e.jsx(m.Protect,{permissions:s,children:e.jsx(ce,{})})};export{ce as ListPage,me as ProtectedListPage};
