var e=function(e){return function(e){return!!e&&"object"==typeof e}(e)&&!function(e){var i=Object.prototype.toString.call(e);return"[object RegExp]"===i||"[object Date]"===i||function(e){return e.$$typeof===t}(e)}(e)};var t="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function i(e,t){return!1!==t.clone&&t.isMergeableObject(e)?c((i=e,Array.isArray(i)?[]:{}),e,t):e;var i}function s(e,t,s){return e.concat(t).map((function(e){return i(e,s)}))}function n(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter((function(t){return e.propertyIsEnumerable(t)})):[]}(e))}function r(e,t){try{return t in e}catch(e){return!1}}function o(e,t,s){var o={};return s.isMergeableObject(e)&&n(e).forEach((function(t){o[t]=i(e[t],s)})),n(t).forEach((function(n){(function(e,t){return r(e,t)&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))})(e,n)||(r(e,n)&&s.isMergeableObject(t[n])?o[n]=function(e,t){if(!t.customMerge)return c;var i=t.customMerge(e);return"function"==typeof i?i:c}(n,s)(e[n],t[n],s):o[n]=i(t[n],s))})),o}function c(t,n,r){(r=r||{}).arrayMerge=r.arrayMerge||s,r.isMergeableObject=r.isMergeableObject||e,r.cloneUnlessOtherwiseSpecified=i;var c=Array.isArray(n);return c===Array.isArray(t)?c?r.arrayMerge(t,n,r):o(t,n,r):i(n,r)}c.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce((function(e,i){return c(e,i,t)}),{})};var a=c;function l(e){return Array.isArray?Array.isArray(e):"[object Array]"===f(e)}function h(e){return"string"==typeof e}function d(e){return"number"==typeof e}function u(e){return!0===e||!1===e||function(e){return m(e)&&null!==e}(e)&&"[object Boolean]"==f(e)}function m(e){return"object"==typeof e}function p(e){return null!=e}function g(e){return!e.trim().length}function f(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const _=Object.prototype.hasOwnProperty;class v{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=E(e);t+=i.weight,this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function E(e){let t=null,i=null,s=null,n=1;if(h(e)||l(e))s=e,t=b(e),i=y(e);else{if(!_.call(e,"name"))throw new Error((e=>`Missing ${e} property in key`)("name"));const r=e.name;if(s=r,_.call(e,"weight")&&(n=e.weight,n<=0))throw new Error((e=>`Property 'weight' in key '${e}' must be a positive integer`)(r));t=b(r),i=y(r)}return{path:t,id:i,weight:n,src:s}}function b(e){return l(e)?e:e.split(".")}function y(e){return l(e)?e.join("."):e}var I={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:function(e,t){let i=[],s=!1;const n=(e,t,r)=>{if(p(e))if(t[r]){const o=e[t[r]];if(!p(o))return;if(r===t.length-1&&(h(o)||d(o)||u(o)))i.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;let t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(o));else if(l(o)){s=!0;for(let e=0,i=o.length;e<i;e+=1)n(o[e],t,r+1)}else t.length&&n(o,t,r+1)}else i.push(e)};return n(e,h(t)?t.split("."):t,0),s?i:i[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const S=/[^ ]+/g;class C{constructor({getFn:e=I.getFn,fieldNormWeight:t=I.fieldNormWeight}={}){this.norm=function(e=1,t=3){const i=new Map,s=Math.pow(10,t);return{get(t){const n=t.match(S).length;if(i.has(n))return i.get(n);const r=1/Math.pow(n,.5*e),o=parseFloat(Math.round(r*s)/s);return i.set(n,o),o},clear(){i.clear()}}}(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach(((e,t)=>{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,h(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const t=this.size();h(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,i=this.size();t<i;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!p(e)||g(e))return;let i={v:e,i:t,n:this.norm.get(e)};this.records.push(i)}_addObject(e,t){let i={i:t,$:{}};this.keys.forEach(((t,s)=>{let n=this.getFn(e,t.path);if(p(n))if(l(n)){let e=[];const t=[{nestedArrIndex:-1,value:n}];for(;t.length;){const{nestedArrIndex:i,value:s}=t.pop();if(p(s))if(h(s)&&!g(s)){let t={v:s,i:i,n:this.norm.get(s)};e.push(t)}else l(s)&&s.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[s]=e}else if(!g(n)){let e={v:n,n:this.norm.get(n)};i.$[s]=e}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function L(e,t,{getFn:i=I.getFn,fieldNormWeight:s=I.fieldNormWeight}={}){const n=new C({getFn:i,fieldNormWeight:s});return n.setKeys(e.map(E)),n.setSources(t),n.create(),n}function w(e,{errors:t=0,currentLocation:i=0,expectedLocation:s=0,distance:n=I.distance,ignoreLocation:r=I.ignoreLocation}={}){const o=t/e.length;if(r)return o;const c=Math.abs(s-i);return n?o+c/n:c?1:o}function O(e,t,i,{location:s=I.location,distance:n=I.distance,threshold:r=I.threshold,findAllMatches:o=I.findAllMatches,minMatchCharLength:c=I.minMatchCharLength,includeMatches:a=I.includeMatches,ignoreLocation:l=I.ignoreLocation}={}){if(t.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const h=t.length,d=e.length,u=Math.max(0,Math.min(s,d));let m=r,p=u;const g=c>1||a,f=g?Array(d):[];let _;for(;(_=e.indexOf(t,p))>-1;){let e=w(t,{currentLocation:_,expectedLocation:u,distance:n,ignoreLocation:l});if(m=Math.min(e,m),p=_+h,g){let e=0;for(;e<h;)f[_+e]=1,e+=1}}p=-1;let v=[],E=1,b=h+d;const y=1<<h-1;for(let s=0;s<h;s+=1){let r=0,c=b;for(;r<c;){w(t,{errors:s,currentLocation:u+c,expectedLocation:u,distance:n,ignoreLocation:l})<=m?r=c:b=c,c=Math.floor((b-r)/2+r)}b=c;let a=Math.max(1,u-c+1),_=o?d:Math.min(u+c,d)+h,I=Array(_+2);I[_+1]=(1<<s)-1;for(let r=_;r>=a;r-=1){let o=r-1,c=i[e.charAt(o)];if(g&&(f[o]=+!!c),I[r]=(I[r+1]<<1|1)&c,s&&(I[r]|=(v[r+1]|v[r])<<1|1|v[r+1]),I[r]&y&&(E=w(t,{errors:s,currentLocation:o,expectedLocation:u,distance:n,ignoreLocation:l}),E<=m)){if(m=E,p=o,p<=u)break;a=Math.max(1,2*u-p)}}if(w(t,{errors:s+1,currentLocation:u,expectedLocation:u,distance:n,ignoreLocation:l})>m)break;v=I}const S={isMatch:p>=0,score:Math.max(.001,E)};if(g){const e=function(e=[],t=I.minMatchCharLength){let i=[],s=-1,n=-1,r=0;for(let o=e.length;r<o;r+=1){let o=e[r];o&&-1===s?s=r:o||-1===s||(n=r-1,n-s+1>=t&&i.push([s,n]),s=-1)}return e[r-1]&&r-s>=t&&i.push([s,r-1]),i}(f,c);e.length?a&&(S.indices=e):S.isMatch=!1}return S}function A(e){let t={};for(let i=0,s=e.length;i<s;i+=1){const n=e.charAt(i);t[n]=(t[n]||0)|1<<s-i-1}return t}class T{constructor(e,{location:t=I.location,threshold:i=I.threshold,distance:s=I.distance,includeMatches:n=I.includeMatches,findAllMatches:r=I.findAllMatches,minMatchCharLength:o=I.minMatchCharLength,isCaseSensitive:c=I.isCaseSensitive,ignoreLocation:a=I.ignoreLocation}={}){if(this.options={location:t,threshold:i,distance:s,includeMatches:n,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:c,ignoreLocation:a},this.pattern=c?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const l=(e,t)=>{this.chunks.push({pattern:e,alphabet:A(e),startIndex:t})},h=this.pattern.length;if(h>32){let e=0;const t=h%32,i=h-t;for(;e<i;)l(this.pattern.substr(e,32),e),e+=32;if(t){const e=h-32;l(this.pattern.substr(e),e)}}else l(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,includeMatches:i}=this.options;if(t||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return i&&(t.indices=[[0,e.length-1]]),t}const{location:s,distance:n,threshold:r,findAllMatches:o,minMatchCharLength:c,ignoreLocation:a}=this.options;let l=[],h=0,d=!1;this.chunks.forEach((({pattern:t,alphabet:u,startIndex:m})=>{const{isMatch:p,score:g,indices:f}=O(e,t,u,{location:s+m,distance:n,threshold:r,findAllMatches:o,minMatchCharLength:c,includeMatches:i,ignoreLocation:a});p&&(d=!0),h+=g,p&&f&&(l=[...l,...f])}));let u={isMatch:d,score:d?h/this.chunks.length:1};return d&&i&&(u.indices=l),u}}class x{constructor(e){this.pattern=e}static isMultiMatch(e){return M(e,this.multiRegex)}static isSingleMatch(e){return M(e,this.singleRegex)}search(){}}function M(e,t){const i=e.match(t);return i?i[1]:null}class N extends x{constructor(e,{location:t=I.location,threshold:i=I.threshold,distance:s=I.distance,includeMatches:n=I.includeMatches,findAllMatches:r=I.findAllMatches,minMatchCharLength:o=I.minMatchCharLength,isCaseSensitive:c=I.isCaseSensitive,ignoreLocation:a=I.ignoreLocation}={}){super(e),this._bitapSearch=new T(e,{location:t,threshold:i,distance:s,includeMatches:n,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:c,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class D extends x{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t,i=0;const s=[],n=this.pattern.length;for(;(t=e.indexOf(this.pattern,i))>-1;)i=t+n,s.push([t,i-1]);const r=!!s.length;return{isMatch:r,score:r?0:1,indices:s}}}const F=[class extends x{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},D,class extends x{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},class extends x{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class extends x{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class extends x{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},class extends x{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},N],P=F.length,k=/ +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;const R=new Set([N.type,D.type]);class K{constructor(e,{isCaseSensitive:t=I.isCaseSensitive,includeMatches:i=I.includeMatches,minMatchCharLength:s=I.minMatchCharLength,ignoreLocation:n=I.ignoreLocation,findAllMatches:r=I.findAllMatches,location:o=I.location,threshold:c=I.threshold,distance:a=I.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:i,minMatchCharLength:s,findAllMatches:r,ignoreLocation:n,location:o,threshold:c,distance:a},this.pattern=t?e:e.toLowerCase(),this.query=function(e,t={}){return e.split("|").map((e=>{let i=e.trim().split(k).filter((e=>e&&!!e.trim())),s=[];for(let e=0,n=i.length;e<n;e+=1){const n=i[e];let r=!1,o=-1;for(;!r&&++o<P;){const e=F[o];let i=e.isMultiMatch(n);i&&(s.push(new e(i,t)),r=!0)}if(!r)for(o=-1;++o<P;){const e=F[o];let i=e.isSingleMatch(n);if(i){s.push(new e(i,t));break}}}return s}))}(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:i,isCaseSensitive:s}=this.options;e=s?e:e.toLowerCase();let n=0,r=[],o=0;for(let s=0,c=t.length;s<c;s+=1){const c=t[s];r.length=0,n=0;for(let t=0,s=c.length;t<s;t+=1){const s=c[t],{isMatch:a,indices:l,score:h}=s.search(e);if(!a){o=0,n=0,r.length=0;break}if(n+=1,o+=h,i){const e=s.constructor.type;R.has(e)?r=[...r,...l]:r.push(l)}}if(n){let e={isMatch:!0,score:o/n};return i&&(e.indices=r),e}}return{isMatch:!1,score:1}}}const H=[];function $(e,t){for(let i=0,s=H.length;i<s;i+=1){let s=H[i];if(s.condition(e,t))return new s(e,t)}return new T(e,t)}const j="$and",B="$or",V="$path",G="$val",W=e=>!(!e[j]&&!e[B]),q=e=>({[j]:Object.keys(e).map((t=>({[t]:e[t]})))});function U(e,t,{auto:i=!0}={}){const s=e=>{let n=Object.keys(e);const r=(e=>!!e[V])(e);if(!r&&n.length>1&&!W(e))return s(q(e));if((e=>!l(e)&&m(e)&&!W(e))(e)){const s=r?e[V]:n[0],o=r?e[G]:e[s];if(!h(o))throw new Error((e=>`Invalid value for key ${e}`)(s));const c={keyId:y(s),pattern:o};return i&&(c.searcher=$(o,t)),c}let o={children:[],operator:n[0]};return n.forEach((t=>{const i=e[t];l(i)&&i.forEach((e=>{o.children.push(s(e))}))})),o};return W(e)||(e=q(e)),s(e)}function Y(e,t){const i=e.matches;t.matches=[],p(i)&&i.forEach((e=>{if(!p(e.indices)||!e.indices.length)return;const{indices:i,value:s}=e;let n={indices:i,value:s};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}))}function z(e,t){t.score=e.score}class X{constructor(e,t={},i){this.options={...I,...t},this.options.useExtendedSearch,this._keyStore=new v(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof C))throw new Error("Incorrect 'index' type");this._myIndex=t||L(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){p(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=(()=>!1)){const t=[];for(let i=0,s=this._docs.length;i<s;i+=1){const n=this._docs[i];e(n,i)&&(this.removeAt(i),i-=1,s-=1,t.push(n))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:i,includeScore:s,shouldSort:n,sortFn:r,ignoreFieldNorm:o}=this.options;let c=h(e)?h(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return function(e,{ignoreFieldNorm:t=I.ignoreFieldNorm}){e.forEach((e=>{let i=1;e.matches.forEach((({key:e,norm:s,score:n})=>{const r=e?e.weight:null;i*=Math.pow(0===n&&r?Number.EPSILON:n,(r||1)*(t?1:s))})),e.score=i}))}(c,{ignoreFieldNorm:o}),n&&c.sort(r),d(t)&&t>-1&&(c=c.slice(0,t)),function(e,t,{includeMatches:i=I.includeMatches,includeScore:s=I.includeScore}={}){const n=[];return i&&n.push(Y),s&&n.push(z),e.map((e=>{const{idx:i}=e,s={item:t[i],refIndex:i};return n.length&&n.forEach((t=>{t(e,s)})),s}))}(c,this._docs,{includeMatches:i,includeScore:s})}_searchStringList(e){const t=$(e,this.options),{records:i}=this._myIndex,s=[];return i.forEach((({v:e,i:i,n:n})=>{if(!p(e))return;const{isMatch:r,score:o,indices:c}=t.searchIn(e);r&&s.push({item:e,idx:i,matches:[{score:o,value:e,norm:n,indices:c}]})})),s}_searchLogical(e){const t=U(e,this.options),i=(e,t,s)=>{if(!e.children){const{keyId:i,searcher:n}=e,r=this._findMatches({key:this._keyStore.get(i),value:this._myIndex.getValueForItemAtKeyId(t,i),searcher:n});return r&&r.length?[{idx:s,item:t,matches:r}]:[]}const n=[];for(let r=0,o=e.children.length;r<o;r+=1){const o=e.children[r],c=i(o,t,s);if(c.length)n.push(...c);else if(e.operator===j)return[]}return n},s=this._myIndex.records,n={},r=[];return s.forEach((({$:e,i:s})=>{if(p(e)){let o=i(t,e,s);o.length&&(n[s]||(n[s]={idx:s,item:e,matches:[]},r.push(n[s])),o.forEach((({matches:e})=>{n[s].matches.push(...e)})))}})),r}_searchObjectList(e){const t=$(e,this.options),{keys:i,records:s}=this._myIndex,n=[];return s.forEach((({$:e,i:s})=>{if(!p(e))return;let r=[];i.forEach(((i,s)=>{r.push(...this._findMatches({key:i,value:e[s],searcher:t}))})),r.length&&n.push({idx:s,item:e,matches:r})})),n}_findMatches({key:e,value:t,searcher:i}){if(!p(t))return[];let s=[];if(l(t))t.forEach((({v:t,i:n,n:r})=>{if(!p(t))return;const{isMatch:o,score:c,indices:a}=i.searchIn(t);o&&s.push({score:c,key:e,value:t,idx:n,norm:r,indices:a})}));else{const{v:n,n:r}=t,{isMatch:o,score:c,indices:a}=i.searchIn(n);o&&s.push({score:c,key:e,value:n,norm:r,indices:a})}return s}}X.version="6.5.3",X.createIndex=L,X.parseIndex=function(e,{getFn:t=I.getFn,fieldNormWeight:i=I.fieldNormWeight}={}){const{keys:s,records:n}=e,r=new C({getFn:t,fieldNormWeight:i});return r.setKeys(s),r.setIndexRecords(n),r},X.config=I,X.parseQuery=U,function(...e){H.push(...e)}(K);const J={showDropdown:"showDropdown",hideDropdown:"hideDropdown",change:"change",choice:"choice",search:"search",addItem:"addItem",removeItem:"removeItem",highlightItem:"highlightItem",highlightChoice:"highlightChoice",unhighlightItem:"unhighlightItem"},Q={ADD_CHOICE:"ADD_CHOICE",FILTER_CHOICES:"FILTER_CHOICES",ACTIVATE_CHOICES:"ACTIVATE_CHOICES",CLEAR_CHOICES:"CLEAR_CHOICES",ADD_GROUP:"ADD_GROUP",ADD_ITEM:"ADD_ITEM",REMOVE_ITEM:"REMOVE_ITEM",HIGHLIGHT_ITEM:"HIGHLIGHT_ITEM",CLEAR_ALL:"CLEAR_ALL",RESET_TO:"RESET_TO",SET_IS_LOADING:"SET_IS_LOADING"},Z={BACK_KEY:46,DELETE_KEY:8,ENTER_KEY:13,A_KEY:65,ESC_KEY:27,UP_KEY:38,DOWN_KEY:40,PAGE_UP_KEY:33,PAGE_DOWN_KEY:34},ee="text",te="select-one",ie="select-multiple",se=4,ne=(e=!0)=>({type:Q.ACTIVATE_CHOICES,active:e}),re=({value:e,id:t,active:i,disabled:s})=>({type:Q.ADD_GROUP,value:e,id:t,active:i,disabled:s}),oe=(e,t)=>({type:Q.HIGHLIGHT_ITEM,id:e,highlighted:t}),ce=e=>({type:Q.SET_IS_LOADING,isLoading:e});class ae{constructor({element:e,type:t,classNames:i}){this.element=e,this.classNames=i,this.type=t,this.isActive=!1}get distanceFromTopWindow(){return this.element.getBoundingClientRect().bottom}getChild(e){return this.element.querySelector(e)}show(){return this.element.classList.add(this.classNames.activeState),this.element.setAttribute("aria-expanded","true"),this.isActive=!0,this}hide(){return this.element.classList.remove(this.classNames.activeState),this.element.setAttribute("aria-expanded","false"),this.isActive=!1,this}}const le=e=>Array.from({length:e},(()=>{return(e=0,t=36,Math.floor(Math.random()*(t-e)+e)).toString(36);var e,t})).join(""),he=e=>Object.prototype.toString.call(e).slice(8,-1),de=(e,t)=>null!=t&&he(t)===e,ue=e=>"string"!=typeof e?e:e.replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/"/g,"&quot;"),me=(()=>{const e=document.createElement("div");return t=>{const i=t.trim();e.innerHTML=i;const s=e.children[0];for(;e.firstChild;)e.removeChild(e.firstChild);return s}})(),pe=(e,t)=>{const{score:i=0}=e,{score:s=0}=t;return i-s};class ge{constructor({element:e,type:t,classNames:i,position:s}){this.element=e,this.classNames=i,this.type=t,this.position=s,this.isOpen=!1,this.isFlipped=!1,this.isFocussed=!1,this.isDisabled=!1,this.isLoading=!1,this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}addEventListeners(){this.element.addEventListener("focus",this._onFocus),this.element.addEventListener("blur",this._onBlur)}removeEventListeners(){this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur)}shouldFlip(e){if("number"!=typeof e)return!1;let t=!1;return"auto"===this.position?t=!window.matchMedia(`(min-height: ${e+1}px)`).matches:"top"===this.position&&(t=!0),t}setActiveDescendant(e){this.element.setAttribute("aria-activedescendant",e)}removeActiveDescendant(){this.element.removeAttribute("aria-activedescendant")}open(e){this.element.classList.add(this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e)&&(this.element.classList.add(this.classNames.flippedState),this.isFlipped=!0)}close(){this.element.classList.remove(this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(this.element.classList.remove(this.classNames.flippedState),this.isFlipped=!1)}focus(){this.isFocussed||this.element.focus()}addFocusState(){this.element.classList.add(this.classNames.focusState)}removeFocusState(){this.element.classList.remove(this.classNames.focusState)}enable(){this.element.classList.remove(this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),"select-one"===this.type&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1}disable(){this.element.classList.add(this.classNames.disabledState),this.element.setAttribute("aria-disabled","true"),"select-one"===this.type&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0}wrap(e){((e,t=document.createElement("div"))=>{e.parentNode&&(e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t)),t.appendChild(e)})(e,this.element)}unwrap(e){this.element.parentNode&&(this.element.parentNode.insertBefore(e,this.element),this.element.parentNode.removeChild(this.element))}addLoadingState(){this.element.classList.add(this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0}removeLoadingState(){this.element.classList.remove(this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1}_onFocus(){this.isFocussed=!0}_onBlur(){this.isFocussed=!1}}class fe{constructor({element:e,type:t,classNames:i,preventPaste:s}){this.element=e,this.type=t,this.classNames=i,this.preventPaste=s,this.isFocussed=this.element.isEqualNode(document.activeElement),this.isDisabled=e.disabled,this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}set placeholder(e){this.element.placeholder=e}get value(){return ue(this.element.value)}set value(e){this.element.value=e}get rawValue(){return this.element.value}addEventListeners(){this.element.addEventListener("paste",this._onPaste),this.element.addEventListener("input",this._onInput,{passive:!0}),this.element.addEventListener("focus",this._onFocus,{passive:!0}),this.element.addEventListener("blur",this._onBlur,{passive:!0})}removeEventListeners(){this.element.removeEventListener("input",this._onInput),this.element.removeEventListener("paste",this._onPaste),this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur)}enable(){this.element.removeAttribute("disabled"),this.isDisabled=!1}disable(){this.element.setAttribute("disabled",""),this.isDisabled=!0}focus(){this.isFocussed||this.element.focus()}blur(){this.isFocussed&&this.element.blur()}clear(e=!0){return this.element.value&&(this.element.value=""),e&&this.setWidth(),this}setWidth(){const{style:e,value:t,placeholder:i}=this.element;e.minWidth=`${i.length+1}ch`,e.width=`${t.length+1}ch`}setActiveDescendant(e){this.element.setAttribute("aria-activedescendant",e)}removeActiveDescendant(){this.element.removeAttribute("aria-activedescendant")}_onInput(){"select-one"!==this.type&&this.setWidth()}_onPaste(e){this.preventPaste&&e.preventDefault()}_onFocus(){this.isFocussed=!0}_onBlur(){this.isFocussed=!1}}class _e{constructor({element:e}){this.element=e,this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight}clear(){this.element.innerHTML=""}append(e){this.element.appendChild(e)}getChild(e){return this.element.querySelector(e)}hasChildren(){return this.element.hasChildNodes()}scrollToTop(){this.element.scrollTop=0}scrollToChildElement(e,t){if(!e)return;const i=this.element.offsetHeight,s=this.element.scrollTop+i,n=e.offsetHeight,r=e.offsetTop+n,o=t>0?this.element.scrollTop+r-s:e.offsetTop;requestAnimationFrame((()=>{this._animateScroll(o,t)}))}_scrollDown(e,t,i){const s=(i-e)/t,n=s>1?s:1;this.element.scrollTop=e+n}_scrollUp(e,t,i){const s=(e-i)/t,n=s>1?s:1;this.element.scrollTop=e-n}_animateScroll(e,t){const i=this.element.scrollTop;let s=!1;t>0?(this._scrollDown(i,4,e),i<e&&(s=!0)):(this._scrollUp(i,4,e),i>e&&(s=!0)),s&&requestAnimationFrame((()=>{this._animateScroll(e,t)}))}}class ve{constructor({element:e,classNames:t}){if(this.element=e,this.classNames=t,!(e instanceof HTMLInputElement||e instanceof HTMLSelectElement))throw new TypeError("Invalid element passed");this.isDisabled=!1}get isActive(){return"active"===this.element.dataset.choice}get dir(){return this.element.dir}get value(){return this.element.value}set value(e){this.element.value=e}conceal(){this.element.classList.add(this.classNames.input),this.element.hidden=!0,this.element.tabIndex=-1;const e=this.element.getAttribute("style");e&&this.element.setAttribute("data-choice-orig-style",e),this.element.setAttribute("data-choice","active")}reveal(){this.element.classList.remove(this.classNames.input),this.element.hidden=!1,this.element.removeAttribute("tabindex");const e=this.element.getAttribute("data-choice-orig-style");e?(this.element.removeAttribute("data-choice-orig-style"),this.element.setAttribute("style",e)):this.element.removeAttribute("style"),this.element.removeAttribute("data-choice"),this.element.value=this.element.value}enable(){this.element.removeAttribute("disabled"),this.element.disabled=!1,this.isDisabled=!1}disable(){this.element.setAttribute("disabled",""),this.element.disabled=!0,this.isDisabled=!0}triggerEvent(e,t){((e,t,i=null)=>{const s=new CustomEvent(t,{detail:i,bubbles:!0,cancelable:!0});e.dispatchEvent(s)})(this.element,e,t)}}class Ee extends ve{constructor({element:e,classNames:t,delimiter:i}){super({element:e,classNames:t}),this.delimiter=i}get value(){return this.element.value}set value(e){this.element.setAttribute("value",e),this.element.value=e}}class be extends ve{constructor({element:e,classNames:t,template:i}){super({element:e,classNames:t}),this.template=i}get placeholderOption(){return this.element.querySelector('option[value=""]')||this.element.querySelector("option[placeholder]")}get optionGroups(){return Array.from(this.element.getElementsByTagName("OPTGROUP"))}get options(){return Array.from(this.element.options)}set options(e){const t=document.createDocumentFragment(),i=e=>{const i=this.template(e);t.appendChild(i)};e.forEach((e=>i(e))),this.appendDocFragment(t)}appendDocFragment(e){this.element.innerHTML="",this.element.appendChild(e)}}const ye={containerOuter:"choices",containerInner:"choices__inner",input:"choices__input",inputCloned:"choices__input--cloned",list:"choices__list",listItems:"choices__list--multiple",listSingle:"choices__list--single",listDropdown:"choices__list--dropdown",item:"choices__item",itemSelectable:"choices__item--selectable",itemDisabled:"choices__item--disabled",itemChoice:"choices__item--choice",placeholder:"choices__placeholder",group:"choices__group",groupHeading:"choices__heading",button:"choices__button",activeState:"is-active",focusState:"is-focused",openState:"is-open",disabledState:"is-disabled",highlightedState:"is-highlighted",selectedState:"is-selected",flippedState:"is-flipped",loadingState:"is-loading",noResults:"has-no-results",noChoices:"has-no-choices"},Ie={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,addItems:!0,addItemFilter:null,removeItems:!0,removeItemButton:!1,editItems:!1,allowHTML:!0,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sorter:({value:e,label:t=e},{value:i,label:s=i})=>t.localeCompare(s,[],{sensitivity:"base",ignorePunctuation:!0,numeric:!0}),placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:e=>`Press Enter to add <b>"${ue(e)}"</b>`,maxItemText:e=>`Only ${e} values can be added`,valueComparer:(e,t)=>e===t,fuseOptions:{includeScore:!0},callbackOnInit:null,callbackOnCreateTemplates:null,classNames:ye};function Se(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}var Ce="function"==typeof Symbol&&Symbol.observable||"@@observable",Le=function(){return Math.random().toString(36).substring(7).split("").join(".")},we={INIT:"@@redux/INIT"+Le(),REPLACE:"@@redux/REPLACE"+Le(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Le()}};function Oe(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Ae(e,t,i){var s;if("function"==typeof t&&"function"==typeof i||"function"==typeof i&&"function"==typeof arguments[3])throw new Error(Se(0));if("function"==typeof t&&void 0===i&&(i=t,t=void 0),void 0!==i){if("function"!=typeof i)throw new Error(Se(1));return i(Ae)(e,t)}if("function"!=typeof e)throw new Error(Se(2));var n=e,r=t,o=[],c=o,a=!1;function l(){c===o&&(c=o.slice())}function h(){if(a)throw new Error(Se(3));return r}function d(e){if("function"!=typeof e)throw new Error(Se(4));if(a)throw new Error(Se(5));var t=!0;return l(),c.push(e),function(){if(t){if(a)throw new Error(Se(6));t=!1,l();var i=c.indexOf(e);c.splice(i,1),o=null}}}function u(e){if(!Oe(e))throw new Error(Se(7));if(void 0===e.type)throw new Error(Se(8));if(a)throw new Error(Se(9));try{a=!0,r=n(r,e)}finally{a=!1}for(var t=o=c,i=0;i<t.length;i++){(0,t[i])()}return e}function m(e){if("function"!=typeof e)throw new Error(Se(10));n=e,u({type:we.REPLACE})}function p(){var e,t=d;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(Se(11));function i(){e.next&&e.next(h())}return i(),{unsubscribe:t(i)}}})[Ce]=function(){return this},e}return u({type:we.INIT}),(s={dispatch:u,subscribe:d,getState:h,replaceReducer:m})[Ce]=p,s}const Te=[];const xe=[];const Me=[];const Ne={groups:[],items:[],choices:[],loading:!1},De=function(e){for(var t=Object.keys(e),i={},s=0;s<t.length;s++){var n=t[s];"function"==typeof e[n]&&(i[n]=e[n])}var r,o=Object.keys(i);try{!function(e){Object.keys(e).forEach((function(t){var i=e[t];if(void 0===i(void 0,{type:we.INIT}))throw new Error(Se(12));if(void 0===i(void 0,{type:we.PROBE_UNKNOWN_ACTION()}))throw new Error(Se(13))}))}(i)}catch(e){r=e}return function(e,t){if(void 0===e&&(e={}),r)throw r;for(var s=!1,n={},c=0;c<o.length;c++){var a=o[c],l=i[a],h=e[a],d=l(h,t);if(void 0===d)throw t&&t.type,new Error(Se(14));n[a]=d,s=s||d!==h}return(s=s||o.length!==Object.keys(e).length)?n:e}}({items:function(e=Te,t={}){switch(t.type){case"ADD_ITEM":{const i=t;return[...e,{id:i.id,choiceId:i.choiceId,groupId:i.groupId,value:i.value,label:i.label,active:!0,highlighted:!1,customProperties:i.customProperties,placeholder:i.placeholder||!1,keyCode:null}].map((e=>{const t=e;return t.highlighted=!1,t}))}case"REMOVE_ITEM":return e.map((e=>{const i=e;return i.id===t.id&&(i.active=!1),i}));case"HIGHLIGHT_ITEM":{const i=t;return e.map((e=>{const t=e;return t.id===i.id&&(t.highlighted=i.highlighted),t}))}default:return e}},groups:function(e=xe,t={}){switch(t.type){case"ADD_GROUP":{const i=t;return[...e,{id:i.id,value:i.value,active:i.active,disabled:i.disabled}]}case"CLEAR_CHOICES":return[];default:return e}},choices:function(e=Me,t={}){switch(t.type){case"ADD_CHOICE":{const i=t,s={id:i.id,elementId:i.elementId,groupId:i.groupId,value:i.value,label:i.label||i.value,disabled:i.disabled||!1,selected:!1,active:!0,score:9999,customProperties:i.customProperties,placeholder:i.placeholder||!1};return[...e,s]}case"ADD_ITEM":{const i=t;return i.choiceId>-1?e.map((e=>{const t=e;return t.id===parseInt(`${i.choiceId}`,10)&&(t.selected=!0),t})):e}case"REMOVE_ITEM":{const i=t;return i.choiceId&&i.choiceId>-1?e.map((e=>{const t=e;return t.id===parseInt(`${i.choiceId}`,10)&&(t.selected=!1),t})):e}case"FILTER_CHOICES":{const i=t;return e.map((e=>{const t=e;return t.active=i.results.some((({item:e,score:i})=>e.id===t.id&&(t.score=i,!0))),t}))}case"ACTIVATE_CHOICES":{const i=t;return e.map((e=>{const t=e;return t.active=i.active,t}))}case"CLEAR_CHOICES":return Me;default:return e}},loading:(e=false,t={})=>"SET_IS_LOADING"===t.type?t.isLoading:e}),Fe=(e,t)=>{let i=e;if("CLEAR_ALL"===t.type)i=Ne;else if("RESET_TO"===t.type)return s=t.state,JSON.parse(JSON.stringify(s));var s;return De(i,t)};class Pe{constructor(){this._store=Ae(Fe,window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__())}subscribe(e){this._store.subscribe(e)}dispatch(e){this._store.dispatch(e)}get state(){return this._store.getState()}get items(){return this.state.items}get activeItems(){return this.items.filter((e=>!0===e.active))}get highlightedActiveItems(){return this.items.filter((e=>e.active&&e.highlighted))}get choices(){return this.state.choices}get activeChoices(){return this.choices.filter((e=>!0===e.active))}get selectableChoices(){return this.choices.filter((e=>!0!==e.disabled))}get searchableChoices(){return this.selectableChoices.filter((e=>!0!==e.placeholder))}get placeholderChoice(){return[...this.choices].reverse().find((e=>!0===e.placeholder))}get groups(){return this.state.groups}get activeGroups(){const{groups:e,choices:t}=this;return e.filter((e=>{const i=!0===e.active&&!1===e.disabled,s=t.some((e=>!0===e.active&&!1===e.disabled));return i&&s}),[])}isLoading(){return this.state.loading}getChoiceById(e){return this.activeChoices.find((t=>t.id===parseInt(e,10)))}getGroupById(e){return this.groups.find((t=>t.id===e))}}const ke={containerOuter({classNames:{containerOuter:e}},t,i,s,n,r){const o=Object.assign(document.createElement("div"),{className:e});return o.dataset.type=r,t&&(o.dir=t),s&&(o.tabIndex=0),i&&(o.setAttribute("role",n?"combobox":"listbox"),n&&o.setAttribute("aria-autocomplete","list")),o.setAttribute("aria-haspopup","true"),o.setAttribute("aria-expanded","false"),o},containerInner:({classNames:{containerInner:e}})=>Object.assign(document.createElement("div"),{className:e}),itemList:({classNames:{list:e,listSingle:t,listItems:i}},s)=>Object.assign(document.createElement("div"),{className:`${e} ${s?t:i}`}),placeholder:({allowHTML:e,classNames:{placeholder:t}},i)=>Object.assign(document.createElement("div"),{className:t,[e?"innerHTML":"innerText"]:i}),item({allowHTML:e,classNames:{item:t,button:i,highlightedState:s,itemSelectable:n,placeholder:r}},{id:o,value:c,label:a,customProperties:l,active:h,disabled:d,highlighted:u,placeholder:m},p){const g=Object.assign(document.createElement("div"),{className:t,[e?"innerHTML":"innerText"]:a});if(Object.assign(g.dataset,{item:"",id:o,value:c,customProperties:l}),h&&g.setAttribute("aria-selected","true"),d&&g.setAttribute("aria-disabled","true"),m&&g.classList.add(r),g.classList.add(u?s:n),p){d&&g.classList.remove(n),g.dataset.deletable="";const t="Remove item",s=Object.assign(document.createElement("button"),{type:"button",className:i,[e?"innerHTML":"innerText"]:t});s.setAttribute("aria-label",`${t}: '${c}'`),s.dataset.button="",g.appendChild(s)}return g},choiceList({classNames:{list:e}},t){const i=Object.assign(document.createElement("div"),{className:e});return t||i.setAttribute("aria-multiselectable","true"),i.setAttribute("role","listbox"),i},choiceGroup({allowHTML:e,classNames:{group:t,groupHeading:i,itemDisabled:s}},{id:n,value:r,disabled:o}){const c=Object.assign(document.createElement("div"),{className:`${t} ${o?s:""}`});return c.setAttribute("role","group"),Object.assign(c.dataset,{group:"",id:n,value:r}),o&&c.setAttribute("aria-disabled","true"),c.appendChild(Object.assign(document.createElement("div"),{className:i,[e?"innerHTML":"innerText"]:r})),c},choice({allowHTML:e,classNames:{item:t,itemChoice:i,itemSelectable:s,selectedState:n,itemDisabled:r,placeholder:o}},{id:c,value:a,label:l,groupId:h,elementId:d,disabled:u,selected:m,placeholder:p},g){const f=Object.assign(document.createElement("div"),{id:d,[e?"innerHTML":"innerText"]:l,className:`${t} ${i}`});return m&&f.classList.add(n),p&&f.classList.add(o),f.setAttribute("role",h&&h>0?"treeitem":"option"),Object.assign(f.dataset,{choice:"",id:c,value:a,selectText:g}),u?(f.classList.add(r),f.dataset.choiceDisabled="",f.setAttribute("aria-disabled","true")):(f.classList.add(s),f.dataset.choiceSelectable=""),f},input({classNames:{input:e,inputCloned:t}},i){const s=Object.assign(document.createElement("input"),{type:"search",name:"search_terms",className:`${e} ${t}`,autocomplete:"off",autocapitalize:"off",spellcheck:!1});return s.setAttribute("role","textbox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-label",i),s},dropdown({classNames:{list:e,listDropdown:t}}){const i=document.createElement("div");return i.classList.add(e,t),i.setAttribute("aria-expanded","false"),i},notice({allowHTML:e,classNames:{item:t,itemChoice:i,noResults:s,noChoices:n}},r,o=""){const c=[t,i];return"no-choices"===o?c.push(n):"no-results"===o&&c.push(s),Object.assign(document.createElement("div"),{[e?"innerHTML":"innerText"]:r,className:c.join(" ")})},option({label:e,value:t,customProperties:i,active:s,disabled:n}){const r=new Option(e,t,!1,s);return i&&(r.dataset.customProperties=`${i}`),r.disabled=!!n,r}},Re="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,Ke={};class He{constructor(e="[data-choice]",t={}){void 0===t.allowHTML&&console.warn("Deprecation warning: allowHTML will default to false in a future release. To render HTML in Choices, you will need to set it to true. Setting allowHTML will suppress this message."),this.config=a.all([Ie,He.defaults.options,t],{arrayMerge:(e,t)=>[...t]});const i=((e,t)=>{const i=Object.keys(e).sort(),s=Object.keys(t).sort();return i.filter((e=>s.indexOf(e)<0))})(this.config,Ie);i.length&&console.warn("Unknown config option(s) passed",i.join(", "));const s="string"==typeof e?document.querySelector(e):e;if(!(s instanceof HTMLInputElement||s instanceof HTMLSelectElement))throw TypeError("Expected one of the following types text|select-one|select-multiple");if(this._isTextElement="text"===s.type,this._isSelectOneElement="select-one"===s.type,this._isSelectMultipleElement="select-multiple"===s.type,this._isSelectElement=this._isSelectOneElement||this._isSelectMultipleElement,this.config.searchEnabled=this._isSelectMultipleElement||this.config.searchEnabled,["auto","always"].includes(`${this.config.renderSelectedChoices}`)||(this.config.renderSelectedChoices="auto"),t.addItemFilter&&"function"!=typeof t.addItemFilter){const e=t.addItemFilter instanceof RegExp?t.addItemFilter:new RegExp(t.addItemFilter);this.config.addItemFilter=e.test.bind(e)}if(this._isTextElement?this.passedElement=new Ee({element:s,classNames:this.config.classNames,delimiter:this.config.delimiter}):this.passedElement=new be({element:s,classNames:this.config.classNames,template:e=>this._templates.option(e)}),this.initialised=!1,this._store=new Pe,this._initialState=Ne,this._currentState=Ne,this._prevState=Ne,this._currentValue="",this._canSearch=!!this.config.searchEnabled,this._isScrollingOnIe=!1,this._highlightPosition=0,this._wasTap=!0,this._placeholderValue=this._generatePlaceholderValue(),this._baseId=((e,t)=>{let i=e.id||e.name&&`${e.name}-${le(2)}`||le(4);return i=i.replace(/(:|\.|\[|\]|,)/g,""),i=`${t}-${i}`,i})(this.passedElement.element,"choices-"),this._direction=this.passedElement.dir,!this._direction){const{direction:e}=window.getComputedStyle(this.passedElement.element),{direction:t}=window.getComputedStyle(document.documentElement);e!==t&&(this._direction=e)}if(this._idNames={itemChoice:"item-choice"},this._isSelectElement&&(this._presetGroups=this.passedElement.optionGroups,this._presetOptions=this.passedElement.options),this._presetChoices=this.config.choices,this._presetItems=this.config.items,this.passedElement.value&&this._isTextElement){const e=this.passedElement.value.split(this.config.delimiter);this._presetItems=this._presetItems.concat(e)}if(this.passedElement.options&&this.passedElement.options.forEach((e=>{this._presetChoices.push({value:e.value,label:e.innerHTML,selected:!!e.selected,disabled:e.disabled||e.parentNode.disabled,placeholder:""===e.value||e.hasAttribute("placeholder"),customProperties:e.dataset["custom-properties"]})})),this._render=this._render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onFormReset=this._onFormReset.bind(this),this._onSelectKey=this._onSelectKey.bind(this),this._onEnterKey=this._onEnterKey.bind(this),this._onEscapeKey=this._onEscapeKey.bind(this),this._onDirectionKey=this._onDirectionKey.bind(this),this._onDeleteKey=this._onDeleteKey.bind(this),this.passedElement.isActive)return this.config.silent||console.warn("Trying to initialise Choices on element already initialised",{element:e}),void(this.initialised=!0);this.init()}static get defaults(){return Object.preventExtensions({get options(){return Ke},get templates(){return ke}})}init(){if(this.initialised)return;this._createTemplates(),this._createElements(),this._createStructure(),this._store.subscribe(this._render),this._render(),this._addEventListeners();(!this.config.addItems||this.passedElement.element.hasAttribute("disabled"))&&this.disable(),this.initialised=!0;const{callbackOnInit:e}=this.config;e&&"function"==typeof e&&e.call(this)}destroy(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this.clearStore(),this._isSelectElement&&(this.passedElement.options=this._presetOptions),this._templates=ke,this.initialised=!1)}enable(){return this.passedElement.isDisabled&&this.passedElement.enable(),this.containerOuter.isDisabled&&(this._addEventListeners(),this.input.enable(),this.containerOuter.enable()),this}disable(){return this.passedElement.isDisabled||this.passedElement.disable(),this.containerOuter.isDisabled||(this._removeEventListeners(),this.input.disable(),this.containerOuter.disable()),this}highlightItem(e,t=!0){if(!e||!e.id)return this;const{id:i,groupId:s=-1,value:n="",label:r=""}=e,o=s>=0?this._store.getGroupById(s):null;return this._store.dispatch(oe(i,!0)),t&&this.passedElement.triggerEvent(J.highlightItem,{id:i,value:n,label:r,groupValue:o&&o.value?o.value:null}),this}unhighlightItem(e){if(!e||!e.id)return this;const{id:t,groupId:i=-1,value:s="",label:n=""}=e,r=i>=0?this._store.getGroupById(i):null;return this._store.dispatch(oe(t,!1)),this.passedElement.triggerEvent(J.highlightItem,{id:t,value:s,label:n,groupValue:r&&r.value?r.value:null}),this}highlightAll(){return this._store.items.forEach((e=>this.highlightItem(e))),this}unhighlightAll(){return this._store.items.forEach((e=>this.unhighlightItem(e))),this}removeActiveItemsByValue(e){return this._store.activeItems.filter((t=>t.value===e)).forEach((e=>this._removeItem(e))),this}removeActiveItems(e){return this._store.activeItems.filter((({id:t})=>t!==e)).forEach((e=>this._removeItem(e))),this}removeHighlightedItems(e=!1){return this._store.highlightedActiveItems.forEach((t=>{this._removeItem(t),e&&this._triggerChange(t.value)})),this}showDropdown(e){return this.dropdown.isActive||requestAnimationFrame((()=>{this.dropdown.show(),this.containerOuter.open(this.dropdown.distanceFromTopWindow),!e&&this._canSearch&&this.input.focus(),this.passedElement.triggerEvent(J.showDropdown,{})})),this}hideDropdown(e){return this.dropdown.isActive?(requestAnimationFrame((()=>{this.dropdown.hide(),this.containerOuter.close(),!e&&this._canSearch&&(this.input.removeActiveDescendant(),this.input.blur()),this.passedElement.triggerEvent(J.hideDropdown,{})})),this):this}getValue(e=!1){const t=this._store.activeItems.reduce(((t,i)=>{const s=e?i.value:i;return t.push(s),t}),[]);return this._isSelectOneElement?t[0]:t}setValue(e){return this.initialised?(e.forEach((e=>this._setChoiceOrItem(e))),this):this}setChoiceByValue(e){if(!this.initialised||this._isTextElement)return this;return(Array.isArray(e)?e:[e]).forEach((e=>this._findAndSelectChoiceByValue(e))),this}setChoices(e=[],t="value",i="label",s=!1){if(!this.initialised)throw new ReferenceError("setChoices was called on a non-initialized instance of Choices");if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(s&&this.clearChoices(),"function"==typeof e){const n=e(this);if("function"==typeof Promise&&n instanceof Promise)return new Promise((e=>requestAnimationFrame(e))).then((()=>this._handleLoadingState(!0))).then((()=>n)).then((e=>this.setChoices(e,t,i,s))).catch((e=>{this.config.silent||console.error(e)})).then((()=>this._handleLoadingState(!1))).then((()=>this));if(!Array.isArray(n))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: "+typeof n);return this.setChoices(n,t,i,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._startLoading(),e.forEach((e=>{if(e.choices)this._addGroup({id:e.id?parseInt(`${e.id}`,10):null,group:e,valueKey:t,labelKey:i});else{const s=e;this._addChoice({value:s[t],label:s[i],isSelected:!!s.selected,isDisabled:!!s.disabled,placeholder:!!s.placeholder,customProperties:s.customProperties})}})),this._stopLoading(),this}clearChoices(){return this._store.dispatch({type:Q.CLEAR_CHOICES}),this}clearStore(){return this._store.dispatch({type:Q.CLEAR_ALL}),this}clearInput(){const e=!this._isSelectOneElement;return this.input.clear(e),!this._isTextElement&&this._canSearch&&(this._isSearching=!1,this._store.dispatch(ne(!0))),this}_render(){if(this._store.isLoading())return;this._currentState=this._store.state;const e=this._currentState.choices!==this._prevState.choices||this._currentState.groups!==this._prevState.groups||this._currentState.items!==this._prevState.items,t=this._isSelectElement,i=this._currentState.items!==this._prevState.items;e&&(t&&this._renderChoices(),i&&this._renderItems(),this._prevState=this._currentState)}_renderChoices(){const{activeGroups:e,activeChoices:t}=this._store;let i=document.createDocumentFragment();if(this.choiceList.clear(),this.config.resetScrollPosition&&requestAnimationFrame((()=>this.choiceList.scrollToTop())),e.length>=1&&!this._isSearching){const s=t.filter((e=>!0===e.placeholder&&-1===e.groupId));s.length>=1&&(i=this._createChoicesFragment(s,i)),i=this._createGroupsFragment(e,t,i)}else t.length>=1&&(i=this._createChoicesFragment(t,i));if(i.childNodes&&i.childNodes.length>0){const{activeItems:e}=this._store,t=this._canAddItem(e,this.input.value);if(t.response)this.choiceList.append(i),this._highlightChoice();else{const e=this._getTemplate("notice",t.notice);this.choiceList.append(e)}}else{let e,t;this._isSearching?(t="function"==typeof this.config.noResultsText?this.config.noResultsText():this.config.noResultsText,e=this._getTemplate("notice",t,"no-results")):(t="function"==typeof this.config.noChoicesText?this.config.noChoicesText():this.config.noChoicesText,e=this._getTemplate("notice",t,"no-choices")),this.choiceList.append(e)}}_renderItems(){const e=this._store.activeItems||[];this.itemList.clear();const t=this._createItemsFragment(e);t.childNodes&&this.itemList.append(t)}_createGroupsFragment(e,t,i=document.createDocumentFragment()){const s=e=>t.filter((t=>this._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===this.config.renderSelectedChoices||!t.selected)));return this.config.shouldSort&&e.sort(this.config.sorter),e.forEach((e=>{const t=s(e);if(t.length>=1){const s=this._getTemplate("choiceGroup",e);i.appendChild(s),this._createChoicesFragment(t,i,!0)}})),i}_createChoicesFragment(e,t=document.createDocumentFragment(),i=!1){const{renderSelectedChoices:s,searchResultLimit:n,renderChoiceLimit:r}=this.config,o=this._isSearching?pe:this.config.sorter,c=e=>{if("auto"!==s||(this._isSelectOneElement||!e.selected)){const i=this._getTemplate("choice",e,this.config.itemSelectText);t.appendChild(i)}};let a=e;"auto"!==s||this._isSelectOneElement||(a=e.filter((e=>!e.selected)));const{placeholderChoices:l,normalChoices:h}=a.reduce(((e,t)=>(t.placeholder?e.placeholderChoices.push(t):e.normalChoices.push(t),e)),{placeholderChoices:[],normalChoices:[]});(this.config.shouldSort||this._isSearching)&&h.sort(o);let d=a.length;const u=this._isSelectOneElement?[...l,...h]:h;this._isSearching?d=n:r&&r>0&&!i&&(d=r);for(let e=0;e<d;e+=1)u[e]&&c(u[e]);return t}_createItemsFragment(e,t=document.createDocumentFragment()){const{shouldSortItems:i,sorter:s,removeItemButton:n}=this.config;i&&!this._isSelectOneElement&&e.sort(s),this._isTextElement?this.passedElement.value=e.map((({value:e})=>e)).join(this.config.delimiter):this.passedElement.options=e;return e.forEach((e=>{const i=this._getTemplate("item",e,n);t.appendChild(i)})),t}_triggerChange(e){null!=e&&this.passedElement.triggerEvent(J.change,{value:e})}_selectPlaceholderChoice(e){this._addItem({value:e.value,label:e.label,choiceId:e.id,groupId:e.groupId,placeholder:e.placeholder}),this._triggerChange(e.value)}_handleButtonAction(e,t){if(!(e&&t&&this.config.removeItems&&this.config.removeItemButton))return;const i=t.parentNode&&t.parentNode.dataset.id,s=i&&e.find((e=>e.id===parseInt(i,10)));s&&(this._removeItem(s),this._triggerChange(s.value),this._isSelectOneElement&&this._store.placeholderChoice&&this._selectPlaceholderChoice(this._store.placeholderChoice))}_handleItemAction(e,t,i=!1){if(!e||!t||!this.config.removeItems||this._isSelectOneElement)return;const s=t.dataset.id;e.forEach((e=>{e.id!==parseInt(`${s}`,10)||e.highlighted?!i&&e.highlighted&&this.unhighlightItem(e):this.highlightItem(e)})),this.input.focus()}_handleChoiceAction(e,t){if(!e||!t)return;const{id:i}=t.dataset,s=i&&this._store.getChoiceById(i);if(!s)return;const n=e[0]&&e[0].keyCode?e[0].keyCode:void 0,r=this.dropdown.isActive;if(s.keyCode=n,this.passedElement.triggerEvent(J.choice,{choice:s}),!s.selected&&!s.disabled){this._canAddItem(e,s.value).response&&(this._addItem({value:s.value,label:s.label,choiceId:s.id,groupId:s.groupId,customProperties:s.customProperties,placeholder:s.placeholder,keyCode:s.keyCode}),this._triggerChange(s.value))}this.clearInput(),r&&this._isSelectOneElement&&(this.hideDropdown(!0),this.containerOuter.focus())}_handleBackspace(e){if(!this.config.removeItems||!e)return;const t=e[e.length-1],i=e.some((e=>e.highlighted));this.config.editItems&&!i&&t?(this.input.value=t.value,this.input.setWidth(),this._removeItem(t),this._triggerChange(t.value)):(i||this.highlightItem(t,!1),this.removeHighlightedItems(!0))}_startLoading(){this._store.dispatch(ce(!0))}_stopLoading(){this._store.dispatch(ce(!1))}_handleLoadingState(e=!0){let t=this.itemList.getChild(`.${this.config.classNames.placeholder}`);e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?t?t.innerHTML=this.config.loadingText:(t=this._getTemplate("placeholder",this.config.loadingText),t&&this.itemList.append(t)):this.input.placeholder=this.config.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement?t&&(t.innerHTML=this._placeholderValue||""):this.input.placeholder=this._placeholderValue||"")}_handleSearch(e){if(!this.input.isFocussed)return;const{choices:t}=this._store,{searchFloor:i,searchChoices:s}=this.config,n=t.some((e=>!e.active));if(null!=e&&e.length>=i){const t=s?this._searchChoices(e):0;this.passedElement.triggerEvent(J.search,{value:e,resultCount:t})}else n&&(this._isSearching=!1,this._store.dispatch(ne(!0)))}_canAddItem(e,t){let i=!0,s="function"==typeof this.config.addItemText?this.config.addItemText(t):this.config.addItemText;if(!this._isSelectOneElement){const n=((e,t,i="value")=>e.some((e=>"string"==typeof t?e[i]===t.trim():e[i]===t)))(e,t);this.config.maxItemCount>0&&this.config.maxItemCount<=e.length&&(i=!1,s="function"==typeof this.config.maxItemText?this.config.maxItemText(this.config.maxItemCount):this.config.maxItemText),!this.config.duplicateItemsAllowed&&n&&i&&(i=!1,s="function"==typeof this.config.uniqueItemText?this.config.uniqueItemText(t):this.config.uniqueItemText),this._isTextElement&&this.config.addItems&&i&&"function"==typeof this.config.addItemFilter&&!this.config.addItemFilter(t)&&(i=!1,s="function"==typeof this.config.customAddItemText?this.config.customAddItemText(t):this.config.customAddItemText)}return{response:i,notice:s}}_searchChoices(e){const t="string"==typeof e?e.trim():e,i="string"==typeof this._currentValue?this._currentValue.trim():this._currentValue;if(t.length<1&&t===`${i} `)return 0;const s=this._store.searchableChoices,n=t,r=Object.assign(this.config.fuseOptions,{keys:[...this.config.searchFields],includeMatches:!0}),o=new X(s,r).search(n);return this._currentValue=t,this._highlightPosition=0,this._isSearching=!0,this._store.dispatch((e=>({type:Q.FILTER_CHOICES,results:e}))(o)),o.length}_addEventListeners(){const{documentElement:e}=document;e.addEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.addEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(this.containerOuter.element.addEventListener("focus",this._onFocus,{passive:!0}),this.containerOuter.element.addEventListener("blur",this._onBlur,{passive:!0})),this.input.element.addEventListener("keyup",this._onKeyUp,{passive:!0}),this.input.element.addEventListener("focus",this._onFocus,{passive:!0}),this.input.element.addEventListener("blur",this._onBlur,{passive:!0}),this.input.element.form&&this.input.element.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()}_removeEventListeners(){const{documentElement:e}=document;e.removeEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.removeEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(this.containerOuter.element.removeEventListener("focus",this._onFocus),this.containerOuter.element.removeEventListener("blur",this._onBlur)),this.input.element.removeEventListener("keyup",this._onKeyUp),this.input.element.removeEventListener("focus",this._onFocus),this.input.element.removeEventListener("blur",this._onBlur),this.input.element.form&&this.input.element.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()}_onKeyDown(e){const{keyCode:t}=e,{activeItems:i}=this._store,s=this.input.isFocussed,n=this.dropdown.isActive,r=this.itemList.hasChildren(),o=String.fromCharCode(t),c=/[a-zA-Z0-9-_ ]/.test(o),{BACK_KEY:a,DELETE_KEY:l,ENTER_KEY:h,A_KEY:d,ESC_KEY:u,UP_KEY:m,DOWN_KEY:p,PAGE_UP_KEY:g,PAGE_DOWN_KEY:f}=Z;switch(this._isTextElement||n||!c||(this.showDropdown(),this.input.isFocussed||(this.input.value+=o.toLowerCase())),t){case d:return this._onSelectKey(e,r);case h:return this._onEnterKey(e,i,n);case u:return this._onEscapeKey(n);case m:case g:case p:case f:return this._onDirectionKey(e,n);case l:case a:return this._onDeleteKey(e,i,s)}}_onKeyUp({target:e,keyCode:t}){const{value:i}=this.input,{activeItems:s}=this._store,n=this._canAddItem(s,i),{BACK_KEY:r,DELETE_KEY:o}=Z;if(this._isTextElement){if(n.notice&&i){const e=this._getTemplate("notice",n.notice);this.dropdown.element.innerHTML=e.outerHTML,this.showDropdown(!0)}else this.hideDropdown(!0)}else{const i=(t===r||t===o)&&e&&!e.value,s=!this._isTextElement&&this._isSearching,c=this._canSearch&&n.response;i&&s?(this._isSearching=!1,this._store.dispatch(ne(!0))):c&&this._handleSearch(this.input.rawValue)}this._canSearch=this.config.searchEnabled}_onSelectKey(e,t){const{ctrlKey:i,metaKey:s}=e;if((i||s)&&t){this._canSearch=!1;this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll()}}_onEnterKey(e,t,i){const{target:s}=e,{ENTER_KEY:n}=Z,r=s&&s.hasAttribute("data-button");if(this._isTextElement&&s&&s.value){const{value:e}=this.input;this._canAddItem(t,e).response&&(this.hideDropdown(!0),this._addItem({value:e}),this._triggerChange(e),this.clearInput())}if(r&&(this._handleButtonAction(t,s),e.preventDefault()),i){const i=this.dropdown.getChild(`.${this.config.classNames.highlightedState}`);i&&(t[0]&&(t[0].keyCode=n),this._handleChoiceAction(t,i)),e.preventDefault()}else this._isSelectOneElement&&(this.showDropdown(),e.preventDefault())}_onEscapeKey(e){e&&(this.hideDropdown(!0),this.containerOuter.focus())}_onDirectionKey(e,t){const{keyCode:i,metaKey:s}=e,{DOWN_KEY:n,PAGE_UP_KEY:r,PAGE_DOWN_KEY:o}=Z;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;const t=i===n||i===o?1:-1,c="[data-choice-selectable]";let a;if(s||i===o||i===r)a=t>0?this.dropdown.element.querySelector(`${c}:last-of-type`):this.dropdown.element.querySelector(c);else{const e=this.dropdown.element.querySelector(`.${this.config.classNames.highlightedState}`);a=e?((e,t,i=1)=>{const s=(i>0?"next":"previous")+"ElementSibling";let n=e[s];for(;n;){if(n.matches(t))return n;n=n[s]}return n})(e,c,t):this.dropdown.element.querySelector(c)}a&&(((e,t,i=1)=>{if(!e)return!1;let s;return s=i>0?t.scrollTop+t.offsetHeight>=e.offsetTop+e.offsetHeight:e.offsetTop>=t.scrollTop,s})(a,this.choiceList.element,t)||this.choiceList.scrollToChildElement(a,t),this._highlightChoice(a)),e.preventDefault()}}_onDeleteKey(e,t,i){const{target:s}=e;this._isSelectOneElement||s.value||!i||(this._handleBackspace(t),e.preventDefault())}_onTouchMove(){this._wasTap&&(this._wasTap=!1)}_onTouchEnd(e){const{target:t}=e||e.touches[0];if(this._wasTap&&this.containerOuter.element.contains(t)){(t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation()}this._wasTap=!0}_onMouseDown(e){const{target:t}=e;if(!(t instanceof HTMLElement))return;if(Re&&this.choiceList.element.contains(t)){const t=this.choiceList.element.firstElementChild,i="ltr"===this._direction?e.offsetX>=t.offsetWidth:e.offsetX<t.offsetLeft;this._isScrollingOnIe=i}if(t===this.input.element)return;const i=t.closest("[data-button],[data-item],[data-choice]");if(i instanceof HTMLElement){const t=e.shiftKey,{activeItems:s}=this._store,{dataset:n}=i;"button"in n?this._handleButtonAction(s,i):"item"in n?this._handleItemAction(s,i,t):"choice"in n&&this._handleChoiceAction(s,i)}e.preventDefault()}_onMouseOver({target:e}){e instanceof HTMLElement&&"choice"in e.dataset&&this._highlightChoice(e)}_onClick({target:e}){if(this.containerOuter.element.contains(e))this.dropdown.isActive||this.containerOuter.isDisabled?this._isSelectOneElement&&e!==this.input.element&&!this.dropdown.element.contains(e)&&this.hideDropdown():this._isTextElement?document.activeElement!==this.input.element&&this.input.focus():(this.showDropdown(),this.containerOuter.focus());else{this._store.highlightedActiveItems.length>0&&this.unhighlightAll(),this.containerOuter.removeFocusState(),this.hideDropdown(!0)}}_onFocus({target:e}){if(!(e&&this.containerOuter.element.contains(e)))return;({text:()=>{e===this.input.element&&this.containerOuter.addFocusState()},"select-one":()=>{this.containerOuter.addFocusState(),e===this.input.element&&this.showDropdown(!0)},"select-multiple":()=>{e===this.input.element&&(this.showDropdown(!0),this.containerOuter.addFocusState())}})[this.passedElement.element.type]()}_onBlur({target:e}){if(e&&this.containerOuter.element.contains(e)&&!this._isScrollingOnIe){const{activeItems:t}=this._store,i=t.some((e=>e.highlighted));({text:()=>{e===this.input.element&&(this.containerOuter.removeFocusState(),i&&this.unhighlightAll(),this.hideDropdown(!0))},"select-one":()=>{this.containerOuter.removeFocusState(),(e===this.input.element||e===this.containerOuter.element&&!this._canSearch)&&this.hideDropdown(!0)},"select-multiple":()=>{e===this.input.element&&(this.containerOuter.removeFocusState(),this.hideDropdown(!0),i&&this.unhighlightAll())}})[this.passedElement.element.type]()}else this._isScrollingOnIe=!1,this.input.element.focus()}_onFormReset(){var e;this._store.dispatch((e=this._initialState,{type:Q.RESET_TO,state:e}))}_highlightChoice(e=null){const t=Array.from(this.dropdown.element.querySelectorAll("[data-choice-selectable]"));if(!t.length)return;let i=e;Array.from(this.dropdown.element.querySelectorAll(`.${this.config.classNames.highlightedState}`)).forEach((e=>{e.classList.remove(this.config.classNames.highlightedState),e.setAttribute("aria-selected","false")})),i?this._highlightPosition=t.indexOf(i):(i=t.length>this._highlightPosition?t[this._highlightPosition]:t[t.length-1],i||(i=t[0])),i.classList.add(this.config.classNames.highlightedState),i.setAttribute("aria-selected","true"),this.passedElement.triggerEvent(J.highlightChoice,{el:i}),this.dropdown.isActive&&(this.input.setActiveDescendant(i.id),this.containerOuter.setActiveDescendant(i.id))}_addItem({value:e,label:t=null,choiceId:i=-1,groupId:s=-1,customProperties:n={},placeholder:r=!1,keyCode:o=-1}){let c="string"==typeof e?e.trim():e;const{items:a}=this._store,l=t||c,h=i||-1,d=s>=0?this._store.getGroupById(s):null,u=a?a.length+1:1;this.config.prependValue&&(c=this.config.prependValue+c.toString()),this.config.appendValue&&(c+=this.config.appendValue.toString()),this._store.dispatch((({value:e,label:t,id:i,choiceId:s,groupId:n,customProperties:r,placeholder:o,keyCode:c})=>({type:Q.ADD_ITEM,value:e,label:t,id:i,choiceId:s,groupId:n,customProperties:r,placeholder:o,keyCode:c}))({value:c,label:l,id:u,choiceId:h,groupId:s,customProperties:n,placeholder:r,keyCode:o})),this._isSelectOneElement&&this.removeActiveItems(u),this.passedElement.triggerEvent(J.addItem,{id:u,value:c,label:l,customProperties:n,groupValue:d&&d.value?d.value:null,keyCode:o})}_removeItem(e){const{id:t,value:i,label:s,customProperties:n,choiceId:r,groupId:o}=e,c=o&&o>=0?this._store.getGroupById(o):null;t&&r&&(this._store.dispatch(((e,t)=>({type:Q.REMOVE_ITEM,id:e,choiceId:t}))(t,r)),this.passedElement.triggerEvent(J.removeItem,{id:t,value:i,label:s,customProperties:n,groupValue:c&&c.value?c.value:null}))}_addChoice({value:e,label:t=null,isSelected:i=!1,isDisabled:s=!1,groupId:n=-1,customProperties:r={},placeholder:o=!1,keyCode:c=-1}){if(null==e)return;const{choices:a}=this._store,l=t||e,h=a?a.length+1:1,d=`${this._baseId}-${this._idNames.itemChoice}-${h}`;this._store.dispatch((({value:e,label:t,id:i,groupId:s,disabled:n,elementId:r,customProperties:o,placeholder:c,keyCode:a})=>({type:Q.ADD_CHOICE,value:e,label:t,id:i,groupId:s,disabled:n,elementId:r,customProperties:o,placeholder:c,keyCode:a}))({id:h,groupId:n,elementId:d,value:e,label:l,disabled:s,customProperties:r,placeholder:o,keyCode:c})),i&&this._addItem({value:e,label:l,choiceId:h,customProperties:r,placeholder:o,keyCode:c})}_addGroup({group:e,id:t,valueKey:i="value",labelKey:s="label"}){const n=de("Object",e)?e.choices:Array.from(e.getElementsByTagName("OPTION")),r=t||Math.floor((new Date).valueOf()*Math.random()),o=!!e.disabled&&e.disabled;if(n){this._store.dispatch(re({value:e.label,id:r,active:!0,disabled:o}));const t=e=>{const t=e.disabled||e.parentNode&&e.parentNode.disabled;this._addChoice({value:e[i],label:de("Object",e)?e[s]:e.innerHTML,isSelected:e.selected,isDisabled:t,groupId:r,customProperties:e.customProperties,placeholder:e.placeholder})};n.forEach(t)}else this._store.dispatch(re({value:e.label,id:e.id,active:!1,disabled:e.disabled}))}_getTemplate(e,...t){return this._templates[e].call(this,this.config,...t)}_createTemplates(){const{callbackOnCreateTemplates:e}=this.config;let t={};e&&"function"==typeof e&&(t=e.call(this,me)),this._templates=a(ke,t)}_createElements(){this.containerOuter=new ge({element:this._getTemplate("containerOuter",this._direction,this._isSelectElement,this._isSelectOneElement,this.config.searchEnabled,this.passedElement.element.type),classNames:this.config.classNames,type:this.passedElement.element.type,position:this.config.position}),this.containerInner=new ge({element:this._getTemplate("containerInner"),classNames:this.config.classNames,type:this.passedElement.element.type,position:this.config.position}),this.input=new fe({element:this._getTemplate("input",this._placeholderValue),classNames:this.config.classNames,type:this.passedElement.element.type,preventPaste:!this.config.paste}),this.choiceList=new _e({element:this._getTemplate("choiceList",this._isSelectOneElement)}),this.itemList=new _e({element:this._getTemplate("itemList",this._isSelectOneElement)}),this.dropdown=new ae({element:this._getTemplate("dropdown"),classNames:this.config.classNames,type:this.passedElement.element.type})}_createStructure(){this.passedElement.conceal(),this.containerInner.wrap(this.passedElement.element),this.containerOuter.wrap(this.containerInner.element),this._isSelectOneElement?this.input.placeholder=this.config.searchPlaceholderValue||"":this._placeholderValue&&(this.input.placeholder=this._placeholderValue,this.input.setWidth()),this.containerOuter.element.appendChild(this.containerInner.element),this.containerOuter.element.appendChild(this.dropdown.element),this.containerInner.element.appendChild(this.itemList.element),this._isTextElement||this.dropdown.element.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&this.dropdown.element.insertBefore(this.input.element,this.dropdown.element.firstChild):this.containerInner.element.appendChild(this.input.element),this._isSelectElement&&(this._highlightPosition=0,this._isSearching=!1,this._startLoading(),this._presetGroups.length?this._addPredefinedGroups(this._presetGroups):this._addPredefinedChoices(this._presetChoices),this._stopLoading()),this._isTextElement&&this._addPredefinedItems(this._presetItems)}_addPredefinedGroups(e){const t=this.passedElement.placeholderOption;t&&t.parentNode&&"SELECT"===t.parentNode.tagName&&this._addChoice({value:t.value,label:t.innerHTML,isSelected:t.selected,isDisabled:t.disabled,placeholder:!0}),e.forEach((e=>this._addGroup({group:e,id:e.id||null})))}_addPredefinedChoices(e){this.config.shouldSort&&e.sort(this.config.sorter);const t=e.some((e=>e.selected)),i=e.findIndex((e=>void 0===e.disabled||!e.disabled));e.forEach(((e,s)=>{const{value:n="",label:r,customProperties:o,placeholder:c}=e;if(this._isSelectElement)if(e.choices)this._addGroup({group:e,id:e.id||null});else{const a=!!(this._isSelectOneElement&&!t&&s===i)||e.selected,l=e.disabled;this._addChoice({value:n,label:r,isSelected:!!a,isDisabled:!!l,placeholder:!!c,customProperties:o})}else this._addChoice({value:n,label:r,isSelected:!!e.selected,isDisabled:!!e.disabled,placeholder:!!e.placeholder,customProperties:o})}))}_addPredefinedItems(e){e.forEach((e=>{"object"==typeof e&&e.value&&this._addItem({value:e.value,label:e.label,choiceId:e.id,customProperties:e.customProperties,placeholder:e.placeholder}),"string"==typeof e&&this._addItem({value:e})}))}_setChoiceOrItem(e){({object:()=>{e.value&&(this._isTextElement?this._addItem({value:e.value,label:e.label,choiceId:e.id,customProperties:e.customProperties,placeholder:e.placeholder}):this._addChoice({value:e.value,label:e.label,isSelected:!0,isDisabled:!1,customProperties:e.customProperties,placeholder:e.placeholder}))},string:()=>{this._isTextElement?this._addItem({value:e}):this._addChoice({value:e,label:e,isSelected:!0,isDisabled:!1})}})[he(e).toLowerCase()]()}_findAndSelectChoiceByValue(e){const{choices:t}=this._store,i=t.find((t=>this.config.valueComparer(t.value,e)));i&&!i.selected&&this._addItem({value:i.value,label:i.label,choiceId:i.id,groupId:i.groupId,customProperties:i.customProperties,placeholder:i.placeholder,keyCode:i.keyCode})}_generatePlaceholderValue(){if(this._isSelectElement&&this.passedElement.placeholderOption){const{placeholderOption:e}=this.passedElement;return e?e.text:null}const{placeholder:e,placeholderValue:t}=this.config,{element:{dataset:i}}=this.passedElement;if(e){if(t)return t;if(i.placeholder)return i.placeholder}return null}}export{Q as ACTION_TYPES,ye as DEFAULT_CLASSNAMES,Ie as DEFAULT_CONFIG,J as EVENTS,Z as KEY_CODES,se as SCROLLING_SPEED,ie as SELECT_MULTIPLE_TYPE,te as SELECT_ONE_TYPE,ee as TEXT_TYPE,He as default,ke as templates};
