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