let t,e;t=this,e=function(){function t(t,e){const n=Object.keys(t);if(Object.getOwnPropertySymbols){let r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(e=>Object.getOwnPropertyDescriptor(t,e).enumerable)),n.push.apply(n,r)}return n}function e(e){for(let o=1;o{r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach(t=>{Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){if(t){if("string"==typeof t)return s(t,e);let n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n{e.forEach(e=>{t.input&&(n.disconnect(),t.init())})}).observe(document,{childList:!0,subtree:!0})},l=function(t){return"string"==typeof t?document.querySelector(t):t},a=function(t,e){const n="string"==typeof t?document.createElement(t):t;for(const t in e){const r=e[t];if("inside"===t)r.append(n);else if("dest"===t)l(r[0]).insertAdjacentElement(r[1],n);else if("around"===t){const t=l(r);t.parentNode.insertBefore(n,t),n.append(t),null!=t.getAttribute("autofocus")&&t.focus()}else t in n?n[t]=r:n.setAttribute(t,r)}return n},f=function(t,e){return t=t.toString().toLowerCase(),e?t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC"):t},p=function(t,n){return a("mark",e({innerHTML:t},"string"==typeof n&&{classes:n})).outerHTML},d=function(t,e){e.input.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:e.feedback,cancelable:!0}))},h=function(t,e,n){const r=n||{},o=r.mode,i=r.diacritics,s=r.highlight,c=f(e,i);if(e=e.toString(),t=f(t,i),"loose"===o){const n=(t=t.replace(/ /g,"")).length;let r=0;const o=Array.from(e).map((e,o)=>(r{let r,o,i;return r=t.input,o=t.query,(i=t.data).cache&&i.store?e():(o=o?o(r.value):r.value,new Promise((t,e)=>"function"==typeof i.src?i.src(o).then(t,e):t(i.src)).then(r=>{try{return t.feedback=i.store=r,d("response",t),e()}catch(t){return n(t)}},n))})},y=function(t,e){const n=e.data,r=e.searchEngine,o=e.diacritics,s=e.resultsList,c=e.resultItem;let u=[];if(!n.store)return void console.log("e",e);n.store.forEach((e,s)=>{const l=function(n){const i=n?e[n]:e,s="function"==typeof r?r(t,i):h(t,i,{mode:r,diacritics:o,highlight:c.highlight});if(s){const t={match:s,value:e};n&&(t.key=n),u.push(t)}};if(n.keys){let t;const e=function(t,e){let n,r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))){r&&(t=r);let e=0;const n=function(){};return{s:n,n:()=>e>=t.length?{done:!0}:{done:!1,value:t[e++]},e(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}let o=!0,s=!1;return{s(){r=r.call(t)},n(){const t=r.next();return o=t.done,t},e(t){s=!0,n=t},f(){try{o||null==r.return||r.return()}finally{if(s)throw n}}}}(n.keys);try{for(e.s();!(t=e.n()).done;)l(t.value)}catch(t){e.e(t)}finally{e.f()}}else l()}),n.filter&&(u=n.filter(u));const l=u.slice(0,s.maxResults);e.feedback={query:t,matches:u,results:l},d("results",e)},b="aria-expanded",g="aria-activedescendant",v="aria-selected",w=function(t,n){t.feedback.selection=e({index:n},t.feedback.results[n])},O=function(t){t.isOpen||((t.wrapper||t.input).setAttribute(b,!0),t.list.removeAttribute("hidden"),t.isOpen=!0,d("open",t))},A=function(t){t.isOpen&&((t.wrapper||t.input).setAttribute(b,!1),t.input.setAttribute(g,""),t.list.setAttribute("hidden",""),t.isOpen=!1,d("close",t))},S=function(t,e){const n=e.list.getElementsByTagName(e.resultItem.tag);if(e.isOpen&&n.length){let r,i;const s=e.cursor;t>=n.length&&(t=0),t<0&&(t=n.length-1),e.cursor=t,s>-1&&(n[s].removeAttribute(v),c&&(i=n[s].classList).remove.apply(i,o(c))),n[t].setAttribute(v,!0),c&&(r=n[t].classList).add.apply(r,o(c)),e.input.setAttribute(g,n[e.cursor].id),e.list.scrollTop=n[t].offsetTop-e.list.clientHeight+n[t].clientHeight+5,e.feedback.cursor=e.cursor,w(e,t),d("navigate",e)}},L=function(t){const e=t.cursor+1;S(e,t)},j=function(t){const e=t.cursor-1;S(e,t)},k=function(t,e,n){(n=n>=0?n:t.cursor)<0||(t.feedback.event=e,w(t,n),d("selection",t),A(t))};function E(t){const n=this;return new Promise((r,o)=>{let i,s,c,u,l,f,p;return i=t.input,s=t.query,c=t.trigger,u=t.threshold,l=t.resultsList,f=(p=i)instanceof HTMLInputElement||p instanceof HTMLTextAreaElement?p.value:p.innerHTML,function(t,e,n){return c?c(t):t.length>=n}(f=s?s(f):f,0,u)?m(t).then(r=>{try{return y(f,t),l&&function(t){const n=t.resultsList,r=t.list,o=t.resultItem,i=t.feedback;i.query;const s=i.matches,c=i.results;if(t.cursor=-1,r.innerHTML="",s.length||n.noResults){const s=document.createDocumentFragment();c.forEach((t,n)=>{const r=a(o.tag,e({id:"".concat(o.id,"_").concat(n),role:"option",innerHTML:t.match,inside:s},o.class&&{class:o.class}));o.element&&o.element(r,t)}),r.append(s),n.element&&n.element(r,i),O(t)}else A(t)}(t),d.call(n)}catch(t){return o(t)}},o):(A(t),d.call(n));function d(){return r()}})}const T=function(t,e){for(const n in t)for(const r in t[n])e(r,n)},I=function(t){const n=t.events;t.trigger;const r=t.debounce,o=t.resultsList,i=function(t,e){let n;return function(){clearTimeout(n),n=setTimeout(()=>t(),e)}}(()=>E(t),r),s=t.events=e({input:e({},n&&n.input)},o&&{list:n?e({},n.list):{}}),u={input:{input(){i()},keydown(e){!function(t,e){const n=t.keyCode,r=e.resultItem.selected;switch(r&&(c=r.split(" ")),n){case 40:case 38:t.preventDefault(),40===n?L(e):j(e);break;case 13:t.preventDefault(),e.cursor>=0&&k(e,t);break;case 9:e.resultsList.tabSelect&&e.cursor>=0?(t.preventDefault(),k(e,t)):A(e);break;case 27:t.preventDefault(),e.input.value="",A(e)}}(e,t)},blur(){A(t)}},list:{mousedown(t){t.preventDefault()},click(e){!function(t,e){const n=e.resultItem.tag.toUpperCase(),r=Array.from(e.list.querySelectorAll(n)),o=t.target.closest(n);if(o&&o.nodeName===n){t.preventDefault();const n=r.indexOf(o);k(e,t,n)}}(e,t)}}};T(u,(t,e)=>{(o||"list"!==e)&&(s[e][t]||(s[e][t]=u[e][t]))}),T(s,(e,n)=>{t[n].addEventListener(e,s[n][e])})};function x(t){const n=this;return new Promise((r,o)=>{let i,s,c,u,l,f;if(i=t.name,s=t.input,c=t.placeHolder,u=t.resultsList,l=t.data,f={role:"combobox","aria-owns":u.id,"aria-haspopup":!0,"aria-expanded":!1},a(s,e(e({"aria-controls":u.id,"aria-autocomplete":"list",autocomplete:"off"},c&&{placeholder:c}),!t.wrapper&&e({},f))),t.wrapper&&(t.wrapper=a("div",e({around:s,class:`${i}_wrapper`},f))),u&&(t.list=a(u.tag,e({dest:["string"==typeof u.destination?document.querySelector(u.destination):u.destination(),u.position],id:u.id,role:"listbox",hidden:"hidden"},u.class&&{class:u.class}))),l.cache)return m(t).then(t=>{try{return p.call(n)}catch(t){return o(t)}},o);function p(){return I(t),d("init",t),r()}return p.call(n)})}return function t(e){this.options=e,this.id=t.instances=(t.instances||0)+1,this.name="autoComplete",this.wrapper=1,this.threshold=1,this.debounce=0,this.separator={destinations:null,etablissements:null},this.resultsList={position:"afterend",tag:"ul",maxResults:5},this.resultItem={tag:"li"},function(t){const e=t.id,r=t.name,o=t.options,i=t.resultsList,s=t.resultItem;for(const e in o)if("object"===n(o[e]))for(const n in t[e]||(t[e]={}),o[e])t[e][n]=o[e][n];else t[e]=o[e];t.selector=t.selector||`#${r}`,i.destination=i.destination||t.selector,i.id=i.id||`${r}_list_${e}`,s.id=s.id||`${r}_result`,t.input="string"==typeof t.selector?document.querySelector(t.selector):t.selector()}(this),function(t){const e=t.prototype;e.preInit=function(){u(this)},e.init=function(){x(this)},e.start=function(){E(this)},e.unInit=function(){let t;T((t=this).events,(e,n)=>{t[n].removeEventListener(e,t.events[n][e])})},e.open=function(){O(this)},e.close=function(){A(this)},e.goTo=function(t){S(t,this)},e.next=function(){L(this)},e.previous=function(){j(this)},e.select=function(t){k(this,null,t)},t.search=e.search=function(t,e,n){h(t,e,n)}}.call(this,t),(this.observe?u:x)(this)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).autoComplete=e(),window.document.dispatchEvent(new Event("autocompleteloaded"));