| Current Path : /snap/lxd/current/share/lxd-ui/assets/ |
| Current File : //snap/lxd/current/share/lxd-ui/assets/ModifiedStatusAction-BFtE1DQS.js |
import{r as S,d as a,eA as l,j as d,T as k}from"./index-BsQN_SZU.js";function f(){return(e,r)=>{if(r.type==="save"){const t=r.payload,n=[...e.undoStack,t];return{currentState:t,undoStack:n,redoStack:[]}}if(r.type==="undo"){if(e.undoStack.length<2)return e;const t=e.undoStack[e.undoStack.length-1],n=e.undoStack[e.undoStack.length-2],c=e.undoStack.slice(0,e.undoStack.length-1),s=[...e.redoStack,t];return{currentState:n,undoStack:c,redoStack:s}}if(r.type==="redo"){if(!e.redoStack.length)return e;const t=e.redoStack[e.redoStack.length-1],n=[...e.undoStack,t],c=e.redoStack.slice(0,e.redoStack.length-1);return{currentState:t,undoStack:n,redoStack:c}}return e}}function y(e){const{initialState:r}=e,[t,n]=S.useReducer(f(),{currentState:r,undoStack:[],redoStack:[]});S.useEffect(()=>{c(r)},[]),a.useListener(window,o=>{const i=o.ctrlKey||o.metaKey;i&&!o.shiftKey&&o.key.toLowerCase()==="z"&&(o.preventDefault(),s()),i&&o.shiftKey&&o.key.toLowerCase()==="z"&&(o.preventDefault(),u())},"keydown");const c=o=>{n({type:"save",payload:o})},s=()=>{n({type:"undo"})},u=()=>{n({type:"redo"})};return{desiredState:t.currentState,undo:s,redo:u,save:c}}const h=({modifiedCount:e,onUndoChange:r,itemName:t,actionText:n})=>{const c=l(navigator.userAgent)==="macos"?"⌘":"ctrl";return d.jsxs("div",{className:"modified-actions",children:[d.jsxs("div",{className:"modified-status",children:[d.jsx(a.Icon,{name:"status-in-progress-small"}),d.jsx("span",{children:`${e} ${k(t,e)} will be ${n??"modified"}`})]}),d.jsxs(a.Button,{hasIcon:!0,className:"u-no-margin--bottom",dense:!0,onClick:r,title:`Undo most recent change (${c}+z)`,children:[d.jsx(a.Icon,{name:"restart"}),d.jsx("span",{children:"Undo"})]})]})};export{h as M,y as u};