import{c as I,e as g}from"./AppLayout-5c633aaa.js";import{v as F}from"./voiceInput-82d46348.js";import{q as a,u as o,J as d,K as w,v as h,y,_ as L,X as S,F as f,E as v,x as k,D as b,z as x,C as T,A as R,aa as _}from"./vue-0d7ee8e8.js";import{_ as p}from"./_plugin-vue_export-helper-b15b4a05.js";const D="/build/assets/minus-solid-white-361a43e3.svg",E="/build/assets/plus-solid-white-10272622.svg",C={methods:{generateSlug(e,t){e=String(e),t=Object(t);var r={delimiter:"-",limit:void 0,lowercase:!0,replacements:{},transliterate:!0};for(var n in r)t.hasOwnProperty(n)||(t[n]=r[n]);for(var n in t.replacements)e=e.replace(RegExp(n,"g"),t.replacements[n]);if(t.transliterate)for(var n in this.charmap)e=e.replace(RegExp(n,"g"),this.charmap[n]);var l=RegExp(`[^${this.regex}0-9]+`,"ig");return e=e.replace(l,t.delimiter),e=e.replace(RegExp("["+t.delimiter+"]{2,}","g"),t.delimiter),e=e.substring(0,t.limit),e=e.replace(RegExp("(^"+t.delimiter+"|"+t.delimiter+"$)","g"),""),e=e.replace(/^-+/,"").replace(/-+$/,""),t.lowercase?e.toLowerCase():e}}},H={props:{value:{type:String,default:""},startAt:{type:Number,default:2},placeholder:{type:String,default:""},label:{type:String,default:""},filter:{type:Boolean,required:!0},emptyAutosuggest:{type:String,required:!0}},mixins:[F],data(){return{items:[],query:this.value,selected:null,displayResults:!1,emptyResults:!1,clearIcon:I}},computed:{formatted(){return this.items.map(e=>({text:e.text,url:e.url}))},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)}},mounted(){this.fetchItems()},methods:{fetchItems(){this.selected=null,this.query!==""?this.query.length>1&&axios.post(this.route("crosswords.search"),{question:this.query}).then(({data:e})=>{this.items=e,this.items.length?this.emptyResults=!1:this.emptyResults=!0}).catch(function(e){console.log(e)}):(this.items=[],this.$emit("select","")),g.emit("letters",[])},select(e){this.query=this.items[e].text,this.$emit("select",this.items[e].url)},persist(e){this.query=this.items[e].text,this.$emit("persist",this.items[e].url)},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("enter")},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}}},M={class:"typeahead"},B=["placeholder"],j=["src"],A={key:0,class:"fas fa-times"},U={key:1},V={key:0,class:"typeahead-results"},O=["onMousedown"],N=["innerHTML"];function Q(e,t,r,n,l,s){return a(),o("div",M,[d(h("input",{"onUpdate:modelValue":t[0]||(t[0]=i=>l.query=i),id:"question",type:"text",class:"search-box-input !pe-16",placeholder:r.placeholder,autocomplete:"off",ref:"input",onInput:t[1]||(t[1]=(...i)=>s.fetchItems&&s.fetchItems(...i)),onKeydown:t[2]||(t[2]=(...i)=>s.moveSelection&&s.moveSelection(...i)),onFocus:t[3]||(t[3]=(...i)=>s.focusHandler&&s.focusHandler(...i)),onBlur:t[4]||(t[4]=i=>l.displayResults=!1)},null,40,B),[[w,l.query]]),h("button",{type:"button",class:y(["circle w-9 rounded-full absolute top-0 bottom-0 right-8 cursor-pointer",e.isRecorded?"active":""]),onClick:t[5]||(t[5]=i=>e.recordHandler())},[h("img",{class:"m-auto",src:e.microphoneIcon,width:12,height:12},null,8,j)],2),h("button",{class:"typeahead-clear-crossword","aria-label":"reset",onClick:t[6]||(t[6]=L((...i)=>s.reset&&s.reset(...i),["prevent"]))},[r.filter?(a(),o("i",A)):(a(),o("span",U,"X"))]),l.query.length>1&&(s.formatted.length>0||l.emptyResults&&l.query.length>3)?d((a(),o("ul",V,[s.formatted.length>0?(a(!0),o(f,{key:0},v(s.formatted,(i,u)=>(a(),o("li",{key:u,class:"link",onMousedown:m=>s.persist(u)},k(i.text),41,O))),128)):b("",!0),l.emptyResults&&l.query.length>3?(a(),o("li",{key:1,innerHTML:r.emptyAutosuggest},null,8,N)):b("",!0)],512)),[[S,l.displayResults]]):b("",!0)])}const z=p(H,[["render",Q]]),K={props:{value:{type:String,default:""},index:{type:Number,required:!0},regex:{type:String,required:!0}},data(){return{letter:this.value,exclude:new RegExp(`[^${this.regex}0-9]`,"g")}},watch:{letter(e){this.$emit("change",{value:e,index:this.index})}},methods:{validate(e){e.data!==null&&(this.letter=e.data.replace("ß","ẞ").replace(this.exclude,"").toUpperCase())},remove(e){e.key==="Backspace"&&(this.letter===""?this.$emit("change",{value:"",index:this.index}):this.letter="",e.preventDefault())}}},P=["placeholder"];function X(e,t,r,n,l,s){return d((a(),o("input",{class:"switch-input",maxlength:"1","onUpdate:modelValue":t[0]||(t[0]=i=>l.letter=i),ref:"input",placeholder:r.index+1,onInput:t[1]||(t[1]=(...i)=>s.validate&&s.validate(...i)),onKeydown:t[2]||(t[2]=(...i)=>s.remove&&s.remove(...i))},null,40,P)),[[w,l.letter]])}const J=p(K,[["render",X]]),G={mixins:[C],props:{value:{type:String,default:""},label:{type:String,default:""},button:{type:String,default:""},filter:{type:Boolean,required:!0},regex:{type:String,required:!0},charmap:{type:Object,required:!0}},components:{Letter:J},data(){return{lengthCap:10,letters:this.value.split("").map(e=>e==="_"?"":e),plusIcon:E,minusIcon:D}},computed:{lengths(){return[...Array(this.lengthCap-1).keys()].map(t=>t+2)}},methods:{select(e,t="change"){this.letters=Array(e).fill(""),this.queryFilter(t)},changeLetter(e){this.$refs.letters[e.index].$el.value=e.value,this.letters[e.index]=e.value,e.value===""?e.index>0&&this.$refs.letters[e.index-1].$el.focus():e.index<this.letters.length-1&&this.$refs.letters[e.index+1].$el.focus(),this.queryFilter("update")},queryFilter(e="change"){var t="";if(e==="change"){var r=this.letters;r.length>0&&r.forEach(function(l){l.length===0||l===" "?t+="_":t+=l})}else{var r=this.$parent.$refs.mobile.$refs.letters;r.length>0&&r.forEach(function(s,i){s.$el.value.length===0||s.$el.value===" "?t+="_":t+=s.$el.value}),e==="add"?t+="_":e==="remove"&&(t=t.slice(0,-1))}let n=decodeURI(location.pathname.split("/")[2]);if(this.route().current("crosswords.question")){axios.post(this.route("crosswords.question.ajax",n),{pattern:t}).then(({data:s})=>{g.emit("updateData",s)}).catch(function(s){console.log(s)}),this.notify();let l=document.getElementById("lengthFilterText");l&&(t.length===0?l.innerText=this.$page.props.placeholders["answers-filter-all"]:l.innerText=t.length+" "+this.$page.props.placeholders["answers-filter-letters"])}},add(){this.select(this.letters.length+1,"add")},remove(){this.select(this.letters.length-1,"remove")},clear(){this.letters=[],this.queryFilter()},notify(){this.$emit("change",this.letters)}}},W={class:"mt-3"},Y=["innerHTML"],Z=["textContent","aria-label","onClick"],$={class:"switch-input-group pb-6 justify-center"},ee={class:"flex items-center justify-center mb-3"},te=["src"],se=["src"],re=["innerHTML"];function le(e,t,r,n,l,s){const i=x("Letter");return a(),o("div",W,[h("label",{class:"form-label text-center search-filter-lable",innerHTML:r.label},null,8,Y),l.letters.length===0?(a(),o("div",{key:0,class:y(["switch switch-lengths w-full",r.filter?"justify-start":"justify-center"])},[(a(!0),o(f,null,v(s.lengths,u=>(a(),o("button",{type:"button",class:"switch-control",key:u,textContent:k(u),"aria-label":u,onClick:m=>s.select(u)},null,8,Z))),128))],2)):(a(),o(f,{key:1},[h("div",$,[(a(!0),o(f,null,v(l.letters,(u,m)=>(a(),T(i,{ref_for:!0,ref:"letters",key:m,value:u,index:m,regex:r.regex,onChange:s.changeLetter},null,8,["value","index","regex","onChange"]))),128))]),h("div",ee,[h("button",{type:"button",class:"button",onClick:t[0]||(t[0]=(...u)=>s.add&&s.add(...u)),"aria-label":"add"},[h("img",{src:l.plusIcon,width:"15.75",height:"18.4",alt:"plus",class:"py-1"},null,8,te)]),d(h("button",{type:"button",class:"button",onClick:t[1]||(t[1]=(...u)=>s.remove&&s.remove(...u)),"aria-label":"remove"},[h("img",{src:l.minusIcon,width:"15.75",height:"18.4",alt:"minus",class:"py-1"},null,8,se)],512),[[S,l.letters.length>2]]),h("button",{type:"button",class:"button",onClick:t[2]||(t[2]=(...u)=>s.clear&&s.clear(...u)),innerHTML:r.button,"aria-label":"button"},null,8,re)])],64))])}const ie=p(G,[["render",le]]),ne={mixins:[C],props:{question:{type:Object,required:!1},pattern:{type:String,required:!1},strings:{type:Object,required:!0},widthFull:{type:Boolean,required:!0},mobile:{type:Boolean,required:!0},formCenter:{type:Boolean,required:!1},regex:{type:String,required:!0},charmap:{type:Object,required:!0}},components:{TypeAhead:z,SearchFilter:ie},data(){var e;return{currentRoute:this.question?this.question.url:"",letters:this.pattern?this.pattern.split("").map(t=>t==="_"?"":t):"",formaction:this.route("crosswords"),filterInput:"",results:[],displayResults:!1,query:((e=this==null?void 0:this.question)==null?void 0:e.text)||""}},created(){g.on("letters",e=>{this.letters=e})},methods:{persistSelection(e,t){this.setRoute(e),this.submit(t)},setRoute(e){this.currentRoute=e},clearRoute(){this.currentRoute=""},updateLetters(e){this.letters=e,g.emit("filtered",this.letters)},submit(e,t=!1){if(t==="enter"&&e.preventDefault(),this.currentRoute!=null&&this.currentRoute!==""&&!t){let l="";var r="",n=this.$refs.mobile.$refs.letters?this.$refs.mobile.$refs.letters:"";n.length>0&&(n.forEach(function(i){i.$el.value===""?r+="_":r+=i.$el.value}),l=`?pattern=${r}`);let s=this.currentRoute.split("/");s=s[s.length-1],this.question&&this.question.slug==s?window.location=`${this.currentRoute}${l}`:(this.mobile&&(l=""),window.location=`${this.currentRoute}`)}else{var r="",n=this.$refs.mobile.$refs.letters?this.$refs.mobile.$refs.letters:"";n.length>0&&n.forEach(function(u){u.$el.value===""?r+="_":r+=u.$el.value});let i=this.generateSlug(this.$refs.typea.$refs.input.value.trim().toLowerCase());i?(this.formaction=this.route("crosswords")+"/"+i,this.$refs.filterInput.value=r,this.persistSelection(this.formaction,e)):r?(this.formaction=this.route("crosswords.answer",r),this.$refs.filterInput.value=r,this.persistSelection(this.formaction,e)):window.location.reload()}},setFormStyle(){var e="position:relative;";return this.formCenter||(e=e+"margin-left:0;"),e},setFormClass(){var e="form mb-4 md:mb-0";return this.mobile||(e=e+" amp"),this.widthFull?e=e+" transparent js-crosswords-search-form crosswords-search-form mx-auto":e=e+" w-full text-center md:text-left js-crosswords-search-form crosswords-search-form mx-auto",e},handleResults(e){this.results=e},handleDisplayResults(e){this.displayResults=e},handleQuery(e){this.query=e}}},ue=["action"],ae=["aria-label","innerHTML"],oe=["aria-label","innerHTML"];function he(e,t,r,n,l,s){var m,q;const i=x("TypeAhead"),u=x("SearchFilter");return a(),o("form",{method:"post",onSubmit:t[4]||(t[4]=c=>s.submit(c)),action:l.formaction,class:y(s.setFormClass()),style:_(l.query.length>1&&l.displayResults&&((m=l.results)==null?void 0:m.length)>4?s.setFormStyle()+` margin-bottom: ${(((q=l.results)==null?void 0:q.length)-3)*36}px;`:s.setFormClass()),ref:"form"},[h("div",{class:y(r.widthFull?"w-full":"w-full px-3"),style:_(r.mobile?"":"padding-left: 0; padding-right: 0;")},[R(i,{value:r.question?r.question.text:"",label:r.strings["enter-question"],"empty-autosuggest":r.strings["no-autosuggest-results"],placeholder:r.strings.placeholder,onSelect:s.setRoute,onPersist:s.persistSelection,onReset:s.clearRoute,onSubmit:t[0]||(t[0]=c=>s.submit(c,"enter")),onDisplayResults:s.handleDisplayResults,onResults:s.handleResults,onQuery:s.handleQuery,ref:"typea",filter:r.mobile},null,8,["value","label","empty-autosuggest","placeholder","onSelect","onPersist","onReset","onDisplayResults","onResults","onQuery","filter"]),d(h("input",{type:"hidden",name:"pattern","onUpdate:modelValue":t[1]||(t[1]=c=>l.filterInput=c),ref:"filterInput"},null,512),[[w,l.filterInput]]),R(u,{ref:"mobile",filter:r.mobile,value:r.pattern,label:r.strings["letters-count"],button:r.strings["remove-filter"],regex:r.regex,charmap:r.charmap,onChange:s.updateLetters},null,8,["filter","value","label","button","regex","charmap","onChange"]),r.mobile?(a(),o("button",{key:1,type:"submit",class:"button block my-3 md:my-0","aria-label":r.strings.search,innerHTML:r.strings.search,onClick:t[3]||(t[3]=c=>s.submit(c,"enter"))},null,8,oe)):(a(),o("button",{key:0,type:"submit",class:"button mt-3 block mx-auto","aria-label":r.strings.search,innerHTML:r.strings.search,onClick:t[2]||(t[2]=c=>s.submit(c,"enter"))},null,8,ae))],6)],46,ue)}const ge=p(ne,[["render",he]]);export{ge as C,C as c};