/*! YOOtheme Pro v4.5.5 | https://yootheme.com */

(function(d,s){"use strict";d.component("Search",{args:"target",props:{target:String,mode:Boolean,preventSubmit:Boolean},data:{target:null,mode:!1,preventSubmit:!1},computed:{target:({target:e})=>s.$(e),dropdown({mode:e}){const t=e?null:this.target.closest(".uk-drop");return this.$getComponent(t,"drop")||this.$getComponent(t,"dropdown")}},observe:[{target:e=>e.mode?e.$el.form.parentElement:e.target,observe:s.observeIntersection,handler(e){e.some(t=>t.isIntersecting)&&(this.updateForm(!0),this.$el.value&&!this._index&&this.update())}}],events:[{name:"submit",capture:!0,filter:e=>e.preventSubmit,delegate:()=>'form[role="search"]',el:e=>e.$el.form.parentElement,handler:e=>e.preventDefault()},{name:"input",handler(){this.show()}},{name:"input",el:e=>e.target,delegate:()=>'input[type="search"]',handler(e){e.target!==this.$el&&(this.$el.value=e.target.value,this.show())}},{name:"focus",filter:e=>!e.mode,handler(){this.showDropdown()}},{name:"keydown",filter:e=>!e.mode,handler(e){var t;e.key==="ArrowDown"&&(e.preventDefault(),this.dropdown.isToggled()||this.showDropdown(),s.isVisible(this.target)&&((t=s.$(s.selFocusable,this.target))==null||t.focus()))}}],methods:{async show(){await this.update(),this.showDropdown()},async update(){var h;(h=this._index)!=null||(this._index=0);const e=++this._index,t=await this.query();if(e!==this._index)return;const{activeElement:n}=this.$el.ownerDocument,o=s.$$('input[type="search"]',this.target),r=o.findIndex(l=>l===n);c(this.target,t);const a=s.$$('input[type="search"]',this.target);a[r]&&(a[r].replaceWith(o[r]),o[r].focus()),this.updateForm()},updateForm(e){if(!this.mode)return;const t=s.$$('input[type="search"]',this.target).find(s.isVisible);this.$el.form.hidden=!!t,s.toggleClass(this.$el.form,"uk-margin-remove-adjacent",!!t),t&&(t.autofocus=!0,e&&(t.focus(),t.setSelectionRange(t.value.length,t.value.length)))},async query(){const{form:e}=this.$el,t=new FormData(e),n=Object.entries(JSON.parse(e.dataset.liveSearch||"{}"));for(const[r,a]of[...n,["live-search",!0]])t.append(r,a);const o=await fetch(e.action,{method:"POST",body:t});if(o.ok)return await o.text()},showDropdown(){this.dropdown&&(Array.from(this.target.children).some(e=>s.css(e,"display")!=="none")?this.dropdown.show(this.$el.form.parentElement,!1):this.dropdown.hide(!1))}}});const i=new Set;function c(e,t){for(const n of s.$$("script"))i.add(n.src);e.innerHTML=t;for(const n of s.$$("script",e))i.has(n.src)||(n.remove(),e.append(p(n)))}function p(e){const t=document.createElement("script");t.text=e.innerHTML;for(const{name:n,value:o}of e.attributes)t.setAttribute(n,o);return t}})(UIkit,UIkit.util);
