/*!
* @name autocomplete
* @version 3.3.1
* @author Grzegorz Tomicki
* @link https://github.com/tomickigrzegorz/autocomplete
* @license MIT
*/
var Autocomplete=function(){"use strict";var e=function(e,i){Object.entries(i).forEach((function(i){var t=i[0],n=i[1];"addClass"===t||"removeClass"===t?o(e,"addClass"===t?"add":"remove",n):e.setAttribute(t,n)}))},i=function(e){return(e.firstElementChild||e).textContent.trim()},t=function(e,i){e.scrollTop=e.offsetTop-i.offsetHeight},n=function(e,i){e&&(o(e,"remove","hidden"),d(e,"click",i))},o=function(e,i,t){return e.classList[i](t)},a=function(i,t){e(i,{"aria-activedescendant":t||""})},s=function(e,i,t,n){var o=n.previousSibling,a=o?o.offsetHeight:0;if("0"===e.getAttribute("aria-posinset")&&(n.scrollTop=e.offsetTop-function(e,i){var t=document.querySelectorAll("#"+e+" > li:not(."+i+")");return Array.from(t).reduce((function(e,i){return e+i.offsetHeight}),0)}(i,t)),e.offsetTop-a<n.scrollTop)n.scrollTop=e.offsetTop-a;else{var s=e.offsetTop+e.offsetHeight-a;s>n.scrollTop+n.offsetHeight&&(n.scrollTop=s-n.offsetHeight)}},c=function(e){return document.createElement(e)},d=function(e,i,t){e.addEventListener(i,t)},r=function(e,i,t){e.removeEventListener(i,t)},u=function(e,i){return void 0===i&&(i=!1),{"aria-owns":e,"aria-expanded":"false","aria-autocomplete":i?"both":"list","aria-haspopup":"listbox",role:"combobox",removeClass:"auto-expanded"}},l=Object.freeze({ESC:27,ENTER:13,UP:38,DOWN:40,TAB:9});return function(h,v){var f,m,p=this,k=v.delay,x=void 0===k?500:k,b=v.clearButton,w=void 0===b||b,y=v.clearButtonOnInitial,C=void 0!==y&&y,j=v.howManyCharacters,O=void 0===j?1:j,g=v.selectFirst,A=void 0!==g&&g,E=v.insertToInput,V=void 0!==E&&E,T=v.showValuesOnClick,z=void 0!==T&&T,N=v.inline,$=void 0!==N&&N,S=v.cache,B=void 0!==S&&S,J=v.disableCloseOnSelect,P=void 0!==J&&J,q=v.preventScrollUp,D=void 0!==q&&q,G=v.removeResultsWhenInputIsEmpty,I=void 0!==G&&G,R=v.dropdownParent,U=v.dropdownAttrs,W=void 0===U?{}:U,F=v.regex,H=void 0===F?{expression:/[|\\{}()[\]^$+*?]/g,replacement:"\\$&"}:F,K=v.classGroup,L=v.classPreventClosing,M=v.classPrefix,Q=v.ariaLabelClear,X=v.onSearch,Y=v.onResults,Z=void 0===Y?function(){}:Y,_=v.onSubmit,ee=void 0===_?function(){}:_,ie=v.onOpened,te=void 0===ie?function(){}:ie,ne=v.onReset,oe=void 0===ne?function(){}:ne,ae=v.onRender,se=void 0===ae?function(){}:ae,ce=v.onClose,de=void 0===ce?function(){}:ce,re=v.noResults,ue=void 0===re?function(){}:re,le=v.onLoading,he=void 0===le?function(){}:le,ve=v.onSelectedItem,fe=void 0===ve?function(){}:ve;if(this.i=function(){p.t();var i,t,o,a,s,c=u(p.o,p.u);if(e(p.l,c),i=p.l,t=p.h,o=p.o,a=p.v,s=p.m,e(t,{id:o,role:"listbox"}),e(a,{addClass:s+"-results-wrapper"}),a.insertAdjacentElement("beforeend",t),i.parentNode.insertBefore(a,i.nextSibling),p.p){var r;if(p.p.appendChild(p.v),p.k.class)(r=p.v.classList).add.apply(r,p.k.class.trim().split(/\s+/));p.k.style&&p.v.setAttribute("style",p.k.style)}try{p.h.id=p.o,p.l.setAttribute("aria-controls",p.o)}catch(e){}if(d(p.l,"input",p.C),p.j&&d(p.l,"click",p.C),p.O){var l={root:p.l,type:"load"};d(p.l,"load",p.C(l))}p.A({element:p.l,results:p.h}),p.V&&n(p.T,p.reset)},this.N=function(e,i){p.$&&("update"===e?p.l.setAttribute(p.S,null==i?void 0:i.value):"remove"===e?p.l.removeAttribute(p.S):p.l.value=p.l.getAttribute(p.S))},this.C=function(e){var i,t=e.target,n=e.type;if("true"!==p.l.getAttribute("aria-expanded")||"click"!==n){var a=null==(i=t=p.O?p.l:t)?void 0:i.value.replace(p.B.expression,p.B.replacement);p.N("update",t);var s=p.j||p.O&&"load"===n?0:p.J;clearTimeout(p.P),p.P=setTimeout((function(){var e;if(p.q&&0===(null==(e=t)?void 0:e.value.length))return p.h.textContent="",p.D(),void(p.G&&o(p.T,"add","hidden"));p.I(null==a?void 0:a.trim())}),s)}},this.R=function(){var e,i=p.l.getBoundingClientRect();p.v.style.position="fixed",p.v.style.left=i.left+"px",p.v.style.top=i.bottom+"px",p.v.style.width=i.width+"px",null!=(e=p.k.style)&&e.includes("z-index")||(p.v.style.zIndex="9999")},this.U=function(){p.R(),window.addEventListener("scroll",p.R,!0),window.addEventListener("resize",p.R)},this.W=function(){window.removeEventListener("scroll",p.R,!0),window.removeEventListener("resize",p.R)},this.D=function(){var i;o(p.v,"remove",p.F),p.p&&p.W();var t=u(p.o,p.u),n=p.H?t:Object.assign({},t,{"aria-activedescendant":""});e(p.l,n),p.H||(p.K(p.h.querySelector("."+p.L)),p.M=p.X?0:-1),(0===(null==(i=p.Y)?void 0:i.length)&&!p.u||p.j)&&(p.h.textContent=""),p.Z()},this.I=function(e){p._=e,n(p.T,p.reset),e&&0!==(null==e?void 0:e.length)||!p.G||p.V||o(p.T,"add","hidden"),p.ee>(null==e?void 0:e.length)&&!p.j&&!p.O||(p.ie(!0),p.te({currentValue:e,element:p.l}).then((function(i){var t=p.l.value.length,n=i.length;if(p.Y=Array.isArray(i)?i:JSON.parse(JSON.stringify(i)),p.ie(),p.ne(),0===n&&0===t&&o(p.T,"add","hidden"),0===n&&t){o(p.l,"remove","auto-expanded"),p.D();var a=p.oe({element:p.l,currentValue:e});a&&p.ae(a),p.se()}else(n>0||function(e){return e&&"object"==typeof e&&e.constructor===Object}(i))&&(p.M=p.X?0:-1,p.ae(),p.se())})).catch((function(){p.ie(),p.D()})))},this.ie=function(i){if(p.l.parentNode.classList[i?"add":"remove"](p.ce),i){var t=p.de({element:p.l,currentValue:p._});t&&(p.h.textContent="",p.h.insertAdjacentHTML("afterbegin",t),e(p.l,{"aria-expanded":"true",addClass:p.m+"-expanded"}),o(p.v,"add",p.F),p.p&&p.U())}},this.ne=function(){return o(p.l,"remove",p.re)},this.se=function(){r(p.l,"keydown",p.ue),r(p.l,"click",p.le),r(document,"click",p.he),["mousemove","click"].forEach((function(e){r(p.h,e,p.ve)})),d(p.l,"keydown",p.ue),d(p.l,"click",p.le),p.O||d(document,"click",p.he),["mousemove","click"].forEach((function(e){d(p.h,e,p.ve)}))},this.ae=function(i){e(p.l,{"aria-expanded":"true",addClass:p.m+"-expanded"}),p.h.textContent="";var n=null!=i?i:p.fe({currentValue:p._,matches:p.Y,classGroup:p.me});p.h.insertAdjacentHTML("afterbegin",n),o(p.v,"add",p.F),p.p&&p.U();var a,s=p.me?":not(."+p.me+")":"";p.pe=document.querySelectorAll("#"+p.o+" > li"+s),(a=p.pe).forEach((function(i,t){e(i,{role:"option",tabindex:"-1","aria-selected":"false","aria-setsize":a.length,"aria-posinset":t+1})})),p.ke({type:"results",element:p.l,results:p.h}),p.xe(),t(p.h,p.v)},this.he=function(e){var i=e.target;if(i instanceof Element){var t=null;(i.closest("ul")&&p.be||i.closest("."+p.we))&&(t=!0),i.id===p.ye||t||p.D()}},this.xe=function(){if(p.K(p.h.querySelector("."+p.L)),p.X){var i=p.h.firstElementChild,t=p.me&&p.Y.length>0&&p.X?i.nextElementSibling:i;p.Ce({index:p.M,element:p.l,object:p.Y[p.M],currentValue:p.l.value}),e(t,{id:p.je+"-0",addClass:p.L,"aria-selected":"true"}),a(p.l,p.je+"-0")}},this.le=function(){if(p.h.textContent.length>0&&!o(p.v,"contains",p.F)){if(e(p.l,{"aria-expanded":"true",addClass:p.m+"-expanded"}),o(p.v,"add",p.F),p.p&&p.U(),p.H||(t(p.h,p.v),p.xe()),p.ke({type:"showItems",element:p.l,results:p.h}),!p.$)return;p.N("update",p.l)}else p.h.textContent.length>0&&o(p.v,"contains",p.F)&&!p.H&&(p.xe(),p.M=p.X?0:-1)},this.ve=function(e){e.preventDefault();var t=e.target,n=e.type,a=t.closest("li"),s=null==a?void 0:a.hasAttribute("role"),c=p.L,d=p.h.querySelector("."+c);a&&s&&!t.closest("."+p.we)&&("click"===n&&p.Oe(a),"mousemove"!==n||o(a,"contains",c)||(p.K(d),p.ge(a),p.M=p.Ae(a),p.u&&(p.l.value=i(a)),p.Ce({index:p.M,element:p.l,object:p.Y[p.M]}),p.l.value.length>0&&p.G&&o(p.T,"remove","hidden")))},this.Oe=function(e){e&&0!==p.Y.length?(p.G&&o(p.T,"remove","hidden"),p.l.value=i(e),p.Ee({index:p.M,element:p.l,object:p.Y[p.M],results:p.h}),p.be||(p.H||p.K(e),p.D()),p.N("remove")):!p.be&&p.D()},this.Ae=function(e){return Array.prototype.indexOf.call(p.pe,e)},this.ue=function(e){var t=e.keyCode,n=o(p.v,"contains",p.F),s=p.Y.length+1;switch(p.Ve=p.h.querySelector("."+p.L),t){case l.UP:case l.DOWN:if(e.preventDefault(),s<=1&&p.X||!n)return;if(t===l.UP?(p.M<0&&(p.M=s-1),p.M-=1):(p.M+=1,p.M>=s&&(p.M=0)),p.K(p.Ve),p.M>=0&&p.M<s-1){var c=p.pe[p.M];p.u&&n&&(p.l.value=i(c),p.G&&o(p.T,"remove","hidden")),p.Ce({index:p.M,element:p.l,object:p.Y[p.M]}),p.ge(c)}else p.N(),a(p.l),p.Ce({index:null,element:p.l,object:null});break;case l.ENTER:e.preventDefault(),p.Oe(p.Ve);break;case l.TAB:case l.ESC:e.stopPropagation(),p.O||p.D()}},this.ge=function(i){var t=p.je+"-"+p.Ae(i);e(i,{id:t,"aria-selected":"true",addClass:p.L}),a(p.l,t),s(i,p.o,p.me,p.h)},this.K=function(i){i&&e(i,{id:"",removeClass:p.L,"aria-selected":"false"})},this.t=function(){p.G&&(e(p.T,{type:"button",class:p.m+"-clear hidden",title:p.Te,"aria-label":p.Te}),p.l.insertAdjacentElement("afterend",p.T))},this.rerender=function(e){var i=null!=e&&e.trim()?e.trim():p.l.value;null!=e&&e.trim()&&(p.l.value=e.trim(),p.N("update",p.l));var t=i.replace(p.B.expression,p.B.replacement);p.I(t.trim())},this.disable=function(i){void 0===i&&(i=!1),p.l.setAttribute("data-auto-disabled","true"),p.G&&o(p.T,"add","hidden"),i&&(p.l.value="",p.l.focus()),p.h.textContent="",o(p.v,"remove",p.F),e(p.l,{"aria-expanded":"false",removeClass:p.m+"-expanded","aria-activedescendant":""}),r(p.l,"input",p.C),r(p.l,"keydown",p.ue),r(p.l,"click",p.le),p.j&&r(p.l,"click",p.C),p.O||r(document,"click",p.he),["mousemove","click"].forEach((function(e){r(p.h,e,p.ve)})),p.ie(!1),p.ne(),p.Z(),setTimeout((function(){p.l.setAttribute("aria-autocomplete","none")}),0)},this.enable=function(){p.l.removeAttribute("data-auto-disabled");var i=u(p.o,p.u);e(p.l,i),d(p.l,"input",p.C),d(p.l,"keydown",p.ue),d(p.l,"click",p.le),p.j&&d(p.l,"click",p.C),p.O||d(document,"click",p.he),["mousemove","click"].forEach((function(e){d(p.h,e,p.ve)})),p.p&&!p.v.isConnected&&p.p.appendChild(p.v),p.G&&p.l.value.length>0&&o(p.T,"remove","hidden"),p.ke({type:"enable",element:p.l,results:p.h})},this.destroy=function(){p.p&&p.W(),p.p&&p.v.isConnected&&p.v.remove(),p.G&&o(p.T,"add","hidden"),p.l.value="",p.l.focus(),p.h.textContent="",p.O||p.D(),p.O&&p.Z(),p.ne(),p.ie(),r(p.l,"input",p.C),r(p.l,"keydown",p.ue),r(p.l,"click",p.le),p.j&&r(p.l,"click",p.C),r(document,"click",p.he),["mousemove","click"].forEach((function(e){r(p.h,e,p.ve)})),p.ze(p.l)},this.reset=function(){p.l.value="",p.l.focus(),p.h.textContent="",p.G&&o(p.T,"add","hidden"),p.D(),p.ne(),p.ze(p.l)},this.ye=h,this.l=document.getElementById(h),!this.l)throw new Error('Autocomplete: Element with id "'+h+'" not found');this.te=(m=X,Boolean(m&&"function"==typeof m.then)?X:function(e){var i=e.currentValue,t=e.element;return Promise.resolve(X({currentValue:i,element:t}))}),this.fe=Z,this.A=se,this.Ee=ee,this.Ce=fe,this.ke=te,this.ze=oe,this.oe=ue,this.de=he,this.Z=de,this.J=x,this.ee=O,this.G=w,this.V=C,this.X=A,this.u=V,this.j=z,this.O=$,this.me=K,this.we=L,this.Te=Q||"clear the search query",this.m=M?M+"-auto":"auto",this.be=P,this.H=D,this.q=I,this.p="string"==typeof R?document.querySelector(R):R||null,this.k=W,this.$=B,this.P=null,this.o=this.m+"-"+this.ye+"-results",this.S="data-cache-auto-"+this.ye,this.ce=this.m+"-is-loading",this.F=this.m+"-is-active",this.L=this.m+"-selected",this.je=this.m+"-selected-option",this.re=this.m+"-error",this.v=c("div"),this.h=c("ul"),this.T=c("button");var me={expression:/[|\\{}()[\]^$+*?]/g,replacement:"\\$&"};this.B={expression:H.expression||me.expression,replacement:null!=(f=H.replacement)?f:me.replacement},this.i()}}();
