import{s as m}from"./chunk-DZLz74EQ.js";import{n as f}from"./jotai-DDOP7CKM.js";import{E as p,x as D,y as h}from"./cells-B6jS0AIj.js";import{n as C,t as I}from"./jsx-runtime-DvsdsEjx.js";import{t as v}from"./useEventListener-C5BS4xuN.js";import{t as _}from"./button-nRVaalxL.js";import{r as y}from"./requests-D3Z6okhb.js";import{t as b}from"./use-toast-BiL_AQz9.js";import{n as g}from"./useEvent-d8iQXgui.js";import{n as j}from"./renderShortcut-GP8-boTA.js";var w=m(C(),1),d=m(I(),1);const u=e=>{let t=(0,w.c)(7),l;t[0]===e?l=t[1]:(l=a=>{var i;(a.ctrlKey||a.metaKey)&&a.key==="z"&&(a.preventDefault(),a.stopPropagation(),(i=e.onClick)==null||i.call(e,a))},t[0]=e,t[1]=l);let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r={capture:!0},t[2]=r):r=t[2],v(window,"keydown",l,r);let o=e.children??"Undo",s;t[3]===Symbol.for("react.memo_cache_sentinel")?(s=(0,d.jsx)(j,{className:"ml-2",shortcut:"cmd-z"}),t[3]=s):s=t[3];let n;return t[4]!==o||t[5]!==e?(n=(0,d.jsxs)(_,{"data-testid":"undo-button",size:"sm",variant:"outline",...e,children:[o," ",s]}),t[4]=o,t[5]=e,t[6]=n):n=t[6],n};var k=m(C(),1);function z(){let e=(0,k.c)(4),{deleteCell:t,undoDeleteCell:l}=p(),{sendDeleteCell:r}=y(),o;return e[0]!==t||e[1]!==r||e[2]!==l?(o=s=>{var i;if(f.get(h))return;let{cellId:n}=s,a=(((i=f.get(D).cellData[n])==null?void 0:i.code)??"").trim()==="";if(t({cellId:n}),r({cellId:n}).catch(()=>{l()}),!a){let{dismiss:c}=b({title:"Cell deleted",description:"You can bring it back by clicking undo or through the command palette.",action:(0,d.jsx)(u,{"data-testid":"undo-delete-button",onClick:()=>{l(),x()}})}),x=c}},e[0]=t,e[1]=r,e[2]=l,e[3]=o):o=e[3],g(o)}function K(){let e=(0,k.c)(4),{deleteCell:t,undoDeleteCell:l}=p(),{sendDeleteCell:r}=y(),o;return e[0]!==t||e[1]!==r||e[2]!==l?(o=async s=>{if(f.get(h))return;let{cellIds:n}=s;for(let c of n)await r({cellId:c}).then(()=>{t({cellId:c})});let{dismiss:a}=b({title:"Cells deleted",action:(0,d.jsx)(u,{"data-testid":"undo-delete-button",onClick:()=>{for(let c of n)l();i()}})}),i=a},e[0]=t,e[1]=r,e[2]=l,e[3]=o):o=e[3],g(o)}export{K as n,u as r,z as t};
