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

(function(d,n){"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})=>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 c;(c=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 h=n.$$('input[type="search"]',this.target);h[o]&&(h[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.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[r,o]of[...s,["live-search",!0]])t.append(r,o);try{const r=await fetch(e.action,{method:"POST",body:t});if(r.ok)return await r.text()}catch{}},showDropdown(){this.dropdown&&(a(this.target)?this.dropdown.show(this.$el.form.parentElement,!1):this.dropdown.hide(!1))}}});function a(e){return Array.from(e.children).some(t=>n.css(t,"display")!=="none"&&(a(t)||!t.children.length))}const i=new Set;function l(e,t){for(const s of n.$$("script"))i.add(s.src);e.innerHTML=t;for(const s of n.$$("script",e))i.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);
