import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,s as r,t as i}from"./hooks.module-BrXTvcfS.js";import{Dt as a,G as o,H as s,Ot as c,it as l}from"./content_renderer-DOj8g78V.js";import{a as u}from"./i18n-BaLR3UdQ.js";import{i as d}from"./toast-C6WyPqyA.js";import{t as f}from"./jsxRuntime.module-Cao1NCKs.js";import{J as p}from"./hooks-ClTXKdUl.js";import{n as m}from"./note_autocomplete-BT55HtG6.js";import{t as h}from"./Modal-hBkTa-Ee.js";import{t as g}from"./Button-Du0dYm4Z.js";import{t as _}from"./FormTextBox-BLQGoABI.js";import{t as v}from"./NoteList-Oyhm1asf.js";import{t as y}from"./NoteAutocomplete-Cpc7J_0A.js";import{t as b}from"./FormGroup-DqPd4bBP.js";n(),t();function x(){let[t,n]=r(),[a,s]=r(``),[l,d]=r(null),[x,C]=r(!1),w=i(null);p(`cloneNoteIdsTo`,({noteIds:e})=>{(!e||e.length===0)&&(e=[o.tabManager.getActiveContextNoteId()??``]);let t=[];for(let n of e)t.includes(n)||t.push(n);n(t),C(!0)});function T(){if(!t)return;let e=l?.notePath;if(!e){c(u(`clone_to.no_path_to_clone_to`));return}C(!1),S(e,t,a)}return f(h,{className:`clone-to-dialog`,title:u(`clone_to.clone_notes_to`),helpPageId:`IakOLONlIfGI`,size:`lg`,footer:f(e,{children:[f(g,{text:u(`modal.cancel`),onClick:()=>C(!1)}),f(g,{text:u(`clone_to.clone_to_selected_note`),keyboardShortcut:`Enter`})]}),onSubmit:T,onShown:()=>m(w.current),onHidden:()=>C(!1),show:x,children:[f(`h5`,{children:u(`clone_to.notes_to_clone`)}),f(v,{style:{maxHeight:`200px`,overflow:`auto`},noteIds:t}),f(b,{name:`target-parent-note`,label:u(`clone_to.target_parent_note`),children:f(y,{placeholder:u(`clone_to.search_for_note_by_its_name`),onChange:d,inputRef:w})}),f(b,{name:`clone-prefix`,label:u(`clone_to.prefix_optional`),title:u(`clone_to.cloned_note_prefix_title`),children:f(_,{onChange:s})})]})}async function S(e,t,n){let{noteId:r,parentNoteId:i}=a.getNoteIdAndParentIdFromUrl(e);if(!r||!i)return;let o=await s.getBranchId(i,r);if(!(!o||!t))for(let e of t){await l.cloneNoteToBranch(e,o,n);let t=await s.getNote(e),r=s.getBranch(o);if(!t||!r)continue;let i=await r.getNote();i&&d.showMessage(u(`clone_to.note_cloned`,{clonedTitle:t.title,targetTitle:i.title}))}}export{x as default};