import{a as _,j as e,bf as L,bk as x,T as l,e as I,a8 as N,I as $,aA as O,P as m,v as U,w as V,r as M,u as W,z as q,ak as H,bQ as z,bR as Q,B as R,D as J,ai as w,bd as G,be as K,bg as f,bi as X,bj as Y,bS as Z,g as ee,bc as se,bm as te,bn as ae,bo as ne,J as oe}from"./strapi-D_Y4QZhh.js";import{S as ie}from"./SearchInput-BVyPDjXU.js";import{u as le}from"./useAdminRoles-D0ZP7pQz.js";import{s as re}from"./selectors-CVtJ1Wu7.js";const de=({id:s,name:n,description:a,usersCount:c,icons:u,rowIndex:j,canUpdate:g,cursor:h})=>{const{formatMessage:r}=_(),[,b]=u,d=r({id:"Roles.RoleRow.user-count",defaultMessage:"{number, plural, =0 {#  user} one {#  user} other {# users}}"},{number:c});return e.jsxs(L,{cursor:h,"aria-rowindex":j,onClick:g?b.onClick:void 0,children:[e.jsx(x,{maxWidth:"13rem",children:e.jsx(l,{ellipsis:!0,textColor:"neutral800",children:n})}),e.jsx(x,{maxWidth:"25rem",children:e.jsx(l,{ellipsis:!0,textColor:"neutral800",children:a})}),e.jsx(x,{children:e.jsx(l,{textColor:"neutral800",children:d})}),e.jsx(x,{children:e.jsx(I,{justifyContent:"flex-end",onClick:o=>o.stopPropagation(),children:u.map((o,p)=>o?e.jsx(N,{paddingLeft:p===0?0:1,children:e.jsx($,{...o,variant:"ghost"})},o.label):null)})})]},s)},ce=()=>{const{formatMessage:s}=_(),n=O(re),{formatAPIError:a}=U(),{toggleNotification:c}=V(),[u,j]=M.useState(!1),[{query:g}]=W(),{isLoading:h,allowedActions:{canCreate:r,canDelete:b,canRead:d,canUpdate:o}}=q(n.settings?.roles),{roles:p,refetch:A}=le({filters:g?._q?{name:{$containsi:g._q}}:void 0},{refetchOnMountOrArgChange:!0,skip:h||!d}),C=H(),[{roleToDelete:k},E]=M.useReducer(ge,ue),{post:y}=Q(),P=async()=>{try{E({type:"ON_REMOVE_ROLES"}),await y("/admin/roles/batch-delete",{ids:[k]}),await A(),E({type:"RESET_DATA_TO_DELETE"})}catch(t){oe(t)&&c({type:"danger",message:a(t)})}},T=()=>C("new"),D=()=>j(t=>!t),S=t=>i=>{i.preventDefault(),i.stopPropagation(),t.usersCount?c({type:"info",message:s({id:"Roles.ListPage.notification.delete-not-allowed"})}):(E({type:"SET_ROLE_TO_DELETE",id:t.id}),D())},v=t=>i=>{i.preventDefault(),i.stopPropagation(),C(`duplicate/${t.id}`)},B=p.length+1,F=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(R.Header,{primaryAction:r?e.jsx(J,{onClick:T,startIcon:e.jsx(w,{}),size:"S",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(R.Action,{startActions:e.jsx(ie,{label:s({id:"app.component.search.label",defaultMessage:"Search for {target}"},{target:s({id:"global.roles",defaultMessage:"roles"})})})}),d&&e.jsx(R.Content,{children:e.jsxs(G,{colCount:F,rowCount:B,footer:r?e.jsx(te,{cursor:"pointer",onClick:T,icon:e.jsx(w,{}),children:s({id:"Settings.roles.list.button.add",defaultMessage:"Add new role"})}):null,children:[e.jsx(K,{children:e.jsxs(L,{"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(X,{children:s({id:"global.actions",defaultMessage:"Actions"})})})]})}),e.jsx(Y,{children:p?.map((t,i)=>e.jsx(de,{cursor:"pointer",id:t.id,name:t.name,description:t.description,usersCount:t.usersCount,icons:[r&&{onClick:v(t),label:s({id:"app.utils.duplicate",defaultMessage:"Duplicate"}),children:e.jsx(Z,{})},o&&{onClick:()=>C(t.id.toString()),label:s({id:"app.utils.edit",defaultMessage:"Edit"}),children:e.jsx(ee,{})},b&&{onClick:S(t),label:s({id:"global.delete",defaultMessage:"Delete"}),children:e.jsx(se,{})}].filter(Boolean),rowIndex:i+2,canUpdate:o},t.id))})]})}),e.jsx(ae.Root,{open:u,onOpenChange:D,children:e.jsx(ne,{onConfirm:P})})]})},ue={roleToDelete:null,showModalConfirmButtonLoading:!1,shouldRefetchData:!1},ge=(s,n)=>z(s,a=>{switch(n.type){case"ON_REMOVE_ROLES":{a.showModalConfirmButtonLoading=!0;break}case"ON_REMOVE_ROLES_SUCCEEDED":{a.shouldRefetchData=!0,a.roleToDelete=null;break}case"RESET_DATA_TO_DELETE":{a.shouldRefetchData=!1,a.roleToDelete=null,a.showModalConfirmButtonLoading=!1;break}case"SET_ROLE_TO_DELETE":{a.roleToDelete=n.id;break}default:return a}}),me=()=>{const s=O(n=>n.admin_app.permissions.settings?.roles.read);return e.jsx(m.Protect,{permissions:s,children:e.jsx(ce,{})})};export{ce as ListPage,me as ProtectedListPage};
