import{dv as Ge,bT as Ve,g7 as G,el as ee,gK as We,cj as ze,b_ as L,iO as Ke,gH as f,fH as e,hg as Ye,jD as U,bU as E,gw as Ze,iv as w,eI as Q,ck as y,aD as b,c7 as se,cz as O,dI as oe,hc as Xe,ey as ce,ce as I,d3 as Je,d9 as es,dn as ss,d7 as ts,d8 as ns,dq as rs,eO as le,dk as is,fl as as,fr as V,h5 as os,dl as cs,gR as te,f0 as S,e5 as ls,e6 as ne,es as re,iG as H,hT as T,hi as de,bL as v,bE as k,iF as ue,iY as he,iE as W,ap as ge,ao as pe,aZ as P,r as me,jG as fe,h1 as be,cI as R,cQ as xe,bt as je,iC as ds,iN as ye,fI as us,A as ve,bV as N,bn as Re,d2 as hs,gZ as gs,dN as ps,cG as ms,au as fs,iP as bs,iQ as xs,S as js,bS as ys,eo as vs,gX as Rs,C as Cs,$ as Ms,cl as $,aP as Os,dx as Ss,K as ks,c6 as Es,c5 as F}from"./strapi-ye6TfKul.js";import{P as x}from"./index-mKkR6X_j.js";import{s as ie}from"./sortBy-BHPiSJWc.js";import{t as ws,m as Ps}from"./tail-NS65kI-u.js";import{S as As}from"./SearchInput-BQCQgGkW.js";import"./_baseMap-CagEH0Ml.js";import"./_baseEach-BHFmNlG9.js";var Ds=function(s){Ge(t,s);function t(r,a){var n;return n=s.call(this)||this,n.client=r,n.queries=[],n.result=[],n.observers=[],n.observersMap={},a&&n.setQueries(a),n}var i=t.prototype;return i.onSubscribe=function(){var a=this;this.listeners.length===1&&this.observers.forEach(function(n){n.subscribe(function(o){a.onUpdate(n,o)})})},i.onUnsubscribe=function(){this.listeners.length||this.destroy()},i.destroy=function(){this.listeners=[],this.observers.forEach(function(a){a.destroy()})},i.setQueries=function(a,n){this.queries=a,this.updateObservers(n)},i.getCurrentResult=function(){return this.result},i.getOptimisticResult=function(a){return this.findMatchingObservers(a).map(function(n){return n.observer.getOptimisticResult(n.defaultedQueryOptions)})},i.findMatchingObservers=function(a){var n=this,o=this.observers,l=a.map(function(h){return n.client.defaultQueryObserverOptions(h)}),d=l.flatMap(function(h){var j=o.find(function(C){return C.options.queryHash===h.queryHash});return j!=null?[{defaultedQueryOptions:h,observer:j}]:[]}),p=d.map(function(h){return h.defaultedQueryOptions.queryHash}),g=l.filter(function(h){return!p.includes(h.queryHash)}),u=o.filter(function(h){return!d.some(function(j){return j.observer===h})}),c=g.map(function(h,j){if(h.keepPreviousData){var C=u[j];if(C!==void 0)return{defaultedQueryOptions:h,observer:C}}return{defaultedQueryOptions:h,observer:n.getObserver(h)}}),m=function(j,C){return l.indexOf(j.defaultedQueryOptions)-l.indexOf(C.defaultedQueryOptions)};return d.concat(c).sort(m)},i.getObserver=function(a){var n=this.client.defaultQueryObserverOptions(a),o=this.observersMap[n.queryHash];return o??new Ve(this.client,n)},i.updateObservers=function(a){var n=this;G.batch(function(){var o=n.observers,l=n.findMatchingObservers(n.queries);l.forEach(function(c){return c.observer.setOptions(c.defaultedQueryOptions,a)});var d=l.map(function(c){return c.observer}),p=Object.fromEntries(d.map(function(c){return[c.options.queryHash,c]})),g=d.map(function(c){return c.getCurrentResult()}),u=d.some(function(c,m){return c!==o[m]});o.length===d.length&&!u||(n.observers=d,n.observersMap=p,n.result=g,n.hasListeners()&&(ee(o,d).forEach(function(c){c.destroy()}),ee(d,o).forEach(function(c){c.subscribe(function(m){n.onUpdate(c,m)})}),n.notify()))})},i.onUpdate=function(a,n){var o=this.observers.indexOf(a);o!==-1&&(this.result=We(this.result,o,n),this.notify())},i.notify=function(){var a=this;G.batch(function(){a.listeners.forEach(function(n){n(a.result)})})},t}(ze);function Ls(s){var t=L.useRef(!1),i=L.useState(0),r=i[1],a=Ke(),n=f.useMemo(function(){return s.map(function(p){var g=a.defaultQueryObserverOptions(p);return g.optimisticResults=!0,g})},[s,a]),o=L.useState(function(){return new Ds(a,n)}),l=o[0],d=l.getOptimisticResult(n);return L.useEffect(function(){t.current=!0;var p=l.subscribe(G.batchCalls(function(){t.current&&r(function(g){return g+1})}));return function(){t.current=!1,p()}},[l]),L.useEffect(function(){l.setQueries(n,{listeners:!1})},[n,l]),d}const Ce=f.createContext({}),Me=({children:s,value:t})=>e.jsx(Ce.Provider,{value:t,children:s}),z=()=>f.useContext(Ce);Me.propTypes={children:x.node.isRequired,value:x.object.isRequired};function Is(s){switch(s){case"application":return"Application";case"plugin::content-manager":return"Content manager";case"plugin::content-type-builder":return"Content types builder";case"plugin::documentation":return"Documentation";case"plugin::email":return"Email";case"plugin::i18n":return"i18n";case"plugin::upload":return"Media Library";case"plugin::users-permissions":return"Users-permissions";default:return Ye(s.replace("api::","").replace("plugin::",""))}}const Ts=(s,t)=>{const i=Object.keys(t).sort().map(r=>({name:r,isOpen:!1}));return{...s,collapses:i}},ae=Ze`
  background: ${s=>s.theme.colors.primary100};

  #cog {
    opacity: 1;
  }
`,_s=U(E)`
  display: flex;
  justify-content: space-between;
  align-items: center;

  #cog {
    opacity: 0;
    path {
      fill: ${s=>s.theme.colors.primary600};
    }
  }

  /* Show active style both on hover and when the action is selected */
  ${s=>s.isActive&&ae}
  &:hover {
    ${ae}
  }
`,qs=U.div`
  flex: 1;
  align-self: center;
  border-top: 1px solid ${({theme:s})=>s.colors.neutral150};
`,Oe=({subCategory:s})=>{const{formatMessage:t}=w(),{onChange:i,onChangeSelectAll:r,onSelectedAction:a,selectedAction:n,modifiedData:o}=z(),l=f.useMemo(()=>Q(o,s.name,{}),[o,s]),d=f.useMemo(()=>Object.values(l).every(c=>c.enabled===!0),[l]),p=f.useMemo(()=>Object.values(l).some(c=>c.enabled===!0)&&!d,[l,d]),g=f.useCallback(({target:{name:c}})=>{r({target:{name:c,value:!d}})},[d,r]),u=f.useCallback(c=>n===c,[n]);return e.jsxs(E,{children:[e.jsxs(y,{justifyContent:"space-between",alignItems:"center",children:[e.jsx(E,{paddingRight:4,children:e.jsx(b,{variant:"sigma",textColor:"neutral600",children:s.label})}),e.jsx(qs,{}),e.jsx(E,{paddingLeft:4,children:e.jsx(se,{name:s.name,checked:p?"indeterminate":d,onCheckedChange:c=>g({target:{name:s.name,value:c}}),children:t({id:"app.utils.select-all",defaultMessage:"Select all"})})})]}),e.jsx(y,{paddingTop:6,paddingBottom:6,children:e.jsx(O.Root,{gap:2,style:{flex:1},children:s.actions.map(c=>{const m=`${c.name}.enabled`;return e.jsx(O.Item,{col:4,xs:12,s:6,direction:"column",alignItems:"stretch",children:e.jsxs(_s,{isActive:u(c.name),padding:2,hasRadius:!0,children:[e.jsx(se,{checked:Q(o,m,!1),name:m,onCheckedChange:h=>i({target:{name:m,value:h}}),children:c.label}),e.jsxs("button",{type:"button",onClick:()=>a(c.name),style:{display:"inline-flex",alignItems:"center"},children:[e.jsx(oe,{tag:"span",children:t({id:"app.utils.show-bound-route",defaultMessage:"Show bound route for {route}"},{route:c.name})}),e.jsx(Xe,{id:"cog",cursor:"pointer"})]})]})},c.name)})})})]})};Oe.propTypes={subCategory:x.object.isRequired};const Se=({name:s,permissions:t})=>{const i=f.useMemo(()=>ie(Object.values(t.controllers).reduce((r,a,n)=>{const o=`${s}.controllers.${Object.keys(t.controllers)[n]}`,l=ie(Object.keys(a).reduce((d,p)=>[...d,{...a[p],label:p,name:`${o}.${p}`}],[]),"label");return[...r,{actions:l,label:Object.keys(t.controllers)[n],name:o}]},[]),"label"),[s,t]);return e.jsx(E,{padding:6,children:i.map(r=>e.jsx(Oe,{subCategory:r},r.name))})};Se.propTypes={name:x.string.isRequired,permissions:x.object.isRequired};const Ns={collapses:[]},$s=(s,t)=>ce(s,i=>{switch(t.type){case"TOGGLE_COLLAPSE":{i.collapses=s.collapses.map((r,a)=>a===t.index?{...r,isOpen:!r.isOpen}:{...r,isOpen:!1});break}default:return i}}),Qs=()=>{const{modifiedData:s}=z(),{formatMessage:t}=w(),[{collapses:i}]=f.useReducer($s,Ns,r=>Ts(r,s));return e.jsx(I.Root,{size:"M",children:e.jsx(y,{direction:"column",alignItems:"stretch",gap:1,children:i.map((r,a)=>e.jsxs(I.Item,{value:r.name,children:[e.jsx(I.Header,{variant:a%2===0?"secondary":void 0,children:e.jsx(I.Trigger,{caretPosition:"right",description:t({id:"users-permissions.Plugin.permissions.plugins.description",defaultMessage:"Define all allowed actions for the {name} plugin."},{name:r.name}),children:Is(r.name)})}),e.jsx(I.Content,{children:e.jsx(Se,{permissions:s[r.name],name:r.name})})]},r.name))})})};var Us=Je,Hs=ts,Bs=ns,Fs=es,Gs=ss,Vs=rs,Ws=200;function zs(s,t,i,r){var a=-1,n=Hs,o=!0,l=s.length,d=[],p=t.length;if(!l)return d;i&&(t=Fs(t,Gs(i))),r?(n=Bs,o=!1):t.length>=Ws&&(n=Vs,o=!1,t=new Us(t));e:for(;++a<l;){var g=s[a],u=i==null?g:i(g);if(g=r||g!==0?g:0,o&&u===u){for(var c=p;c--;)if(t[c]===u)continue e;d.push(g)}else n(t,u,r)||d.push(g)}return d}var Ks=zs,Ys=Ks,Zs=is,Xs=as,Js=Zs(function(s,t){return Xs(s)?Ys(s,t):[]}),et=Js;const st=le(et),tt=s=>{switch(s){case"POST":return{text:"success600",border:"success200",background:"success100"};case"GET":return{text:"secondary600",border:"secondary200",background:"secondary100"};case"PUT":return{text:"warning600",border:"warning200",background:"warning100"};case"DELETE":return{text:"danger600",border:"danger200",background:"danger100"};default:return{text:"neutral600",border:"neutral200",background:"neutral100"}}},nt=U(E)`
  margin: -1px;
  border-radius: ${({theme:s})=>s.spaces[1]} 0 0 ${({theme:s})=>s.spaces[1]};
`;function K({route:s}){const{formatMessage:t}=w(),{method:i,handler:r,path:a}=s,n=a?ws(a.split("/")):[],[o="",l=""]=r?r.split("."):[],d=tt(s.method);return e.jsxs(y,{direction:"column",alignItems:"stretch",gap:2,children:[e.jsxs(b,{variant:"delta",tag:"h3",children:[t({id:"users-permissions.BoundRoute.title",defaultMessage:"Bound route to"})," ",e.jsx("span",{children:o}),e.jsxs(b,{variant:"delta",textColor:"primary600",children:[".",l]})]}),e.jsxs(y,{hasRadius:!0,background:"neutral0",borderColor:"neutral200",gap:0,children:[e.jsx(nt,{background:d.background,borderColor:d.border,padding:2,children:e.jsx(b,{fontWeight:"bold",textColor:d.text,children:i})}),e.jsx(E,{paddingLeft:2,paddingRight:2,children:Ps(n,p=>e.jsxs(b,{textColor:p.includes(":")?"neutral600":"neutral900",children:["/",p]},p))})]})]})}K.defaultProps={route:{handler:"Nocontroller.error",method:"GET",path:"/there-is-no-path"}};K.propTypes={route:x.shape({handler:x.string,method:x.string,path:x.string})};const rt=()=>{const{formatMessage:s}=w(),{selectedAction:t,routes:i}=z(),r=st(t.split("."),"controllers"),a=Q(i,r[0]),n=r.slice(1).join("."),o=V(a)?[]:a.filter(l=>l.handler.endsWith(n));return e.jsx(O.Item,{col:5,xs:12,background:"neutral150",paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,style:{minHeight:"100%"},direction:"column",alignItems:"stretch",children:t?e.jsx(y,{direction:"column",alignItems:"stretch",gap:2,children:o.map((l,d)=>e.jsx(K,{route:l},d))}):e.jsxs(y,{direction:"column",alignItems:"stretch",gap:2,children:[e.jsx(b,{variant:"delta",tag:"h3",children:s({id:"users-permissions.Policies.header.title",defaultMessage:"Advanced settings"})}),e.jsx(b,{tag:"p",textColor:"neutral600",children:s({id:"users-permissions.Policies.header.hint",defaultMessage:"Select the application's actions or the plugin's actions and click on the cog icon to display the bound route"})})]})})},it=(s,t,i)=>({...s,initialData:t,modifiedData:t,routes:i});var at=cs,ot=os;function ct(s,t,i){return s&&s.length?(t=i||t===void 0?1:ot(t),at(s,0,t<0?0:t)):[]}var lt=ct;const dt=le(lt),ut={initialData:{},modifiedData:{},routes:{},selectedAction:"",policies:[]},ht=(s,t)=>ce(s,i=>{switch(t.type){case"ON_CHANGE":{const r=t.keys.length,a=t.keys[r-1]==="enabled";if(t.value&&a){const n=dt(t.keys,r-1).join(".");i.selectedAction=n}te(i,["modifiedData",...t.keys],t.value);break}case"ON_CHANGE_SELECT_ALL":{const r=["modifiedData",...t.keys],a=Q(s,r,{}),n=Object.keys(a).reduce((o,l)=>(o[l]={...a[l],enabled:t.value},o),{});te(i,r,n);break}case"ON_RESET":{i.modifiedData=s.initialData;break}case"ON_SUBMIT_SUCCEEDED":{i.initialData=s.modifiedData;break}case"SELECT_ACTION":{const{actionToSelect:r}=t;i.selectedAction=r===s.selectedAction?"":r;break}default:return i}}),ke=f.forwardRef(({permissions:s,routes:t},i)=>{const{formatMessage:r}=w(),[a,n]=f.useReducer(ht,ut,g=>it(g,s,t));f.useImperativeHandle(i,()=>({getPermissions(){return{permissions:a.modifiedData}},resetForm(){n({type:"ON_RESET"})},setFormAfterSubmit(){n({type:"ON_SUBMIT_SUCCEEDED"})}}));const p={...a,onChange:({target:{name:g,value:u}})=>n({type:"ON_CHANGE",keys:g.split("."),value:u==="empty__string_value"?"":u}),onChangeSelectAll:({target:{name:g,value:u}})=>n({type:"ON_CHANGE_SELECT_ALL",keys:g.split("."),value:u}),onSelectedAction:g=>n({type:"SELECT_ACTION",actionToSelect:g})};return e.jsx(Me,{value:p,children:e.jsxs(O.Root,{gap:0,shadow:"filterShadow",hasRadius:!0,background:"neutral0",children:[e.jsx(O.Item,{col:7,xs:12,paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,direction:"column",alignItems:"stretch",children:e.jsxs(y,{direction:"column",alignItems:"stretch",gap:6,children:[e.jsxs(y,{direction:"column",alignItems:"stretch",gap:2,children:[e.jsx(b,{variant:"delta",tag:"h2",children:r({id:S("Plugins.header.title"),defaultMessage:"Permissions"})}),e.jsx(b,{tag:"p",textColor:"neutral600",children:r({id:S("Plugins.header.description"),defaultMessage:"Only actions bound by a route are listed below."})})]}),e.jsx(Qs,{})]})}),e.jsx(rt,{})]})})});ke.propTypes={permissions:x.object.isRequired,routes:x.object.isRequired};var Ee=f.memo(ke);const we=ls().shape({name:ne().required(re.required.id),description:ne().required(re.required.id)}),gt=s=>Object.keys(s).reduce((t,i)=>{const r=s[i].controllers,a=Object.keys(r).reduce((n,o)=>(V(r[o])||(n[o]=r[o]),n),{});return V(a)||(t[i]={controllers:a}),t},{}),Pe=()=>{const{toggleNotification:s}=H(),{get:t}=T(),{formatAPIError:i}=de(S),[{data:r,isLoading:a,error:n,refetch:o},{data:l,isLoading:d,error:p,refetch:g}]=Ls([{queryKey:["users-permissions","permissions"],async queryFn(){const{data:{permissions:m}}=await t("/users-permissions/permissions");return m}},{queryKey:["users-permissions","routes"],async queryFn(){const{data:{routes:m}}=await t("/users-permissions/routes");return m}}]),u=async()=>{await Promise.all([o(),g()])};f.useEffect(()=>{n&&s({type:"danger",message:i(n)})},[s,n,i]),f.useEffect(()=>{p&&s({type:"danger",message:i(p)})},[s,p,i]);const c=a||d;return{permissions:r?gt(r):{},routes:l??{},getData:u,isLoading:c}},pt=()=>{const{formatMessage:s}=w(),{toggleNotification:t}=H(),i=ue(),{isLoading:r,permissions:a,routes:n}=Pe(),{trackUsage:o}=he(),l=f.useRef(),{post:d}=T(),p=W(u=>d("/users-permissions/roles",u),{onError(){t({type:"danger",message:s({id:"notification.error",defaultMessage:"An error occurred"})})},onSuccess(){o("didCreateRole"),t({type:"success",message:s({id:S("Settings.roles.created"),defaultMessage:"Role created"})}),i(-1)}}),g=async u=>{const c=l.current.getPermissions();await p.mutate({...u,...c,users:[]})};return e.jsxs(v.Main,{children:[e.jsx(v.Title,{children:s({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:"Roles"})}),e.jsx(ge,{enableReinitialize:!0,initialValues:{name:"",description:""},onSubmit:g,validationSchema:we,children:({handleSubmit:u,values:c,handleChange:m,errors:h})=>e.jsxs(pe,{noValidate:!0,onSubmit:u,children:[e.jsx(P.Header,{primaryAction:!r&&e.jsx(fe,{type:"submit",loading:p.isLoading,startIcon:e.jsx(be,{}),fullWidth:!0,children:s({id:"global.save",defaultMessage:"Save"})}),title:s({id:"Settings.roles.create.title",defaultMessage:"Create a role"}),subtitle:s({id:"Settings.roles.create.description",defaultMessage:"Define the rights given to the role"}),navigationAction:e.jsx(E,{display:{initial:"none",medium:"block"},children:e.jsx(me,{fallback:".."})})}),e.jsx(P.Content,{children:e.jsxs(y,{background:"neutral0",direction:"column",alignItems:"stretch",gap:7,hasRadius:!0,paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,shadow:"filterShadow",children:[e.jsxs(y,{direction:"column",alignItems:"stretch",children:[e.jsx(b,{variant:"delta",tag:"h2",children:s({id:S("EditPage.form.roles"),defaultMessage:"Role details"})}),e.jsxs(O.Root,{gap:4,children:[e.jsx(O.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsxs(R.Root,{name:"name",error:h?.name?s({id:h.name,defaultMessage:"Name is required"}):!1,required:!0,children:[e.jsx(R.Label,{children:s({id:"global.name",defaultMessage:"Name"})}),e.jsx(xe,{type:"text",value:c.name||"",onChange:m}),e.jsx(R.Error,{})]})}),e.jsx(O.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsxs(R.Root,{name:"description",error:h?.description?s({id:h.description,defaultMessage:"Description is required"}):!1,required:!0,children:[e.jsx(R.Label,{children:s({id:"global.description",defaultMessage:"Description"})}),e.jsx(je,{value:c.description||"",onChange:m}),e.jsx(R.Error,{})]})})]})]}),!r&&e.jsx(Ee,{ref:l,permissions:a,routes:n})]})})]})})]})},mt=()=>e.jsx(v.Protect,{permissions:k.createRole,children:e.jsx(pt,{})}),ft=()=>{const{formatMessage:s}=w(),{toggleNotification:t}=H(),{params:{id:i}}=ds("/settings/users-permissions/roles/:id"),{get:r}=T(),{isLoading:a,routes:n}=Pe(),{data:o,isLoading:l,refetch:d}=ye(["users-permissions","role",i],async()=>{const{data:{role:h}}=await r(`/users-permissions/roles/${i}`);return h}),p=f.useRef(),{put:g}=T(),{formatAPIError:u}=de(),c=W(h=>g(`/users-permissions/roles/${i}`,h),{onError(h){t({type:"danger",message:u(h)})},async onSuccess(){t({type:"success",message:s({id:S("Settings.roles.created"),defaultMessage:"Role edited"})}),await d()}}),m=async h=>{const j=p.current.getPermissions();await c.mutate({...h,...j,users:[]})};return l?e.jsx(v.Loading,{}):e.jsxs(v.Main,{children:[e.jsx(v.Title,{children:s({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:"Roles"})}),e.jsx(ge,{enableReinitialize:!0,initialValues:{name:o.name,description:o.description},onSubmit:m,validationSchema:we,children:({handleSubmit:h,values:j,handleChange:C,errors:A})=>e.jsxs(pe,{noValidate:!0,onSubmit:h,children:[e.jsx(P.Header,{primaryAction:a?null:e.jsx(fe,{disabled:o.code==="strapi-super-admin",type:"submit",loading:c.isLoading,startIcon:e.jsx(be,{}),fullWidth:!0,children:s({id:"global.save",defaultMessage:"Save"})}),title:o.name,subtitle:o.description,navigationAction:e.jsx(E,{display:{initial:"none",medium:"block"},children:e.jsx(me,{fallback:".."})})}),e.jsx(P.Content,{children:e.jsxs(y,{background:"neutral0",direction:"column",alignItems:"stretch",gap:7,hasRadius:!0,paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,shadow:"filterShadow",children:[e.jsxs(y,{direction:"column",alignItems:"stretch",gap:4,children:[e.jsx(b,{variant:"delta",tag:"h2",children:s({id:S("EditPage.form.roles"),defaultMessage:"Role details"})}),e.jsxs(O.Root,{gap:4,children:[e.jsx(O.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsxs(R.Root,{name:"name",error:A?.name?s({id:A.name,defaultMessage:"Name is required"}):!1,required:!0,children:[e.jsx(R.Label,{children:s({id:"global.name",defaultMessage:"Name"})}),e.jsx(xe,{type:"text",value:j.name||"",onChange:C}),e.jsx(R.Error,{})]})}),e.jsx(O.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsxs(R.Root,{name:"description",error:A?.description?s({id:A.description,defaultMessage:"Description is required"}):!1,required:!0,children:[e.jsx(R.Label,{children:s({id:"global.description",defaultMessage:"Description"})}),e.jsx(je,{value:j.description||"",onChange:C}),e.jsx(R.Error,{})]})})]})]}),!a&&e.jsx(Ee,{ref:p,permissions:o.permissions,routes:n})]})})]})})]})},bt=()=>e.jsx(v.Protect,{permissions:k.updateRole,children:e.jsx(ft,{})}),xt=U(ms)`
  align-items: center;
  height: 3.2rem;
  width: 3.2rem;
  display: flex;
  justify-content: center;
  padding: ${({theme:s})=>`${s.spaces[2]}`};

  svg {
    height: 1.6rem;
    width: 1.6rem;

    path {
      fill: ${({theme:s})=>s.colors.neutral500};
    }
  }

  &:hover,
  &:focus {
    svg {
      path {
        fill: ${({theme:s})=>s.colors.neutral800};
      }
    }
  }
`,Y=({sortedRoles:s,canDelete:t,canUpdate:i,setRoleToDelete:r,onDelete:a})=>{const{formatMessage:n}=w(),o=ue(),[l,d]=a,p=u=>t&&!["public","authenticated"].includes(u.type),g=u=>{r(u),d(!l)};return e.jsx(us,{children:s?.map(u=>e.jsxs(ve,{cursor:"pointer",onClick:()=>o(u.id.toString()),children:[e.jsx(N,{width:"20%",children:e.jsx(b,{children:u.name})}),e.jsx(N,{width:"50%",children:e.jsx(b,{children:u.description})}),e.jsx(N,{width:"30%",children:e.jsx(b,{children:n({id:"Roles.RoleRow.user-count",defaultMessage:"{number, plural, =0 {# user} one {# user} other {# users}}"},{number:u.nb_users})})}),e.jsx(N,{children:e.jsxs(y,{justifyContent:"end",onClick:c=>c.stopPropagation(),children:[i?e.jsx(xt,{tag:Re,to:u.id.toString(),"aria-label":n({id:"app.component.table.edit",defaultMessage:"Edit {target}"},{target:`${u.name}`}),children:e.jsx(hs,{})}):null,p(u)&&e.jsx(gs,{onClick:()=>g(u.id.toString()),variant:"ghost",label:n({id:"global.delete-target",defaultMessage:"Delete {target}"},{target:`${u.name}`}),children:e.jsx(ps,{})})]})})]},u.name))})};Y.defaultProps={canDelete:!1,canUpdate:!1};Y.propTypes={onDelete:x.array.isRequired,setRoleToDelete:x.func.isRequired,sortedRoles:x.array.isRequired,canDelete:x.bool,canUpdate:x.bool};const jt=()=>{const{trackUsage:s}=he(),{formatMessage:t,locale:i}=w(),{toggleNotification:r}=H(),{notifyStatus:a}=fs(),[{query:n}]=bs(),o=n?._q||"",[l,d]=f.useState(!1),[p,g]=f.useState(),{del:u,get:c}=T(),{isLoading:m,allowedActions:{canRead:h,canDelete:j,canCreate:C,canUpdate:A}}=xs({create:k.createRole,read:k.readRoles,update:k.updateRole,delete:k.deleteRole}),{isLoading:Ae,data:{roles:Z},isFetching:De,refetch:Le}=ye("get-roles",()=>qe(r,t,a),{initialData:{},enabled:h}),{contains:X}=js(i,{sensitivity:"base"}),J=ys(i,{sensitivity:"base"}),Ie=Ae||De||m,Te=()=>{d(!l)},_e=async(M,D,B)=>{try{await u(`/users-permissions/roles/${M}`)}catch{B({type:"danger",message:D({id:"notification.error",defaultMessage:"An error occured"})})}},qe=async(M,D,B)=>{try{const{data:q}=await c("/users-permissions/roles");return B("The roles have loaded successfully"),q}catch(q){throw M({type:"danger",message:D({id:"notification.error",defaultMessage:"An error occurred"})}),new Error(q)}},Ne={roles:{id:S("Roles.empty"),defaultMessage:"You don't have any roles yet."},search:{id:S("Roles.empty.search"),defaultMessage:"No roles match the search."}},$e=t({id:"global.roles",defaultMessage:"Roles"}),Qe=W(M=>_e(M,t,r),{async onSuccess(){await Le()}}),Ue=async()=>{await Qe.mutateAsync(p),d(!l)},_=(Z||[]).filter(M=>X(M.name,o)||X(M.description,o)).sort((M,D)=>J.compare(M.name,D.name)||J.compare(M.description,D.description)),He=o&&!_.length?"search":"roles",Be=4,Fe=(Z?.length||0)+1;return Ie?e.jsx(v.Loading,{}):e.jsxs(v.Main,{children:[e.jsx(v.Title,{children:t({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:$e})}),e.jsx(P.Header,{title:t({id:"global.roles",defaultMessage:"Roles"}),subtitle:t({id:"Settings.roles.list.description",defaultMessage:"List of roles"}),primaryAction:C?e.jsx(vs,{to:"new",tag:Re,onClick:()=>s("willCreateRole"),startIcon:e.jsx(Rs,{}),size:"S",fullWidth:!0,children:t({id:S("List.button.roles"),defaultMessage:"Add new role"})}):null}),e.jsx(P.Action,{startActions:e.jsx(As,{label:t({id:"app.component.search.label",defaultMessage:"Search"})})}),e.jsxs(P.Content,{children:[!h&&e.jsx(v.NoPermissions,{}),h&&_&&_?.length?e.jsxs(Cs,{colCount:Be,rowCount:Fe,children:[e.jsx(Ms,{children:e.jsxs(ve,{children:[e.jsx($,{children:e.jsx(b,{variant:"sigma",textColor:"neutral600",children:t({id:"global.name",defaultMessage:"Name"})})}),e.jsx($,{children:e.jsx(b,{variant:"sigma",textColor:"neutral600",children:t({id:"global.description",defaultMessage:"Description"})})}),e.jsx($,{children:e.jsx(b,{variant:"sigma",textColor:"neutral600",children:t({id:"global.users",defaultMessage:"Users"})})}),e.jsx($,{children:e.jsx(oe,{children:t({id:"global.actions",defaultMessage:"Actions"})})})]})}),e.jsx(Y,{sortedRoles:_,canDelete:j,canUpdate:A,permissions:k,setRoleToDelete:g,onDelete:[l,d]})]}):e.jsx(Os,{content:t(Ne[He])})]}),e.jsx(Ss.Root,{open:l,onOpenChange:Te,children:e.jsx(ks,{onConfirm:Ue})})]})},yt=()=>e.jsx(v.Protect,{permissions:k.accessRoles,children:e.jsx(jt,{})}),Et=()=>e.jsx(v.Protect,{permissions:k.accessRoles,children:e.jsxs(Es,{children:[e.jsx(F,{index:!0,element:e.jsx(yt,{})}),e.jsx(F,{path:"new",element:e.jsx(mt,{})}),e.jsx(F,{path:":id",element:e.jsx(bt,{})})]})});export{Et as default};
