import{s as g}from"./searchFromField-1654e33e.js";import{c as b}from"./AppLayout-bec1cc2f.js";import{v as w}from"./voiceInput-82d46348.js";import{q as u,u as n,J as m,K as R,v as o,y as d,X as S,F as q,E as v,x as _,D as h,z as k,A as I,aa as C,_ as D}from"./vue-0d7ee8e8.js";import{_ as y}from"./_plugin-vue_export-helper-b15b4a05.js";const F={mixins:[g,w],props:{source:{type:String,required:!0},startAt:{type:Number,default:2},placeholder:{type:String,default:""},label:{type:String,default:""},emptyAutosuggest:{type:String,required:!0},value:{type:String,default:""}},data(){return{items:[],query:this.value,selected:null,displayResults:!1,emptyResults:!1,clearIcon:b}},computed:{formatted(){return this.items.map(e=>({word:e.word}))},locale(){return this.$page.props.layoutData.locale}},watch:{items(){this.$emit("results",this.items)},displayResults(){this.$emit("displayResults",this.displayResults)},query(){this.$emit("query",this.query)}},methods:{fetchItems(e){this.selected=null,this.query!==""?(this.$emit("select",this.query),this.query.length>1&&axios.post(this.source,{_token:document.querySelector('meta[name="csrf-token"]').getAttribute("content"),word:this.query}).then(({data:s})=>{this.items=s,this.items.length?(this.selected=this.items[0].word,this.emptyResults=!1):this.emptyResults=!0}).catch(function(s){console.log(s)})):(this.items=[],this.$emit("select",""))},select(e){this.query=this.items[e].word,this.$emit("select",this.items[e].word)},persist(e){this.query=this.items[e].word,this.$emit("persist",this.items[e].word)},reset(){this.query="",this.items=[],this.selected=null,this.$emit("reset")},itemSelected(e){return this.selected===e?"selected":""},moveSelection(e){e.key==="ArrowDown"?this.selectionDown():e.key==="ArrowUp"?this.selectionUp():e.key==="Enter"&&this.submit()},selectionDown(){this.selected===null?this.selected=0:this.selected+1<this.items.length&&this.selected++,this.select(this.selected)},selectionUp(){this.selected===null?this.selected=this.items.length-1:this.selected>0&&this.selected--,this.select(this.selected)},focusHandler(){this.displayResults=!0,this.fetchItems()},submit(){this.$emit("submit")},updateVoiceInputValue(e){this.query=e}}},x={class:"typeahead"},H=["placeholder","value"],M=["src"],A=["src"],B={key:0,class:"typeahead-results"},E=["onMousedown"],L=["innerHTML"];function T(e,s,i,p,l,t){return u(),n("div",x,[m(o("input",{"onUpdate:modelValue":s[0]||(s[0]=r=>l.query=r),type:"text",class:"search-box-input pe-8",placeholder:i.placeholder,autocomplete:"off",ref:"input",required:"",onInput:s[1]||(s[1]=(...r)=>t.fetchItems&&t.fetchItems(...r)),onKeydown:s[2]||(s[2]=(...r)=>t.moveSelection&&t.moveSelection(...r)),onFocus:s[3]||(s[3]=(...r)=>t.focusHandler&&t.focusHandler(...r)),onBlur:s[4]||(s[4]=r=>l.displayResults=!1),value:l.query},null,40,H),[[R,l.query]]),o("button",{type:"button",class:d(["circle w-9 rounded-full absolute top-0 bottom-0 right-8 cursor-pointer",e.isRecorded?"active":""]),onClick:s[5]||(s[5]=r=>e.recordHandler())},[o("img",{class:"m-auto",src:e.microphoneIcon,width:12,height:12},null,8,M)],2),o("button",{type:"button",class:"typeahead-clear",onClick:s[6]||(s[6]=(...r)=>t.reset&&t.reset(...r)),"aria-label":"clear"},[o("img",{src:l.clearIcon,width:"13.5",height:"18.4",alt:"clear"},null,8,A)]),l.query.length>1&&(t.formatted.length>0||l.emptyResults&&l.query.length>3)?m((u(),n("ul",B,[t.formatted.length>0?(u(!0),n(q,{key:0},v(t.formatted,(r,a)=>(u(),n("li",{key:a,class:"link",onMousedown:c=>t.persist(a)},_(r.word),41,E))),128)):h("",!0),l.emptyResults&&l.query.length>3?(u(),n("li",{key:1,innerHTML:i.emptyAutosuggest},null,8,L)):h("",!0)],512)),[[S,l.displayResults]]):h("",!0)])}const V=y(F,[["render",T]]),U={props:{strings:{type:Object,required:!0},isPart:{type:Boolean,required:!0},pageEntry:{type:String,default:""},allowedChars:{type:String,required:!0}},components:{SearchFormSearchBox:V},data(){return{currentRoute:null,mobile:!1,results:[],displayResults:!1,query:this.pageEntry||""}},methods:{persistSelection(e){this.setRoute(e),this.submit()},setRoute(e){this.currentRoute=this.route("synonyms.search")+"/"+this.urlencode(e)},submit(){this.currentRoute!=null&&this.currentRoute!==""?window.location=`${this.currentRoute}`:window.location.reload()},urlencode(e){return e=e.replace(/[%${}]/g,""),e=(e+"").replaceAll("/",""),encodeURIComponent(e).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A").replace(/~/g,"%7E").replace(/%20/g,"+")},setFormClass(){var e="form synonyms-search-form mb-6";return this.isPart&&(e=e+" transparent"),this.mobile||(e=e+" amp"),e},handleResults(e){this.results=e},handleDisplayResults(e){this.displayResults=e},handleQuery(e){this.query=e}}},N=["innerHTML"],P=["aria-label","innerHTML"];function Q(e,s,i,p,l,t){var a,c;const r=k("SearchFormSearchBox");return u(),n("form",{class:d(t.setFormClass()),id:"synonym-search-form",method:"get",style:C([{position:"relative"},l.query.length>1&&l.displayResults&&((a=l.results)==null?void 0:a.length)>2?`margin-bottom: ${(((c=l.results)==null?void 0:c.length)-1)*36}px;`:null]),onSubmit:s[0]||(s[0]=D((...f)=>t.submit&&t.submit(...f),["prevent"]))},[o("label",{class:"form-label text-center",innerHTML:i.strings.label},null,8,N),I(r,{name:"letters",placeholder:i.strings.letters,value:i.pageEntry,"empty-autosuggest":i.strings["no-autosuggest-results"],"allowed-chars":i.allowedChars,"max-length":30,source:e.route("word-search"),onSelect:t.setRoute,onPersist:t.persistSelection,onSubmit:t.submit,onDisplayResults:t.handleDisplayResults,onResults:t.handleResults,onQuery:t.handleQuery},null,8,["placeholder","value","empty-autosuggest","allowed-chars","source","onSelect","onPersist","onSubmit","onDisplayResults","onResults","onQuery"]),o("button",{type:"submit",class:"button search block mt-3 mx-auto","aria-label":i.strings.search,innerHTML:i.strings.search},null,8,P)],38)}const X=y(U,[["render",Q]]);export{X as S};