import{E as e,L as t,M as n,O as r,a as i,b as a,c as o,d as s,f as c,g as l,i as u,n as d,o as f,rt as p,s as m,t as h,tt as g,v as _,w as v,x as y,y as b}from"./runtime-core.esm-bundler.-wy0QUpZ.js";import{i as x}from"./runtime-dom.esm-bundler.DR37s0zV.js";import{K as S,k as C}from"./utils.CNePm0t_.js";import{a as w,c as T,f as E,h as D,m as O}from"./index.CzQRfW04.js";var k={class:`ui small input global-shortcut-wrapper`},A=[`placeholder`,`aria-expanded`],j={ref:`searchPopup`,class:`file-search-popup`},M={key:0,role:`listbox`,class:`file-search-results flex-items-block`},N=[`aria-selected`,`onClick`,`onMouseenter`,`title`],P={class:`full-path`},F={key:1},I={key:2,class:`tw-p-4`},L=E(c({__name:`RepoFileSearch`,props:{repoLink:{type:String,required:!0},currentRefNameSubURL:{type:String,required:!0},treeListUrl:{type:String,required:!0},noResultsText:{type:String,required:!0},placeholder:{type:String,required:!0}},setup(c){let E=c,L=v(`searchInput`),R=v(`searchPopup`),z=n(``),B=n([]),V=n(0),H=n(!1),U=n(!1),W=u(()=>z.value.length>0),G=u(()=>z.value?T(B.value,z.value):[]),K=S(300,()=>{z.value=L.value.value,V.value=0}),q=()=>{Z(),K()},J=e=>{if(e.isComposing)return;if(e.key===`Escape`){Y(),l(()=>L.value.blur());return}if(!z.value||G.value.length===0)return;let t=t=>{e.preventDefault(),V.value=t,R.value.querySelector(`.file-search-results > :nth-child(${t+1} of .item)`)?.scrollIntoView({block:`nearest`,behavior:`instant`})};if(e.key===`ArrowDown`)t(Math.min(V.value+1,G.value.length-1));else if(e.key===`ArrowUp`)t(Math.max(V.value-1,0));else if(e.key===`Enter`){e.preventDefault();let t=G.value[V.value];t&&Q(t.matchResult.join(``))}},Y=()=>{z.value=``,L.value.value=``},X=e=>{if(!z.value)return;let t=e.target;L.value.contains(t)||R.value.contains(t)||Y()},Z=async()=>{if(!(U.value||H.value)){H.value=!0;try{B.value=await(await O(E.treeListUrl)).json(),U.value=!0}finally{H.value=!1}}};function Q(e){Y(),window.location.href=`${E.repoLink}/src/${w(E.currentRefNameSubURL)}/${w(e)}`}let $=()=>{if(!W.value)return;let e=L.value.getBoundingClientRect(),t=R.value.getBoundingClientRect(),n=document.documentElement,r=R.value.style;r.top=`${n.scrollTop+e.bottom+4}px`,e.x+t.width<n.clientWidth?r.left=`${n.scrollLeft+e.x}px`:r.left=`calc(${n.scrollLeft+n.getBoundingClientRect().width-t.width}px - var(--page-margin-x))`};return _(()=>{let e=C(`file-search-popup-`);R.value.setAttribute(`id`,e),L.value.setAttribute(`aria-controls`,e),document.addEventListener(`click`,X),window.addEventListener(`resize`,$)}),b(()=>{document.removeEventListener(`click`,X),window.removeEventListener(`resize`,$)}),e([z,G],async()=>{z.value&&(await l(),$())}),(e,n)=>(a(),o(`div`,null,[i(`div`,k,[i(`input`,{ref:`searchInput`,placeholder:c.placeholder,autocomplete:`off`,role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":z.value?`true`:`false`,onInput:q,onKeydown:J},null,40,A),n[0]||(n[0]=i(`kbd`,{"data-global-init":`onGlobalShortcut`,"data-shortcut-keys":`t`},`T`,-1))]),(a(),f(d,{to:`body`},[r(i(`div`,j,[W.value?(a(),o(h,{key:0},[G.value.length?(a(),o(`div`,M,[(a(!0),o(h,null,y(G.value,(e,n)=>(a(),o(`div`,{key:e.matchResult.join(``),class:g([`item`,{selected:n===V.value}]),role:`option`,"aria-selected":n===V.value,onClick:t=>Q(e.matchResult.join(``)),onMouseenter:e=>V.value=n,title:e.matchResult.join(``)},[s(t(D),{name:`octicon-file`,class:`file-icon`}),i(`span`,P,[(a(!0),o(h,null,y(e.matchResult,(e,t)=>(a(),o(`span`,{key:t},p(e),1))),128))])],42,N))),128))])):H.value?(a(),o(`div`,F,[...n[1]||(n[1]=[i(`div`,{class:`is-loading`},null,-1)])])):(a(),o(`div`,I,p(E.noResultsText),1))],64)):m(``,!0)],512),[[x,W.value]])]))]))}}),[[`__scopeId`,`data-v-4ec2f37d`]]);export{L as default};
//# sourceMappingURL=RepoFileSearch.DvYnM2Aq.js.map