/*! YOOtheme Pro v5.0.24 | https://yootheme.com */

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