import{r as S,d as a,g9 as l,j as d,a2 as k}from"./index-66XtK6kJ.js";function f(){return(t,r)=>{if(r.type==="save"){const e=r.payload,n=[...t.undoStack,e];return{currentState:e,undoStack:n,redoStack:[]}}if(r.type==="undo"){if(t.undoStack.length<2)return t;const e=t.undoStack[t.undoStack.length-1],n=t.undoStack[t.undoStack.length-2],c=t.undoStack.slice(0,t.undoStack.length-1),s=[...t.redoStack,e];return{currentState:n,undoStack:c,redoStack:s}}if(r.type==="redo"){if(!t.redoStack.length)return t;const e=t.redoStack[t.redoStack.length-1],n=[...t.undoStack,e],c=t.redoStack.slice(0,t.redoStack.length-1);return{currentState:e,undoStack:n,redoStack:c}}return t}}function y(t){const{initialState:r}=t,[e,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:e.currentState,undo:s,redo:u,save:c}}const h=({modifiedCount:t,onUndoChange:r,itemName:e,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:`${t} ${k(e,t)} 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};
