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

(function(c,n){"use strict";c.component("Search",{args:"target",props:{target:String,mode:Boolean,preventSubmit:Boolean},data:{target:null,mode:!1,preventSubmit:!1},computed:{target:({target:e})=>n.$(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:n.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(),n.isVisible(this.target)&&((t=n.$(n.selFocusable,this.target))==null||t.focus()))}}],methods:{async show(){await this.update(),this.showDropdown()},async update(){var d;(d=this._index)!=null||(this._index=0);const e=++this._index,t=await this.query();if(e!==this._index)return;const{activeElement:s}=this.$el.ownerDocument,r=n.$$('input[type="search"]',this.target),o=r.findIndex(f=>f===s);l(this.target,t);const a=n.$$('input[type="search"]',this.target);a[o]&&(a[o].replaceWith(r[o]),r[o].focus()),this.updateForm()},updateForm(e){if(!this.mode)return;const t=n.$$('input[type="search"]',this.target).find(n.isVisible);this.$el.form.hidden=!!t,n.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),s=Object.entries(JSON.parse(e.dataset.liveSearch||"{}"));for(const[o,a]of[...s,["live-search",!0]])t.append(o,a);const r=await fetch(e.action,{method:"POST",body:t});if(r.ok)return await r.text()},showDropdown(){this.dropdown&&(i(this.target)?this.dropdown.show(this.$el.form.parentElement,!1):this.dropdown.hide(!1))}}});function i(e){return Array.from(e.children).some(t=>n.css(t,"display")!=="none"&&(i(t)||!t.children.length))}const h=new Set;function l(e,t){for(const s of n.$$("script"))h.add(s.src);e.innerHTML=t;for(const s of n.$$("script",e))h.has(s.src)||(s.remove(),e.append(p(s)))}function p(e){const t=document.createElement("script");t.text=e.innerHTML;for(const{name:s,value:r}of e.attributes)t.setAttribute(s,r);return t}})(UIkit,UIkit.util);
