import{d as e,l as t}from"./hooks.module-BrXTvcfS.js";import{a as n}from"./i18n-BaLR3UdQ.js";import{t as r}from"./jsxRuntime.module-Cao1NCKs.js";import{G as i}from"./hooks-ClTXKdUl.js";import{t as a}from"./note_autocomplete-BT55HtG6.js";e();function o({id:e,inputRef:o,text:s,placeholder:c,onChange:l,onTextChange:u,container:d,containerStyle:f,opts:p,noteId:m,noteIdChanged:h,onKeyDown:g,onBlur:_}){let v=i(o);return t(()=>{if(!v.current)return;let e=$(v.current);e.off(`autocomplete:noteselected`).off(`autocomplete:commandselected`),a.initNoteAutocomplete(e,{...p,container:d?.current}),u&&e.on(`input`,()=>u(e[0].value)),g&&e.on(`keydown`,e=>e.originalEvent&&g(e.originalEvent)),_&&e.on(`blur`,()=>_(e.getSelectedNoteId()??``))},[p,d?.current]),t(()=>{if(!v.current)return;let e=$(v.current);if(l||h){let t=(e,t)=>{if(l?.(t),h){let e=t?.notePath?.split(`/`)?.at(-1);h(e)}},n=e=>{v.current?.value||t(e,null)};return e.on(`autocomplete:noteselected`,t).on(`autocomplete:externallinkselected`,t).on(`autocomplete:commandselected`,t).on(`change`,n),()=>{e.off(`autocomplete:noteselected`,t).off(`autocomplete:externallinkselected`,t).off(`autocomplete:commandselected`,t).off(`change`,n)}}},[p,d?.current,l,h]),t(()=>{if(!v.current)return;let e=$(v.current);m?e.setNote(m):s?a.setText(e,s):(e.setSelectedNotePath(``),e.autocomplete(`val`,``),v.current.value=``)},[s,m]),r(`div`,{className:`input-group`,style:f,children:r(`input`,{id:e,ref:v,className:`note-autocomplete form-control`,placeholder:c??n(`add_link.search_note`)})})}export{o as t};