import{d as e,s as t,t as n}from"./hooks.module-BrXTvcfS.js";import{G as r,Gt as i}from"./content_renderer-DOj8g78V.js";import{a}from"./i18n-BaLR3UdQ.js";import{t as o}from"./jsxRuntime.module-Cao1NCKs.js";import{o as s}from"./react_utils-Bz0ffU2Y.js";import{J as c}from"./hooks-ClTXKdUl.js";import{r as l,t as u}from"./note_autocomplete-BT55HtG6.js";import{t as d}from"./Modal-hBkTa-Ee.js";import{t as f}from"./Button-Du0dYm4Z.js";import{t as p}from"./NoteAutocomplete-Cpc7J_0A.js";e();var m=120;function h(){let[e,h]=t(),[g,_]=t(0),v=n(null),y=n(null),[b,x]=t(e===`commands`),[S,C]=t(b?`> `:``),w=n(S),[T,E]=t(!1);async function D(t){let n,r=``;t?(n=`commands`,r=`>`):Date.now()-g<=m*1e3&&w.current?(n=`last-search`,r=w.current):n=`recent-notes`,e!==n&&h(n),C(r),E(!0),_(Date.now())}c(`jumpToNote`,()=>D(!1)),c(`commandPalette`,()=>D(!0));async function O(e){e&&(E(!1),e.notePath?r.tabManager.getActiveContext()?.setNote(e.notePath):e.commandId&&await l.executeCommand(e.commandId))}function k(){let t=s(y);switch(e){case`last-search`:break;case`recent-notes`:u.showRecentNotes(t);break;case`commands`:u.showAllCommands(t);break}if(t.trigger(`focus`),e===`commands`){let e=y.current;if(e){let t=e.value.length;e.setSelectionRange(t,t)}}else t.trigger(`select`);i.bindElShortcut(t,`ctrl+return`,()=>{b||A()})}async function A(){try{E(!1);let e=w.current?.trim();e&&!e.startsWith(`>`)&&await r.triggerCommand(`searchNotes`,{searchString:e})}catch(e){console.error(`Failed to trigger full search:`,e)}}return o(d,{className:`jump-to-note-dialog`,size:`lg`,title:o(p,{placeholder:a(`jump_to_note.search_placeholder`),inputRef:y,container:v,text:S,opts:{allowCreatingNotes:!0,hideGoToSelectedNoteButton:!0,allowJumpToSearchNotes:!0,isCommandPalette:!0},onTextChange:e=>{w.current=e,x(e.startsWith(`>`))},onChange:O}),onShown:k,onHidden:()=>E(!1),footer:!b&&o(f,{className:`show-in-full-text-button`,text:a(`jump_to_note.search_button`),keyboardShortcut:`Ctrl+Enter`,onClick:A}),show:T,children:o(`div`,{className:`algolia-autocomplete-container jump-to-note-results`,ref:v})})}export{h as default};