import{c as G}from"./AppLayout-5c633aaa.js";import{s as ue}from"./searchFromField-7fd882c6.js";import{q as M,u as R,v as g,J as W,K as ce,X as de,F as fe,E as he,x as pe,D as E,z as ve,y as H,A as me,_ as Q}from"./vue-0d7ee8e8.js";import{_ as N}from"./_plugin-vue_export-helper-b15b4a05.js";import{$ as l}from"./jquery-32293273.js";const ye="/build/assets/fullview-24f85572.svg",ge="/build/assets/reduce-ad4b9a1e.svg",we="/build/assets/references-2daed1ea.svg",xe={mixins:[ue],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:G}},computed:{formatted(){return this.items.map(a=>({url:a.url,word:a.word}))}},methods:{fetchItems(a){this.selected=null,this.query!==""?(this.$emit("select",this.query),this.query.length>1&&axios.post(this.route("visual-dictionary.matches"),{_token:document.querySelector('meta[name="csrf-token"]').getAttribute("content"),lookup:this.query}).then(({data:f})=>{this.items=f,this.items.length?(this.selected=this.items[0].url,this.emptyResults=!1):this.emptyResults=!0}).catch(function(f){console.log(f)})):(this.items=[],this.$emit("select",""))},select(a){this.query=this.items[a].url,this.$emit("select",this.items[a].url)},persist(a){this.query=this.items[a].url,this.$emit("persist",this.items[a].url)},reset(){this.query="",this.items=[],this.selected=null,this.$emit("reset")},itemSelected(a){return this.selected===a?"selected":""},moveSelection(a){a.key==="ArrowDown"?this.selectionDown():a.key==="ArrowUp"?this.selectionUp():a.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")}}},be={class:"w-full"},_e={class:"typeahead"},Se=["placeholder"],ke=["src"],qe={key:0,class:"typeahead-results"},Ie=["onMousedown"],Me=["innerHTML"];function Re(a,f,x,b,h,c){return M(),R("div",be,[g("div",_e,[W(g("input",{"onUpdate:modelValue":f[0]||(f[0]=m=>h.query=m),type:"text",class:"search-box-input pe-8",placeholder:x.placeholder,autocomplete:"off",ref:"input",onInput:f[1]||(f[1]=(...m)=>c.fetchItems&&c.fetchItems(...m)),onKeydown:f[2]||(f[2]=(...m)=>c.moveSelection&&c.moveSelection(...m)),onFocus:f[3]||(f[3]=(...m)=>c.focusHandler&&c.focusHandler(...m)),onBlur:f[4]||(f[4]=m=>h.displayResults=!1)},null,40,Se),[[ce,h.query]]),g("button",{type:"button",class:"typeahead-clear","aria-label":"reset",onClick:f[5]||(f[5]=(...m)=>c.reset&&c.reset(...m))},[g("img",{src:h.clearIcon,width:"13.5",height:"18.4",alt:"clear"},null,8,ke)]),h.query.length>1&&(c.formatted.length>0||h.emptyResults&&h.query.length>3)?W((M(),R("ul",qe,[c.formatted.length>0?(M(!0),R(fe,{key:0},he(c.formatted,(m,p)=>(M(),R("li",{key:p,class:"link",onMousedown:o=>c.persist(p)},pe(m.word),41,Ie))),128)):E("",!0),h.emptyResults&&h.query.length>3?(M(),R("li",{key:1,innerHTML:x.emptyAutosuggest},null,8,Me)):E("",!0)],512)),[[de,h.displayResults]]):E("",!0)])])}const Te=N(xe,[["render",Re]]),De={props:{isPart:{type:Boolean,default:!1},visualDictionaryFormValues:{type:Object,default(){return{}}},strings:Object},components:{SearchFormSearchBox:Te},data(){return{clearIcon:G,lookup:this.visualDictionaryFormValues.hasOwnProperty("value")?this.visualDictionaryFormValues.value:"",searchResults:[],showResults:!1,vd:null,emptyResults:!1}},methods:{persistSelection(a){this.setRoute(a),this.submit()},setRoute(a){this.currentRoute=a},submit(){var a=route().params.fullview==="true";this.currentRoute!=null&&this.currentRoute!==""?document.location.href=this.route("visual-dictionary")+`?fullview=${a}&lookup=${this.currentRoute}`:window.location.reload()}}},Fe=["innerHTML"],Le={class:"flex justify-center pt-3"},Ve=["aria-label","innerHTML"];function Ae(a,f,x,b,h,c){const m=ve("SearchFormSearchBox");return M(),R("div",null,[g("form",{class:H("form visual-dictionary-search-form amp "+(x.isPart?"transparent":"")),onSubmit:f[0]||(f[0]=Q((...p)=>c.submit&&c.submit(...p),["prevent"])),style:{position:"relative"}},[g("label",{class:H(["form-label",x.isPart?"text-left":"text-center"]),innerHTML:x.strings.label},null,10,Fe),g("div",null,[me(m,{name:"value",placeholder:x.strings.placeholder,value:h.lookup,"empty-autosuggest":x.strings["no-autosuggest-results"],onSelect:c.setRoute,onPersist:c.persistSelection,onSubmit:c.submit},null,8,["placeholder","value","empty-autosuggest","onSelect","onPersist","onSubmit"]),g("div",Le,[g("button",{type:"submit",class:"button search","aria-label":x.strings.search,innerHTML:x.strings.search},null,8,Ve)])])],34)])}const Je=N(De,[["render",Ae]]),Be={props:{value:String,snappywords:String},data(){return{fullviewImage:ye,reduceImage:ge,referencesImage:we}},methods:{switchSize(){var a=route().params.fullview!=="true";document.location.href=`/visual-dictionary?fullview=${a}&lookup=${this.value}`}},mounted(){let a=this.$props.snappywords;window.lexurl=this.route("visual-dictionary.search"),window.assetsurl=this.route("visual-dictionary.config"),l(document).ready(function(){var f=window.lexurl+"?find=",x=window.assetsurl,b=l(".snappywords").hasClass("min-h-screen")?1.5:1;l(".snappywords").width()/2,l(".snappywords").height()/2;var h=l(".snappywords"),c=h.find(".origin");l("#snappywords_enter");var m=0,p=null,o=new Array,_=new Array,A=0,T=null,D=null;function Z(e){for(var t=0;t<p.entity_category.length;t++)if(p.entity_category[t].type==e)return p.base_url+p.entity_category[t].file;return null}function P(e){for(var t=null,i=null,s=0;s<p.association_type.length;s++)if(p.association_type[s].type==e){var r=p.association_type[s];return r.reciprocal&&(t=r.reciprocal),r.file&&(i=p.base_url+r.file),{reciprocal:t,file:i}}return null}function $(e,t,i,s,r){var n=l("<img/>").attr("src",e);return n.addClass("link").appendTo(c),z(n,t,i,s,r),n}function z(e,t,i,s,r){var n=(i-.5*t)*b,d=(s-5)*b,u=180*r/Math.PI;l(e).css({width:t*b+"px",height:"10px",left:n+"px",top:d+"px",transform:"rotate("+u+"deg)"})}function ee(e,t,i){var s=P(e);if(s.reciprocal){s=P(s.reciprocal);var r=t;t=i,i=r}var n=s.file,d=F(t),u=F(i),v=o[d].position,S=o[u].position,y=.5*(v.x+S.x),I=.5*(v.y+S.y),q=S.x-v.x,w=S.y-v.y,oe=Math.atan2(w,q),le=Math.sqrt(w*w+q*q)-32,ae=$(n,le,y,I,oe);_.push({n1:o[d],n2:o[u],domLink:ae})}function te(e,t){var i=e.category,s=null,r=null;if(i=="word"){s=l('<div class="node word"></div>').appendTo(c),r=l('<div class="words"></div>').appendTo(s);var n=e.label.replace(/ /g," ").replace(/-/g,"‑");r.append("<div>"+n+"</div>");var d=.5*(s.height()-r.height()),u=.5*(s.width()-r.width());r.css({top:d+"px",left:u+"px"})}else if(s=l('<div class="node"></div>').css({backgroundImage:"url("+Z(i)+")"}).appendTo(c),e.label){var v=0;for(r=l('<div class="words"></div>').appendTo(s),v=0;v<e.label.length&&!(v>=3);v++){var n=e.label[v].replace(/ /g," ").replace(/-/g,"‑").replace(/\(p\)/,"");r.append("<div>"+n+"</div>")}var d=.5*(s.height()-r.height()),u=.5*(s.width()-r.width());r.css({top:d+"px",left:u+"px"})}return O(s,t),s}function O(e,t){var i=e.width(),s=e.height(),r=t.x*b-.5*i,n=t.y*b-.5*s;e.css({left:r+"px",top:n+"px"})}function F(e){for(var t=0;t<o.length;t++)if(o[t].identity==e)return t;return-1}function se(e,t){var i=-1;t&&(i=F(t));var s=e.entity,r=F(s.identity);if(!(r>=0)){var n=null;if(i>=0){n=o[i].position;var d=2*Math.PI*Math.random(),u=n.x+30*Math.cos(d),v=n.y+30*Math.sin(d);n={x:u,y:v}}else n={x:0,y:0};var S=te(s,n);s.position=n,s.force={x:0,y:0},s.domNode=S,o.push(s);for(var y=0;y<s.association.length;y++)if(18>A){A++;var I=s.association[y].link,q=s.identity;B(I,q)}}if(i>=0){var w=o[i];for(y=0;y<w.association.length;y++)if(w.association[y].link==s.identity){ee(w.association[y].type,w.identity,s.identity);break}}}function B(e,t){l(document).delay(100),l(document).queue(function(){l.ajax({dataType:"json",url:f+e,success:function(i){se(i,t)}}),l(this).dequeue()})}function L(e){var t,i,s={x:0,y:0};if(e.touches){var r=e.touches[0];t=r.pageX,i=r.pageY}else t=e.pageX,i=e.pageY;var n=c.offset();return s.x=t-n.left,s.y=i-n.top,s}function ie(e,t){var i=e.x-t.x*b,s=e.y-t.y*b;return i*i+s*s}function C(e){for(var t=null,i=1024,s=0;s<o.length;s++){var r=o[s].position,n=ie(e,r);i>n&&(t=o[s],i=n)}return t}function re(e){var t=L(e),i=C(t);i?(e.preventDefault(),j(i)):T||V()}function U(e){var t=new Date,i=t.getTime();if(200>i-m){var d=L(e),u=C(d);console.debug(u);for(var s=0;s<u.association.length;s++){A++;var r=u.association[s].link,n=u.identity;B(r,n)}}m=i;var d=L(e),u=C(d);u&&(e.preventDefault(),ne(u))}function ne(e){V(),T=e.domNode,T.addClass("grabbed"),D=null,j(e)}function X(e){if(T){e.preventDefault();var t=L(e);D={x:t.x/b,y:t.y/b},J(h.find(".definition"),t)}}function V(){h.find(".grabbed").removeClass("grabbed"),h.find(".definition").remove(),T=null}function j(e){h.find(".definition").remove();var t=400,i=h.width()-4;if(i>t&&(i=t),e.category!="word"){var s=l('<div class="definition"></div>'),r=e.label.join(", ");s.html('<div class="liner"><div class="label">'+r+'</div><div class="defn">'+e.definition+"</div></div>"),s.css({width:i+"px"}),s.appendTo(c),J(s,e.position)}}function J(e,t){var i=-l(k).find(".origin").position().left,s=+l(k).width()+i;s-=e.width()+4;{var r=l(window).scrollTop()+l("header").height(),n=-l(k).find(".origin").position().top;+l(k).height()+n}n+=r;var d=t.x-.5*e.width(),u=t.y-40-e.height();n>u&&(u=t.y+40),i>d&&(d=i),d>s&&(d=s),e.css({left:d+"px",top:u+"px",opacity:1})}function K(e,t,i,s){var r=88,n=20,d=r*r,u=t.x-e.x,v=t.y-e.y,S=u*u+v*v,y=Math.sqrt(S),I=0;s&&(I+=S/d),i&&(I-=d/S);var q=I*u/y,w=I*v/y;return-n>q&&(q=-n),q>+n&&(q=+n),-n>w&&(w=-n),w>+n&&(w=+n),{x:q,y:w}}function Y(){for(var e=1;e<o.length;e++)for(var t=0;t<e;t++){var i=o[e].position,s=o[t].position,r=K(i,s,1,0);o[e].force.x+=r.x,o[e].force.y+=r.y,o[t].force.x-=r.x,o[t].force.y-=r.y}for(var e=0;e<_.length;e++){var i=_[e].n1.position,s=_[e].n2.position,r=K(i,s,0,1);_[e].n1.force.x+=r.x,_[e].n1.force.y+=r.y,_[e].n2.force.x-=r.x,_[e].n2.force.y-=r.y}for(var e=0;e<o.length;e++)o[e].domNode!=T?(o[e].position.x+=o[e].force.x,o[e].position.y+=o[e].force.y):D&&(o[e].position=D),O(o[e].domNode,o[e].position),o[e].force.x*=.8,o[e].force.y*=.8;for(var e=0;e<_.length;e++){var i=_[e].n1.position,s=_[e].n2.position,n=.5*(i.x+s.x),d=.5*(i.y+s.y),u=s.x-i.x,v=s.y-i.y,S=Math.atan2(v,u),y=Math.sqrt(v*v+u*u)-32;z(_[e].domLink,y,n,d,S)}setTimeout(function(){Y()},40)}var k=h;l(k).on({mousemove:function(e){re(e.originalEvent)}}),l(k).on({mousedown:function(e){U(e.originalEvent)}}),l(k).on({touchstart:function(e){U(e.originalEvent)}}),l(k).on({mousemove:function(e){X(e.originalEvent)}}),l(k).on({touchmove:function(e){X(e.originalEvent)}}),l(k).on({mouseup:function(){V()}}),l(k).on({mouseleave:function(){V()}}),l.getJSON(x).done(function(e){p=e.assets;var t;for(t=0;t<p.association_type.length;t++)if(p.association_type[t].file){var i=new Image;i.src=p.base_url+p.association_type[t].file}for(t=0;t<p.entity_category.length;t++){var i=new Image;i.src=p.base_url+p.entity_category[t].file}window.snappywords=!0,window.snappywords&&(B(a,null),Y())})})}},Ce={class:"absolute top-0 right-0 mt-1 mr-4",type:"submit"},Ee=["src"],He=g("div",{class:"origin"},null,-1),Ne=["src"];function Pe(a,f,x,b,h,c){return M(),R("div",null,[g("div",{class:H(`snappywords rounded-lg mb-2 ${a.route().params.fullview==="true"?"min-h-screen":""}`)},[g("form",{onSubmit:f[0]||(f[0]=Q((...m)=>c.switchSize&&c.switchSize(...m),["prevent"]))},[g("button",Ce,[g("img",{width:"36",height:"36",src:a.route().params.fullview==="true"?h.reduceImage:h.fullviewImage,alt:"full view"},null,8,Ee)])],32),He],2),g("img",{class:"w-full",width:"895",height:"218",src:h.referencesImage,alt:"references"},null,8,Ne)])}const Ke=N(Be,[["render",Pe]]);export{Ke as V,Je as a};