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}from"./content_renderer-DOj8g78V.js";import{a as c}from"./i18n-BaLR3UdQ.js";import{t as l}from"./server-BXh06Wz_.js";import{i as u}from"./toast-C6WyPqyA.js";import{t as d}from"./jsxRuntime.module-Cao1NCKs.js";import{J as f}from"./hooks-ClTXKdUl.js";import{t as p}from"./Icon-BEnt7704.js";import{t as m}from"./Modal-hBkTa-Ee.js";import{t as h}from"./Button-Du0dYm4Z.js";import{r as g,t as _}from"./Card-DHxlpCRf.js";import{t as v}from"./FormGroup-DqPd4bBP.js";n(),t();var y=`virt-`;function b(){let[t,n]=r(!1),[l,u]=r([]),[b,C]=r(``),w=i(null);f(`editBranchPrefix`,async e=>{let t=[];if(e?.selectedOrActiveBranchIds&&e.selectedOrActiveBranchIds.length>0)t=e.selectedOrActiveBranchIds.filter(e=>!e.startsWith(y));else{let e=o.tabManager.getActiveContextNotePath();if(!e)return;let{noteId:n,parentNoteId:r}=a.getNoteIdAndParentIdFromUrl(e);if(!n||!r)return;let i=await s.getBranchId(r,n);if(!i)return;let c=await s.getNote(r);if(!c||c.type===`search`)return;t=[i]}if(t.length===0)return;let r=t.map(e=>s.getBranch(e)).filter(e=>e!==null);r.length!==0&&(u(r),C(r[0]?.prefix??``),n(!0))});async function T(){l.length!==0&&(l.length===1?await x(l[0].branchId,b):await S(l.map(e=>e.branchId),b),n(!1))}return d(m,{className:`branch-prefix-dialog`,title:l.length===1?c(`branch_prefix.edit_branch_prefix`):c(`branch_prefix.edit_branch_prefix_multiple`,{count:l.length}),size:`lg`,onShown:()=>w.current?.select(),onHidden:()=>n(!1),onSubmit:T,helpPageId:`TBwsyfadTA18`,footer:d(e,{children:[d(h,{text:c(`branch_prefix.cancel`),onClick:()=>n(!1)}),d(h,{text:c(`branch_prefix.save`),kind:`primary`})]}),show:t,children:[d(v,{label:c(`branch_prefix.prefix`),name:`prefix`,description:c(`branch_prefix.description`),children:d(`input`,{class:`branch-prefix-input form-control`,value:b,ref:w,onChange:e=>C(e.target.value)})}),d(_,{heading:c(`branch_prefix.preview_in_tree`),children:d(g,{noPadding:!0,children:d(`ul`,{className:`preview-list`,children:l.map(e=>{let t=e.getNoteFromCache();return t&&d(`li`,{children:[d(p,{icon:t.getIcon()}),b&&d(`span`,{className:`branch-prefix-current`,children:[b,` - `]}),t.title]},e.branchId)})})})})]})}async function x(e,t){await l.put(`branches/${e}/set-prefix`,{prefix:t}),u.showMessage(c(`branch_prefix.branch_prefix_saved`))}async function S(e,t){await l.put(`branches/set-prefix-batch`,{branchIds:e,prefix:t}),u.showMessage(c(`branch_prefix.branch_prefix_saved_multiple`,{count:e.length}))}export{b as default};