import{r as S,d as u,dN as p,j as r,ak as h,C as c,dF as y,ce as m,dM as k,u as f,z as g,q as w}from"./index-lOezWVmi.js";function j(){return(e,t)=>{if(t.type==="save"){const n=t.payload,o=[...e.undoStack,n];return{currentState:n,undoStack:o,redoStack:[]}}if(t.type==="undo"){if(e.undoStack.length<2)return e;const n=e.undoStack[e.undoStack.length-1],o=e.undoStack[e.undoStack.length-2],s=e.undoStack.slice(0,e.undoStack.length-1),d=[...e.redoStack,n];return{currentState:o,undoStack:s,redoStack:d}}if(t.type==="redo"){if(!e.redoStack.length)return e;const n=e.redoStack[e.redoStack.length-1],o=[...e.undoStack,n],s=e.redoStack.slice(0,e.redoStack.length-1);return{currentState:n,undoStack:o,redoStack:s}}return e}}function U(e){const{initialState:t}=e,[n,o]=S.useReducer(j(),{currentState:t,undoStack:[],redoStack:[]});S.useEffect(()=>{s(t)},[]),u.useListener(window,a=>{const l=a.ctrlKey||a.metaKey;l&&!a.shiftKey&&a.key.toLowerCase()==="z"&&(a.preventDefault(),d()),l&&a.shiftKey&&a.key.toLowerCase()==="z"&&(a.preventDefault(),i())},"keydown");const s=a=>{o({type:"save",payload:a})},d=()=>{o({type:"undo"})},i=()=>{o({type:"redo"})};return{desiredState:n.currentState,undo:d,redo:i,save:s}}const G=({modifiedCount:e,onUndoChange:t,itemName:n,actionText:o})=>{const s=p(navigator.userAgent)==="macos"?"⌘":"ctrl";return r.jsxs("div",{className:"modified-actions",children:[r.jsxs("div",{className:"modified-status",children:[r.jsx(u.Icon,{name:"status-in-progress-small"}),r.jsx("span",{children:`${e} ${h(n,e)} will be ${o??"modified"}`})]}),r.jsxs(u.Button,{hasIcon:!0,className:"u-no-margin--bottom",dense:!0,onClick:t,title:`Undo most recent change (${s}+z)`,children:[r.jsx(u.Icon,{name:"restart"}),r.jsx("span",{children:"Undo"})]})]})},x=["can_delete","can_edit"],C=async e=>{const t=new URLSearchParams;return t.set("recursion","1"),m(t,e,x),fetch(`/1.0/auth/groups?${t.toString()}`).then(c).then(n=>(n.metadata.map(k),n.metadata))},b=async e=>{await fetch("/1.0/auth/groups",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(c)},R=async e=>{await fetch(`/1.0/auth/groups/${encodeURIComponent(e)}`,{method:"DELETE"}).then(c)},K=async e=>Promise.allSettled(e.map(async t=>R(t))).then(y),$=async e=>{await fetch(`/1.0/auth/groups/${encodeURIComponent(e.name)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(c)},N=async(e,t)=>{await fetch(`/1.0/auth/groups/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}).then(c)},O=()=>{const{isFineGrained:e}=f();return g({queryKey:[w.authGroups],queryFn:async()=>C(e),enabled:e!==null})};export{G as M,U as a,$ as b,b as c,K as d,N as r,O as u};
