import{g as X,u as Z,h as j,i as ee,P as se,t as te,j as ae,k as q,l as k,m as t,n as le,p as I,q as re,R as $,s as ue,v as ie,x as oe,y as ne,z as ce,A as b,B as T,C as ve,D as Ee,E as de,F as he,G as pe,H as ye,I as me,J as O,K as Ae,L as D}from"./app-BvgF5LHD.js";const Be=["/","/homework/","/md/01%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5.html","/md/02%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B.html","/md/03%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE.html","/md/04%E5%90%8C%E6%AD%A5%E6%93%8D%E4%BD%9C.html","/md/05%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B%E4%B8%8E%E5%8E%9F%E5%AD%90%E6%93%8D%E4%BD%9C.html","/md/06%E5%8D%8F%E7%A8%8B.html","/md/","/image/%E6%8D%90%E8%B5%A0/","/md/%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90/01thread%E7%9A%84%E6%9E%84%E9%80%A0%E4%B8%8E%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90.html","/md/%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90/02scoped_lock%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90.html","/md/%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90/03async%E4%B8%8Efuture%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90.html","/md/%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90/04%E7%BA%BF%E7%A8%8B%E6%B1%A0.html","/md/%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90/","/404.html","/image/"],ge="SEARCH_PRO_QUERY_HISTORY",y=O(ge,[]),fe=()=>{const{queryHistoryCount:l}=D;return{enabled:l>0,queryHistory:y,addQueryHistory:i=>{y.value=Array.from(new Set([i,...y.value.slice(0,l-1)]))},removeQueryHistory:i=>{y.value=[...y.value.slice(0,i),...y.value.slice(i+1)]}}},x=l=>Be[l.id]+("anchor"in l?`#${l.anchor}`:""),He="SEARCH_PRO_RESULT_HISTORY",{resultHistoryCount:_}=D,m=O(He,[]),ke=()=>({enabled:_>0,resultHistory:m,addResultHistory:r=>{{const i={link:x(r),display:r.display};"header"in r&&(i.header=r.header),m.value=[i,...m.value.slice(0,_-1)]}},removeResultHistory:r=>{m.value=[...m.value.slice(0,r),...m.value.slice(r+1)]}}),De=l=>{const r=ve(),i=j(),R=Ee(),o=q(0),A=k(()=>o.value>0),E=de([]);return he(()=>{const{search:F,terminate:d}=pe(),B=ye(p=>{const g=p.join(" "),{searchFilter:h=a=>a,splitWord:S,suggestionsFilter:u,...n}=r.value;g?(o.value+=1,F(p.join(" "),i.value,n).then(a=>h(a,g,i.value,R.value)).then(a=>{o.value-=1,E.value=a}).catch(a=>{console.warn(a),o.value-=1,o.value||(E.value=[])})):E.value=[]},D.searchDelay-D.suggestDelay);I([l,i],([p])=>B(p),{immediate:!0}),me(()=>{d()})}),{isSearching:A,results:E}};var Fe=X({name:"SearchResult",props:{queries:{type:Array,required:!0},isFocusing:Boolean},emits:["close","updateQuery"],setup(l,{emit:r}){const i=Z(),R=j(),o=ee(se),{addQueryHistory:A,queryHistory:E,removeQueryHistory:F}=fe(),{resultHistory:d,addResultHistory:B,removeResultHistory:p}=ke(),g=te(l,"queries"),{results:h,isSearching:S}=De(g),u=ae({isQuery:!0,index:0}),n=q(0),a=q(0),L=k(()=>E.value.length>0||d.value.length>0),w=k(()=>h.value.length>0),C=k(()=>h.value[n.value]||null),U=()=>{const{isQuery:e,index:s}=u;s===0?(u.isQuery=!e,u.index=e?d.value.length-1:E.value.length-1):u.index=s-1},Y=()=>{const{isQuery:e,index:s}=u;s===(e?E.value.length-1:d.value.length-1)?(u.isQuery=!e,u.index=0):u.index=s+1},M=()=>{n.value=n.value>0?n.value-1:h.value.length-1,a.value=C.value.contents.length-1},z=()=>{n.value=n.value{a.value{a.value>0?a.value-=1:M()},Q=e=>e.map(s=>Ae(s)?s:t(s[0],s[1])),K=e=>{if(e.type==="customField"){const s=ne[e.index]||"$content",[c,H=""]=ce(s)?s[R.value].split("$content"):s.split("$content");return e.display.map(v=>t("div",Q([c,...v,H])))}return e.display.map(s=>t("div",Q(s)))},f=()=>{n.value=0,a.value=0,r("updateQuery",""),r("close")},V=()=>t("ul",{class:"search-pro-result-list"},t("li",{class:"search-pro-result-list-item"},[t("div",{class:"search-pro-result-title"},o.value.queryHistory),E.value.map((e,s)=>t("div",{class:["search-pro-result-item",{active:u.isQuery&&u.index===s}],onClick:()=>{r("updateQuery",e)}},[t(b,{class:"search-pro-result-type"}),t("div",{class:"search-pro-result-content"},e),t("button",{class:"search-pro-remove-icon",innerHTML:T,onClick:c=>{c.preventDefault(),c.stopPropagation(),F(s)}})]))])),N=()=>t("ul",{class:"search-pro-result-list"},t("li",{class:"search-pro-result-list-item"},[t("div",{class:"search-pro-result-title"},o.value.resultHistory),d.value.map((e,s)=>t($,{to:e.link,class:["search-pro-result-item",{active:!u.isQuery&&u.index===s}],onClick:()=>{f()}},()=>[t(b,{class:"search-pro-result-type"}),t("div",{class:"search-pro-result-content"},[e.header?t("div",{class:"content-header"},e.header):null,t("div",e.display.map(c=>Q(c)).flat())]),t("button",{class:"search-pro-remove-icon",innerHTML:T,onClick:c=>{c.preventDefault(),c.stopPropagation(),p(s)}})]))]));return le("keydown",e=>{if(l.isFocusing){if(w.value){if(e.key==="ArrowUp")J();else if(e.key==="ArrowDown")G();else if(e.key==="Enter"){const s=C.value.contents[a.value];A(l.queries.join(" ")),B(s),i.push(x(s)),f()}}else if(e.key==="ArrowUp")U();else if(e.key==="ArrowDown")Y();else if(e.key==="Enter"){const{index:s}=u;u.isQuery?(r("updateQuery",E.value[s]),e.preventDefault()):(i.push(d.value[s].link),f())}}}),I([n,a],()=>{var e;(e=document.querySelector(".search-pro-result-list-item.active .search-pro-result-item.active"))==null||e.scrollIntoView(!1)},{flush:"post"}),()=>t("div",{class:["search-pro-result-wrapper",{empty:l.queries.length?!w.value:!L.value}],id:"search-pro-results"},l.queries.length?S.value?t(re,{hint:o.value.searching}):w.value?t("ul",{class:"search-pro-result-list"},h.value.map(({title:e,contents:s},c)=>{const H=n.value===c;return t("li",{class:["search-pro-result-list-item",{active:H}]},[t("div",{class:"search-pro-result-title"},e||o.value.defaultTitle),s.map((v,W)=>{const P=H&&a.value===W;return t($,{to:x(v),class:["search-pro-result-item",{active:P,"aria-selected":P}],onClick:()=>{A(l.queries.join(" ")),B(v),f()}},()=>[v.type==="text"?null:t(v.type==="title"?ue:v.type==="heading"?ie:oe,{class:"search-pro-result-type"}),t("div",{class:"search-pro-result-content"},[v.type==="text"&&v.header?t("div",{class:"content-header"},v.header):null,t("div",K(v))])])})])})):o.value.emptyResult:L.value?[V(),N()]:o.value.emptyHistory)}});export{Fe as default};