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