import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,l as r,s as i,t as a}from"./hooks.module-BrXTvcfS.js";import{H as o}from"./content_renderer-DOj8g78V.js";import{a as s}from"./i18n-BaLR3UdQ.js";import{t as c}from"./server-BXh06Wz_.js";import{t as l}from"./jsxRuntime.module-Cao1NCKs.js";import{J as u}from"./hooks-ClTXKdUl.js";import{t as d}from"./FormToggle-wwys3uI5.js";import{t as f}from"./Modal-hBkTa-Ee.js";import{t as p}from"./Button-Du0dYm4Z.js";import{n as m}from"./NoteLink-DzIkXtVf.js";import{r as h,t as g}from"./Card-DHxlpCRf.js";import{t as _}from"./react-window-B_BjKdTZ.js";import{t as v}from"./OptionsRow-CcGZJWUG.js";n(),t();function y(){let[t,n]=i({}),[m,_]=i(!1),[y,x]=i(!!t.forceDeleteAllClones),[S,C]=i([]),[w,D]=i([]),[O,k]=i(!1),[A,j]=i({totalCloneCount:0}),M=a(null);return u(`showDeleteNotesDialog`,e=>{n(e),_(!1),x(!!e.forceDeleteAllClones),k(!0)}),r(()=>{let{branchIdsToDelete:e}=t;if(!e||e.length===0){j({totalCloneCount:0});return}async function n(){let t=o.getBranches(e,!0),n=[...new Set(t.map(e=>e.noteId))],r=await o.getNotes(n),i=0;for(let t of r){let n=t.getParentBranches().filter(t=>!e.includes(t.branchId));i+=n.length}j({totalCloneCount:i})}n()},[t.branchIdsToDelete]),r(()=>{let{branchIdsToDelete:e,forceDeleteAllClones:n}=t;!e||e.length===0||c.post(`delete-notes-preview`,{branchIdsToDelete:e,deleteAllClones:n||m}).then(e=>{C(e.brokenRelations),D(e.noteIdsToBeDeleted)})},[t,m]),l(f,{className:`delete-notes-dialog`,size:`lg`,title:s(`delete_notes.title`),onShown:()=>M.current?.focus(),onHidden:()=>{t.callback?.({proceed:!1}),k(!1)},footer:l(e,{children:[l(p,{text:s(`delete_notes.cancel`),onClick:()=>k(!1)}),l(p,{text:s(`delete_notes.delete`),kind:`primary`,buttonRef:M,onClick:()=>{t.callback?.({proceed:!0,deleteAllClones:m,eraseNotes:y}),k(!1)}})]}),show:O,children:[l(g,{children:l(h,{children:[l(b,{cloneInfo:A,deleteAllClones:m,setDeleteAllClones:_}),l(v,{name:`erase-notes`,label:s(`delete_notes.erase_notes_label`),description:s(`delete_notes.erase_notes_description`),children:l(d,{disabled:t.forceDeleteAllClones,currentValue:y,onChange:x})})]})}),l(E,{brokenRelations:S}),l(T,{noteIdsToBeDeleted:w})]})}function b({cloneInfo:e,deleteAllClones:t,setDeleteAllClones:n}){let{totalCloneCount:r}=e;return r===0?null:l(v,{name:`delete-all-clones`,label:s(`delete_notes.clones_label`),description:s(`delete_notes.delete_clones_description`,{count:r}),children:l(d,{currentValue:t,onChange:n})})}var x=36,S=100,C=400;function w({index:e,style:t,noteIds:n}){return l(`li`,{style:t,children:l(m,{notePath:n[e],showNotePath:!0,showNoteIcon:!0})},n[e])}function T({noteIdsToBeDeleted:e}){return l(g,{heading:s(`delete_notes.notes_to_be_deleted`,{notesCount:e.length}),children:l(h,{noPadding:e.length>0,children:e.length?e.length>S?l(_,{className:`preview-list`,tagName:`ul`,rowComponent:w,rowCount:e.length,rowHeight:x,rowProps:{noteIds:e},style:{maxHeight:C}}):l(`ul`,{className:`preview-list`,children:e.map(e=>l(`li`,{children:l(m,{notePath:e,showNotePath:!0,showNoteIcon:!0})},e))}):l(`span`,{className:`muted-text`,children:s(`delete_notes.no_note_to_delete`)})})})}function E({brokenRelations:e}){if(!e.length)return null;let t=e.filter(e=>e.value&&e.noteId).map(e=>({noteId:e.value,relationName:e.name,sourceNoteId:e.noteId}));return l(g,{heading:s(`delete_notes.broken_relations_to_be_deleted`,{relationCount:e.length}),children:l(h,{noPadding:!0,children:l(`div`,{style:{overflowX:`auto`},children:l(`table`,{className:`table table-striped`,children:[l(`thead`,{children:l(`tr`,{children:[l(`th`,{children:s(`delete_notes.table_note_with_relation`)}),l(`th`,{children:s(`delete_notes.table_relation`)}),l(`th`,{children:s(`delete_notes.table_points_to`)})]})}),l(`tbody`,{children:t.map((e,t)=>l(`tr`,{children:[l(`td`,{children:l(m,{notePath:e.sourceNoteId,showNoteIcon:!0})}),l(`td`,{children:l(`code`,{children:e.relationName})}),l(`td`,{children:l(m,{notePath:e.noteId,showNoteIcon:!0})})]},t))})]})})})})}export{y as default};