import{v as c,cb as S,r as l,D as p,j as a,d as u,ce as m,a2 as k}from"./index-CzUo07dn.js";const w=()=>new Promise((e,n)=>{fetch("/1.0/auth/groups?recursion=1").then(c).then(t=>e(t.metadata)).catch(n)}),x=e=>new Promise((n,t)=>{fetch("/1.0/auth/groups",{method:"POST",body:JSON.stringify(e)}).then(c).then(n).catch(t)}),f=e=>new Promise((n,t)=>{fetch(`/1.0/auth/groups/${e}`,{method:"DELETE"}).then(c).then(n).catch(t)}),P=e=>new Promise((n,t)=>{Promise.allSettled(e.map(r=>f(r))).then(S).then(n).catch(t)}),j=e=>new Promise((n,t)=>{fetch(`/1.0/auth/groups/${e.name}`,{method:"PUT",body:JSON.stringify(e)}).then(c).then(n).catch(t)}),E=(e,n)=>new Promise((t,r)=>{fetch(`/1.0/auth/groups/${e}`,{method:"POST",body:JSON.stringify({name:n})}).then(c).then(t).catch(r)});function g(){return(e,n)=>{if(n.type==="save"){const t=n.payload,r=[...e.undoStack,t];return{currentState:t,undoStack:r,redoStack:[]}}if(n.type==="undo"){if(e.undoStack.length<2)return e;const t=e.undoStack[e.undoStack.length-1],r=e.undoStack[e.undoStack.length-2],o=e.undoStack.slice(0,e.undoStack.length-1),d=[...e.redoStack,t];return{currentState:r,undoStack:o,redoStack:d}}if(n.type==="redo"){if(!e.redoStack.length)return e;const t=e.redoStack[e.redoStack.length-1],r=[...e.undoStack,t],o=e.redoStack.slice(0,e.redoStack.length-1);return{currentState:t,undoStack:r,redoStack:o}}return e}}function b(e){const{initialState:n}=e,[t,r]=l.useReducer(g(),{currentState:n,undoStack:[],redoStack:[]});l.useEffect(()=>{o(n)},[]),p("keydown",s=>{const h=s.ctrlKey||s.metaKey;h&&!s.shiftKey&&s.key.toLowerCase()==="z"&&(s.preventDefault(),d()),h&&s.shiftKey&&s.key.toLowerCase()==="z"&&(s.preventDefault(),i())});const o=s=>{r({type:"save",payload:s})},d=()=>{r({type:"undo"})},i=()=>{r({type:"redo"})};return{desiredState:t.currentState,undo:d,redo:i,save:o}}const N=({onChange:e,value:n,disabled:t})=>{const r=o=>{e(o.target.value.toLowerCase())};return a.jsx("div",{className:"permission-groups-filter",children:a.jsx(u.Input,{id:"search-groups",name:"search-groups",type:"text",onChange:r,value:n,placeholder:"Search groups",disabled:t,className:"u-no-margin--bottom"})})},C=({modifiedCount:e,onUndoChange:n,itemName:t,actionText:r})=>{const o=m(navigator.userAgent)==="macos"?"⌘":"ctrl";return a.jsxs("div",{className:"modified-actions",children:[a.jsxs("div",{className:"modified-status",children:[a.jsx(u.Icon,{name:"status-in-progress-small"}),a.jsx("span",{children:`${e} ${k(t,e)} will be ${r??"modified"}`})]}),a.jsxs(u.Button,{hasIcon:!0,className:"u-no-margin--bottom",dense:!0,onClick:n,title:`Undo most recent change (${o}+z)`,children:[a.jsx(u.Icon,{name:"restart"}),a.jsx("span",{children:"Undo"})]})]})};export{C as M,N as P,P as a,j as b,x as c,f as d,w as f,E as r,b as u};
