import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,l as r,s as i}from"./hooks.module-BrXTvcfS.js";import{G as a,H as o,Pt as s,Tt as c,ft as l,jt as u,st as d}from"./content_renderer-DOj8g78V.js";import{a as f}from"./i18n-BaLR3UdQ.js";import{t as p}from"./server-BXh06Wz_.js";import{i as m}from"./toast-C6WyPqyA.js";import{t as h}from"./jsxRuntime.module-Cao1NCKs.js";import{J as g,Q as _}from"./hooks-ClTXKdUl.js";import{t as v}from"./Dropdown-BUar6udP.js";import{a as y,t as b}from"./FormList-CnuOJg6b.js";import{t as x}from"./Modal-hBkTa-Ee.js";import{t as S}from"./RawHtml-BZRPHliO.js";import{n as C,t as w}from"./formatters-Dszv3NKH.js";import{t as T}from"./NoItems-ZA3b1X1n.js";n(),t();function E(){let[t,n]=i(),[s,l]=i(),[u,d]=i(0),[S,w]=i(!1),[E,O]=i(!1),[k,A]=i(),[M]=_(`eraseEntitiesAfterTimeInSeconds`),[N]=_(`eraseEntitiesAfterTimeScale`);g(`showRecentChanges`,({ancestorNoteId:e})=>{n(e??c.getHoistedNoteId()),O(!1),w(!0)}),g(`showDeletedNotes`,({ancestorNoteId:e})=>{n(e??c.getHoistedNoteId()),O(!0),w(!0)}),r(()=>{if(!t||t===`root`){A(void 0);return}let e=!0;return o.getNote(t,!0).then(t=>{e&&A(t?.title)}),()=>{e=!1}},[t]),r(()=>{t&&p.get(`recent-changes/${t}?deletedOnly=${E}`).then(async e=>{await o.getNotes(e.map(e=>e.noteId),!0);let t=j(e);l(t)})},[S,u,E,t]);let P=f(E?`recent_changes.deleted_notes_title`:`recent_changes.title`),F=C(M,N);return h(x,{title:k?f(`recent_changes.title_with_ancestor`,{title:P,ancestorTitle:k}):P,className:`recent-changes-dialog ${E?`recent-changes-dialog-view-mode-deleted-only`:`recent-changes-dialog-view-mode-all-changes`}`,size:`lg`,scrollable:!0,header:h(v,{className:`recent-changes-actions`,buttonClassName:`custom-title-bar-button bx bx-dots-horizontal-rounded`,title:f(`recent_changes.more_actions`),hideToggleArrow:!0,noSelectButtonStyle:!0,children:[h(y,{icon:`bx bx-trash`,onClick:()=>{p.post(`notes/erase-deleted-notes-now`).then(()=>{d(u+1),m.showMessage(f(`recent_changes.deleted_notes_message`))})},children:f(`recent_changes.erase_notes_button`)}),E&&h(e,{children:[h(b,{}),h(y,{icon:`bx bx-cog`,onClick:()=>void a.triggerCommand(`showOptions`,{section:`_optionsOther`}),children:f(`recent_changes.deleted_notes_settings`)})]})]}),onHidden:()=>w(!1),show:S,children:h(`div`,{className:`recent-changes-content`,children:s?.size?h(D,{groupedByDate:s,setShown:w}):E?h(T,{icon:`bx bx-trash-alt`,text:f(`recent_changes.no_deleted_notes_message`),children:F&&h(`small`,{children:f(`recent_changes.no_deleted_notes_erasure_hint`,{duration:F})})}):h(T,{icon:`bx bx-history`,text:f(`recent_changes.no_changes_message`)})})})}function D({groupedByDate:t,setShown:n}){return h(e,{children:Array.from(t.entries()).map(([e,t])=>h(`div`,{children:[h(`b`,{children:w(e,`full`,`none`)}),h(`ul`,{children:t.map(e=>{let t=e.current_isDeleted,r=w(e.date,`none`,`short`),i=o.getNoteFromCache(e.noteId)?.getBestNotePathString();return h(`li`,{className:t?`deleted-note`:``,children:[h(`span`,{title:e.date,children:r}),i&&!t?h(O,{notePath:i,title:e.current_title}):h(k,{change:e,setShown:n})]})})})]}))})}function O({notePath:e,title:t}){let[n,a]=i(null);return r(()=>{l.createLink(e,{title:t,showNotePath:!0}).then(a)},[e,t]),n?h(S,{className:`note-title`,html:n[0].innerHTML}):h(`span`,{className:`note-title`,children:t})}function k({change:t,setShown:n}){return h(e,{children:[h(`span`,{className:`note-title`,"data-href":`#${t.noteId}?`,"data-note-deleted":!0,children:t.current_title}),`\xA0 (`,h(`a`,{href:`javascript:`,onClick:()=>A(t,n),children:f(`recent_changes.undelete_link`)}),`)`]})}async function A(e,t){let n=!!e.canBeUndeleted;if(!await s.confirm(f(n?`recent_changes.confirm_undelete`:`recent_changes.confirm_undelete_to_default_location`)))return;let r=null;if(!n&&(r=await d.getInboxNote(),!r)){m.showError(f(`recent_changes.undelete_failed`));return}let{undeleted:i,restoredToFallbackParent:o}=await p.put(`notes/${e.noteId}/undelete`,{fallbackParentNoteId:r?.noteId});if(!i){m.showError(f(`recent_changes.undelete_failed`));return}o&&r&&m.showMessage(f(`recent_changes.undeleted_to_default_location`,{title:r.title})),t(!1),await u.waitForMaxKnownEntityChangeId(),a.tabManager.getActiveContext()?.setNote(e.noteId)}function j(e){let t=new Map;for(let n of e){let e=n.date.substr(0,10),r=t.get(e);r||(r=[],t.set(e,r)),r.push(n)}return t}export{E as default};