import{z as m,m as v,b as p,p as f,E as w,a2 as q,s as x,P as S,a1 as K,az as A,v as g,a6 as N,c as E,F as L,D as M,a5 as z,q as R,a4 as P,X as J,as as O,y as D,M as X,ak as j,d as G,B as H,O as Q,J as Y}from"./entry.DCZz6JvG.js";const Z={__name:"base-auto-complete",props:{inputText:{type:String,default:""},autoCompleteItems:{type:Array,default:()=>[]},placeholder:{type:String,default:""},noInput:{type:Boolean,default:!1},rules:{type:Array,default:()=>[]}},emits:["update:inputText","updateIsFocused","selectKeyword","search"],setup(n,{emit:k}){const d=n,c=k,u=m(d.inputText);v(()=>d.inputText,a=>{u.value=a}),v(u,a=>{c("update:inputText",a),b()});const i=a=>{a&&c("selectKeyword",a)},y=a=>{c("updateIsFocused",a),a||b()},h=m(!1),b=()=>{let a=!0;d.rules.forEach(l=>{l(u.value)!==!0&&(a=!1)}),h.value=!a};return(a,l)=>(p(),f(P,{class:R(["base-auto-complete",{"is-error":x(h)}]),rounded:"lg",color:"transparent"},{default:w(()=>[n.noInput?g("",!0):(p(),f(q,{key:0,modelValue:x(u),"onUpdate:modelValue":l[0]||(l[0]=s=>S(u)?u.value=s:null),class:"mx-3 mb-2","hide-details":"",density:"compact",variant:"plain","prepend-inner-icon":"mdi-magnify",placeholder:n.placeholder,rules:n.rules,"onClick:prependInner":l[1]||(l[1]=s=>c("search")),onKeydown:l[2]||(l[2]=K(A(s=>c("search"),["prevent"]),["enter"])),"onUpdate:focused":y},null,8,["modelValue","placeholder","rules"])),n.autoCompleteItems.length?(p(),f(N,{key:1,class:"auto-complete-list mt-n2","bg-color":"transparent"},{default:w(()=>[(p(!0),E(L,null,M(n.autoCompleteItems,s=>(p(),f(z,{key:s,class:"px-3 text-left auto-complete-item animate can-click",title:s,density:"compact",onMousedown:t=>i(s)},null,8,["title","onMousedown"]))),128))]),_:1})):g("",!0)]),_:1},8,["class"]))}},_={class:"input-wrap"},te={__name:"base-search-block",props:{inputText:{type:String,default:""},isAbsolute:{type:Boolean,default:!1},placeholder:{type:String,default:"searchPlaceholder"}},emits:["update:inputText"],setup(n,{emit:k}){const{$store:d,$getRouteBaseName:c,$localePath:u}=Y(),i=J(),y=O(),{checkIsWallet:h}=D(),{required:b,addressRule:a}=X(),l=k,s=n,t=m(i.query.v?decodeURIComponent(i.query.v):s.inputText),C=m(null),T=async()=>{if(t.value){if(a(t.value)===!0){const r=await h(t.value)?`/wallet/${t.value}`:`/search/details/${t.value}`;y.push(u(r));return}y.push({path:u("/search"),query:{v:encodeURIComponent(t.value)}})}};v(()=>c(i),async e=>{if(e==="search"){t.value=i.query.v?decodeURIComponent(i.query.v):s.inputText;return}t.value="",await C.value.resetValidation()});const I=m([]),o=m(null),U=()=>{o.value=new WebSocket(`${d.backendWebsocketUrl}${d.backendWebsocketVersion}/trending`),o.value.onopen=()=>{o.value.send(t.value||"")},o.value.onmessage=e=>{const r=JSON.parse(e.data)||[];I.value=r.slice(0,5)}},V=()=>{o.value.readyState===1&&(o.value.close(),I.value=[])};v(t,e=>{o.value&&o.value.readyState===1&&(e===null||!e||o.value.send(e))}),v(()=>s.inputText,e=>{t.value=decodeURIComponent(e)}),v(t,e=>{l("update:inputText",e)});const B=e=>{if(e){U();return}V()},F=e=>{t.value=e,T()};return j(()=>{o.value&&o.value.readyState!==3&&V()}),(e,r)=>{const W=Z;return p(),f(Q,{ref_key:"form",ref:C,class:"base-search-block"},{default:w(()=>[G("div",_,[H(W,{"input-text":x(t),"onUpdate:inputText":r[0]||(r[0]=$=>S(t)?t.value=$:null),class:R(["input-text search-auto-complete w-100",{"is-absolute":n.isAbsolute}]),placeholder:e.$t(n.placeholder),"auto-complete-items":x(I),onUpdateIsFocused:B,onSelectKeyword:F,onSearch:r[1]||(r[1]=$=>T())},null,8,["input-text","class","placeholder","auto-complete-items"])])]),_:1},512)}}};export{te as _};