var e="undefined"!==typeof globalThis?globalThis:"undefined"!==typeof self?self:global;var t={};(function(e,s){t=s()})(0,(function(){function forEvents(e,t){e.split(/\s+/).forEach((e=>{t(e)}))}class MicroEvent{constructor(){this._events=void 0;this._events={}}on(e,t){forEvents(e,(e=>{const s=this._events[e]||[];s.push(t);this._events[e]=s}))}off(e,t){var s=arguments.length;0!==s?forEvents(e,(e=>{if(1===s){delete this._events[e];return}const i=this._events[e];if(void 0!==i){i.splice(i.indexOf(t),1);this._events[e]=i}})):this._events={}}trigger(e,...t){var s=this;forEvents(e,(e=>{const i=s._events[e];void 0!==i&&i.forEach((e=>{e.apply(s,t)}))}))}}function MicroPlugin(e){e.plugins={};return class extends e{constructor(...e){super(...e);this.plugins={names:[],settings:{},requested:{},loaded:{}}}
/**
       * Registers a plugin.
       *
       * @param {function} fn
       */static define(t,s){e.plugins[t]={name:t,fn:s}}
/**
       * Initializes the listed plugins (with options).
       * Acceptable formats:
       *
       * List (without options):
       *   ['a', 'b', 'c']
       *
       * List (with options):
       *   [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
       *
       * Hash (with options):
       *   {'a': { ... }, 'b': { ... }, 'c': { ... }}
       *
       * @param {array|object} plugins
       */initializePlugins(e){var t,s;const i=this;const n=[];if(Array.isArray(e))e.forEach((e=>{if("string"===typeof e)n.push(e);else{i.plugins.settings[e.name]=e.options;n.push(e.name)}}));else if(e)for(t in e)if(e.hasOwnProperty(t)){i.plugins.settings[t]=e[t];n.push(t)}while(s=n.shift())i.require(s)}loadPlugin(t){var s=this;var i=s.plugins;var n=e.plugins[t];if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin');i.requested[t]=true;i.loaded[t]=n.fn.apply(s,[s.plugins.settings[t]||{}]);i.names.push(t)}require(e){var t=this;var s=t.plugins;if(!t.plugins.loaded.hasOwnProperty(e)){if(s.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")');t.loadPlugin(e)}return s.loaded[e]}}}
/**
   * Convert array of strings to a regular expression
   *	ex ['ab','a'] => (?:ab|a)
   * 	ex ['a','b'] => [ab]
   * @param {string[]} chars
   * @return {string}
   */const arrayToPattern=e=>{e=e.filter(Boolean);return e.length<2?e[0]||"":1==maxValueLength(e)?"["+e.join("")+"]":"(?:"+e.join("|")+")"};
/**
   * @param {string[]} array
   * @return {string}
   */const sequencePattern=e=>{if(!hasDuplicates(e))return e.join("");let t="";let s=0;const prev_pattern=()=>{s>1&&(t+="{"+s+"}")};e.forEach(((i,n)=>{if(i!==e[n-1]){prev_pattern();t+=i;s=1}else s++}));prev_pattern();return t};
/**
   * Convert array of strings to a regular expression
   *	ex ['ab','a'] => (?:ab|a)
   * 	ex ['a','b'] => [ab]
   * @param {Set<string>} chars
   * @return {string}
   */const setToPattern=e=>{let t=toArray(e);return arrayToPattern(t)};
/**
   *
   * https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values
   * @param {any[]} array
   */const hasDuplicates=e=>new Set(e).size!==e.length;
/**
   * https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error
   * @param {string} str
   * @return {string}
   */const escape_regex=e=>(e+"").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu,"\\$1");
/**
   * Return the max length of array values
   * @param {string[]} array
   *
   */const maxValueLength=e=>e.reduce(((e,t)=>Math.max(e,unicodeLength(t))),0);
/**
   * @param {string} str
   */const unicodeLength=e=>toArray(e).length;
/**
   * @param {any} p
   * @return {any[]}
   */const toArray=e=>Array.from(e)
/**
   * Get all possible combinations of substrings that add up to the given string
   * https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string
   * @param {string} input
   * @return {string[][]}
   */;const allSubstrings=e=>{if(1===e.length)return[[e]];
/** @type {string[][]} */let t=[];const s=e.substring(1);const i=allSubstrings(s);i.forEach((function(s){let i=s.slice(0);i[0]=e.charAt(0)+i[0];t.push(i);i=s.slice(0);i.unshift(e.charAt(0));t.push(i)}));return t};
/**
   * @typedef {{[key:string]:string}} TUnicodeMap
   * @typedef {{[key:string]:Set<string>}} TUnicodeSets
   * @typedef {[[number,number]]} TCodePoints
   * @typedef {{folded:string,composed:string,code_point:number}} TCodePointObj
   * @typedef {{start:number,end:number,length:number,substr:string}} TSequencePart
   */
/** @type {TCodePoints} */const t=[[0,65535]];const s="[̀-ͯ·ʾʼ]";
/** @type {TUnicodeMap} */let i;
/** @type {RegExp} */let n;const o=3;
/** @type {TUnicodeMap} */const r={};
/** @type {TUnicodeMap} */const l={"/":"⁄∕",0:"߀",a:"ⱥɐɑ",aa:"ꜳ",ae:"æǽǣ",ao:"ꜵ",au:"ꜷ",av:"ꜹꜻ",ay:"ꜽ",b:"ƀɓƃ",c:"ꜿƈȼↄ",d:"đɗɖᴅƌꮷԁɦ",e:"ɛǝᴇɇ",f:"ꝼƒ",g:"ǥɠꞡᵹꝿɢ",h:"ħⱨⱶɥ",i:"ɨı",j:"ɉȷ",k:"ƙⱪꝁꝃꝅꞣ",l:"łƚɫⱡꝉꝇꞁɭ",m:"ɱɯϻ",n:"ꞥƞɲꞑᴎлԉ",o:"øǿɔɵꝋꝍᴑ",oe:"œ",oi:"ƣ",oo:"ꝏ",ou:"ȣ",p:"ƥᵽꝑꝓꝕρ",q:"ꝗꝙɋ",r:"ɍɽꝛꞧꞃ",s:"ßȿꞩꞅʂ",t:"ŧƭʈⱦꞇ",th:"þ",tz:"ꜩ",u:"ʉ",v:"ʋꝟʌ",vy:"ꝡ",w:"ⱳ",y:"ƴɏỿ",z:"ƶȥɀⱬꝣ",hv:"ƕ"};for(let e in l){let t=l[e]||"";for(let s=0;s<t.length;s++){let i=t.substring(s,s+1);r[i]=e}}const a=new RegExp(Object.keys(r).join("|")+"|"+s,"gu");
/**
   * Initialize the unicode_map from the give code point ranges
   *
   * @param {TCodePoints=} _code_points
   */const initialize=e=>{void 0===i&&(i=generateMap(e||t))};
/**
   * Helper method for normalize a string
   * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
   * @param {string} str
   * @param {string} form
   */const normalize=(e,t="NFKD")=>e.normalize(t)
/**
   * Remove accents without reordering string
   * calling str.normalize('NFKD') on \u{594}\u{595}\u{596} becomes \u{596}\u{594}\u{595}
   * via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703
   * @param {string} str
   * @return {string}
   */;const asciifold=e=>toArray(e).reduce((
/**
     * @param {string} result
     * @param {string} char
     */
(e,t)=>e+_asciifold(t)),"");
/**
   * @param {string} str
   * @return {string}
   */const _asciifold=e=>{e=normalize(e).toLowerCase().replace(a,(/** @type {string} */
e=>r[e]||""));return normalize(e,"NFC")};
/**
   * Generate a list of unicode variants from the list of code points
   * @param {TCodePoints} code_points
   * @yield {TCodePointObj}
   */function*generator(e){for(const[t,s]of e)for(let e=t;e<=s;e++){let t=String.fromCharCode(e);let s=asciifold(t);s!=t.toLowerCase()&&(s.length>o||0!=s.length&&(yield{folded:s,composed:t,code_point:e}))}}
/**
   * Generate a unicode map from the list of code points
   * @param {TCodePoints} code_points
   * @return {TUnicodeSets}
   */const generateSets=e=>{
/** @type {{[key:string]:Set<string>}} */
const t={};
/**
     * @param {string} folded
     * @param {string} to_add
     */const addMatching=(e,s)=>{
/** @type {Set<string>} */
const i=t[e]||new Set;const n=new RegExp("^"+setToPattern(i)+"$","iu");if(!s.match(n)){i.add(escape_regex(s));t[e]=i}};for(let t of generator(e)){addMatching(t.folded,t.folded);addMatching(t.folded,t.composed)}return t};
/**
   * Generate a unicode map from the list of code points
   * ae => (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|Ａ...)(?:E|ɛ|Ⓔ...))
   *
   * @param {TCodePoints} code_points
   * @return {TUnicodeMap}
   */const generateMap=e=>{
/** @type {TUnicodeSets} */
const t=generateSets(e);
/** @type {TUnicodeMap} */const s={};
/** @type {string[]} */let i=[];for(let e in t){let n=t[e];n&&(s[e]=setToPattern(n));e.length>1&&i.push(escape_regex(e))}i.sort(((e,t)=>t.length-e.length));const o=arrayToPattern(i);n=new RegExp("^"+o,"u");return s};
/**
   * Map each element of an array from it's folded value to all possible unicode matches
   * @param {string[]} strings
   * @param {number} min_replacement
   * @return {string}
   */const mapSequence=(e,t=1)=>{let s=0;e=e.map((e=>{i[e]&&(s+=e.length);return i[e]||e}));return s>=t?sequencePattern(e):""};
/**
   * Convert a short string and split it into all possible patterns
   * Keep a pattern only if min_replacement is met
   *
   * 'abc'
   * 		=> [['abc'],['ab','c'],['a','bc'],['a','b','c']]
   *		=> ['abc-pattern','ab-c-pattern'...]
   *
   *
   * @param {string} str
   * @param {number} min_replacement
   * @return {string}
   */const substringsToPattern=(e,t=1)=>{t=Math.max(t,e.length-1);return arrayToPattern(allSubstrings(e).map((e=>mapSequence(e,t))))};
/**
   * Convert an array of sequences into a pattern
   * [{start:0,end:3,length:3,substr:'iii'}...] => (?:iii...)
   *
   * @param {Sequence[]} sequences
   * @param {boolean} all
   */const sequencesToPattern=(e,t=true)=>{let s=e.length>1?1:0;return arrayToPattern(e.map((e=>{let i=[];const n=t?e.length():e.length()-1;for(let t=0;t<n;t++)i.push(substringsToPattern(e.substrs[t]||"",s));return sequencePattern(i)})))};
/**
   * Return true if the sequence is already in the sequences
   * @param {Sequence} needle_seq
   * @param {Sequence[]} sequences
   */const inSequences=(e,t)=>{for(const s of t){if(s.start!=e.start||s.end!=e.end)continue;if(s.substrs.join("")!==e.substrs.join(""))continue;let t=e.parts;
/**
       * @param {TSequencePart} part
       */const filter=e=>{for(const s of t){if(s.start===e.start&&s.substr===e.substr)return false;if(1!=e.length&&1!=s.length){if(e.start<s.start&&e.end>s.start)return true;if(s.start<e.start&&s.end>e.start)return true}}return false};let i=s.parts.filter(filter);if(!(i.length>0))return true}return false};class Sequence{constructor(){
/** @type {TSequencePart[]} */
this.parts=[];
/** @type {string[]} */this.substrs=[];this.start=0;this.end=0}
/**
     * @param {TSequencePart|undefined} part
     */add(e){if(e){this.parts.push(e);this.substrs.push(e.substr);this.start=Math.min(e.start,this.start);this.end=Math.max(e.end,this.end)}}last(){return this.parts[this.parts.length-1]}length(){return this.parts.length}
/**
     * @param {number} position
     * @param {TSequencePart} last_piece
     */clone(e,t){let s=new Sequence;let i=JSON.parse(JSON.stringify(this.parts));let n=i.pop();for(const e of i)s.add(e);let o=t.substr.substring(0,e-n.start);let r=o.length;s.add({start:n.start,end:n.start+r,length:r,substr:o});return s}}
/**
   * Expand a regular expression pattern to include unicode variants
   * 	eg /a/ becomes /aⓐａẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶＡÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/
   *
   * Issue:
   *  ﺊﺋ [ 'ﺊ = \\u{fe8a}', 'ﺋ = \\u{fe8b}' ]
   *	becomes:	ئئ [ 'ي = \\u{64a}', 'ٔ = \\u{654}', 'ي = \\u{64a}', 'ٔ = \\u{654}' ]
   *
   *	İĲ = IIJ = ⅡJ
   *
   * 	1/2/4
   *
   * @param {string} str
   * @return {string|undefined}
   */const getPattern=e=>{initialize();e=asciifold(e);let t="";let s=[new Sequence];for(let i=0;i<e.length;i++){let o=e.substring(i);let r=o.match(n);const l=e.substring(i,i+1);const a=r?r[0]:null;let c=[];let d=new Set;for(const e of s){const t=e.last();if(!t||1==t.length||t.end<=i)if(a){const t=a.length;e.add({start:i,end:i+t,length:t,substr:a});d.add("1")}else{e.add({start:i,end:i+1,length:1,substr:l});d.add("2")}else if(a){let s=e.clone(i,t);const n=a.length;s.add({start:i,end:i+n,length:n,substr:a});c.push(s)}else d.add("3")}if(c.length>0){c=c.sort(((e,t)=>e.length()-t.length()));for(let e of c)inSequences(e,s)||s.push(e)}else if(i>0&&1==d.size&&!d.has("3")){t+=sequencesToPattern(s,false);let e=new Sequence;const i=s[0];i&&e.add(i.last());s=[e]}}t+=sequencesToPattern(s,true);return t};
/**
   * A property getter resolving dot-notation
   * @param  {Object}  obj     The root object to fetch property on
   * @param  {String}  name    The optionally dotted property name to fetch
   * @return {Object}          The resolved property value
   */const getAttr=(e,t)=>{if(e)return e[t]};
/**
   * A property getter resolving dot-notation
   * @param  {Object}  obj     The root object to fetch property on
   * @param  {String}  name    The optionally dotted property name to fetch
   * @return {Object}          The resolved property value
   */const getAttrNesting=(e,t)=>{if(e){var s,i=t.split(".");while((s=i.shift())&&(e=e[s]));return e}};const scoreValue=(e,t,s)=>{var i,n;if(!e)return 0;e+="";if(null==t.regex)return 0;n=e.search(t.regex);if(-1===n)return 0;i=t.string.length/e.length;0===n&&(i+=.5);return i*s};const propToArray=(e,t)=>{var s=e[t];if("function"==typeof s)return s;s&&!Array.isArray(s)&&(e[t]=[s])};const iterate$1=(e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s],s)};const cmp=(e,t)=>{if("number"===typeof e&&"number"===typeof t)return e>t?1:e<t?-1:0;e=asciifold(e+"").toLowerCase();t=asciifold(t+"").toLowerCase();return e>t?1:t>e?-1:0};class Sifter{constructor(e,t){this.items=void 0;this.settings=void 0;this.items=e;this.settings=t||{diacritics:true}}tokenize(e,t,s){if(!e||!e.length)return[];const i=[];const n=e.split(/\s+/);var o;s&&(o=new RegExp("^("+Object.keys(s).map(escape_regex).join("|")+"):(.*)$"));n.forEach((e=>{let s;let n=null;let r=null;if(o&&(s=e.match(o))){n=s[1];e=s[2]}if(e.length>0){r=this.settings.diacritics?getPattern(e)||null:escape_regex(e);r&&t&&(r="\\b"+r)}i.push({string:e,regex:r?new RegExp(r,"iu"):null,field:n})}));return i}
/**
     * Returns a function to be used to score individual results.
     *
     * Good matches will have a higher score than poor matches.
     * If an item is not a match, 0 will be returned by the function.
     *
     * @returns {T.ScoreFn}
     */getScoreFunction(e,t){var s=this.prepareSearch(e,t);return this._getScoreFunction(s)}
/**
     * @returns {T.ScoreFn}
     *
     */_getScoreFunction(e){const t=e.tokens,s=t.length;if(!s)return function(){return 0};const i=e.options.fields,n=e.weights,o=i.length,r=e.getAttrFn;if(!o)return function(){return 1};const l=function(){return 1===o?function(e,t){const s=i[0].field;return scoreValue(r(t,s),e,n[s]||1)}:function(e,t){var s=0;if(e.field){const i=r(t,e.field);!e.regex&&i?s+=1/o:s+=scoreValue(i,e,1)}else iterate$1(n,((i,n)=>{s+=scoreValue(r(t,n),e,i)}));return s/o}}();return 1===s?function(e){return l(t[0],e)}:"and"===e.options.conjunction?function(e){var i,n=0;for(let s of t){i=l(s,e);if(i<=0)return 0;n+=i}return n/s}:function(e){var i=0;iterate$1(t,(t=>{i+=l(t,e)}));return i/s}}getSortFunction(e,t){var s=this.prepareSearch(e,t);return this._getSortFunction(s)}_getSortFunction(e){var t,s=[];const i=this,n=e.options,o=!e.query&&n.sort_empty?n.sort_empty:n.sort;if("function"==typeof o)return o.bind(this);const r=function get_field(t,s){return"$score"===t?s.score:e.getAttrFn(i.items[s.id],t)};if(o)for(let t of o)(e.query||"$score"!==t.field)&&s.push(t);if(e.query){t=true;for(let e of s)if("$score"===e.field){t=false;break}t&&s.unshift({field:"$score",direction:"desc"})}else s=s.filter((e=>"$score"!==e.field));const l=s.length;return l?function(e,t){var i,n;for(let o of s){n=o.field;let s="desc"===o.direction?-1:1;i=s*cmp(r(n,e),r(n,t));if(i)return i}return 0}:null}prepareSearch(e,t){const s={};var i=Object.assign({},t);propToArray(i,"sort");propToArray(i,"sort_empty");if(i.fields){propToArray(i,"fields");const e=[];i.fields.forEach((t=>{"string"==typeof t&&(t={field:t,weight:1});e.push(t);s[t.field]="weight"in t?t.weight:1}));i.fields=e}return{options:i,query:e.toLowerCase().trim(),tokens:this.tokenize(e,i.respect_word_boundaries,s),total:0,items:[],weights:s,getAttrFn:i.nesting?getAttrNesting:getAttr}}search(e,t){var s,i,n=this;i=this.prepareSearch(e,t);t=i.options;e=i.query;const o=t.score||n._getScoreFunction(i);e.length?iterate$1(n.items,((e,n)=>{s=o(e);(false===t.filter||s>0)&&i.items.push({score:s,id:n})})):iterate$1(n.items,((e,t)=>{i.items.push({score:1,id:t})}));const r=n._getSortFunction(i);r&&i.items.sort(r);i.total=i.items.length;"number"===typeof t.limit&&(i.items=i.items.slice(0,t.limit));return i}}const iterate=(e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s],s)};const getDom=e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if(isHtmlString(e)){var t=document.createElement("template");t.innerHTML=e.trim();return t.content.firstChild}return document.querySelector(e)};const isHtmlString=e=>"string"===typeof e&&e.indexOf("<")>-1;const escapeQuery=e=>e.replace(/['"\\]/g,"\\$&");const triggerEvent=(e,t)=>{var s=document.createEvent("HTMLEvents");s.initEvent(t,true,false);e.dispatchEvent(s)};const applyCSS=(e,t)=>{Object.assign(e.style,t)};const addClasses=(e,...t)=>{var s=classesArray(t);e=castAsArray(e);e.map((e=>{s.map((t=>{e.classList.add(t)}))}))};const removeClasses=(e,...t)=>{var s=classesArray(t);e=castAsArray(e);e.map((e=>{s.map((t=>{e.classList.remove(t)}))}))};const classesArray=e=>{var t=[];iterate(e,(e=>{"string"===typeof e&&(e=e.trim().split(/[\11\12\14\15\40]/));Array.isArray(e)&&(t=t.concat(e))}));return t.filter(Boolean)};const castAsArray=e=>{Array.isArray(e)||(e=[e]);return e};const parentMatch=(e,t,s)=>{if(!s||s.contains(e))while(e&&e.matches){if(e.matches(t))return e;e=e.parentNode}};const getTail=(e,t=0)=>t>0?e[e.length-1]:e[0];const isEmptyObject=e=>0===Object.keys(e).length;const nodeIndex=(e,t)=>{if(!e)return-1;t=t||e.nodeName;var s=0;while(e=e.previousElementSibling)e.matches(t)&&s++;return s};const setAttr=(e,t)=>{iterate(t,((t,s)=>{null==t?e.removeAttribute(s):e.setAttribute(s,""+t)}))};const replaceNode=(e,t)=>{e.parentNode&&e.parentNode.replaceChild(t,e)};const highlight=(e,t)=>{if(null===t)return;if("string"===typeof t){if(!t.length)return;t=new RegExp(t,"i")}const highlightText=e=>{var s=e.data.match(t);if(s&&e.data.length>0){var i=document.createElement("span");i.className="highlight";var n=e.splitText(s.index);n.splitText(s[0].length);var o=n.cloneNode(true);i.appendChild(o);replaceNode(n,i);return 1}return 0};const highlightChildren=e=>{1!==e.nodeType||!e.childNodes||/(script|style)/i.test(e.tagName)||"highlight"===e.className&&"SPAN"===e.tagName||Array.from(e.childNodes).forEach((e=>{highlightRecursive(e)}))};const highlightRecursive=e=>{if(3===e.nodeType)return highlightText(e);highlightChildren(e);return 0};highlightRecursive(e)};const removeHighlight=e=>{var t=e.querySelectorAll("span.highlight");Array.prototype.forEach.call(t,(function(e){var t=e.parentNode;t.replaceChild(e.firstChild,e);t.normalize()}))};const c=65;const d=13;const u=27;const p=37;const h=38;const g=39;const f=40;const v=8;const m=46;const y=9;const b="undefined"!==typeof navigator&&/Mac/.test(navigator.userAgent);const O=b?"metaKey":"ctrlKey";var _={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:true,diacritics:true,create:null,createOnBlur:false,createFilter:null,highlight:true,openOnFocus:true,shouldOpen:null,maxOptions:50,maxItems:null,hideSelected:null,duplicates:false,addPrecedence:false,selectOnTab:false,preload:null,allowEmptyOption:false,refreshThrottle:300,loadThrottle:300,loadingClass:"loading",dataAttr:null,optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:false,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"ts-wrapper",controlClass:"ts-control",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:'<input type="text" autocomplete="off" size="1" />',copyClassesToDropdown:false,placeholder:null,hidePlaceholder:null,shouldLoad:function(e){return e.length>0},render:{}};const hash_key=e=>"undefined"===typeof e||null===e?null:get_hash(e);const get_hash=e=>"boolean"===typeof e?e?"1":"0":e+"";const escape_html=e=>(e+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");const timeout=(e,t)=>{if(t>0)return setTimeout(e,t);e.call(null);return null};const loadDebounce=(t,s)=>{var i;return function(n,o){var r=this||e;if(i){r.loading=Math.max(r.loading-1,0);clearTimeout(i)}i=setTimeout((function(){i=null;r.loadedSearches[n]=true;t.call(r,n,o)}),s)}};const debounce_events=(e,t,s)=>{var i;var n=e.trigger;var o={};e.trigger=function(){var s=arguments[0];if(-1===t.indexOf(s))return n.apply(e,arguments);o[s]=arguments};s.apply(e,[]);e.trigger=n;for(i of t)i in o&&n.apply(e,o[i])};const getSelection=e=>({start:e.selectionStart||0,length:(e.selectionEnd||0)-(e.selectionStart||0)});const preventDefault=(e,t=false)=>{if(e){e.preventDefault();t&&e.stopPropagation()}};const addEvent=(e,t,s,i)=>{e.addEventListener(t,s,i)};const isKeyDown=(e,t)=>{if(!t)return false;if(!t[e])return false;var s=(t.altKey?1:0)+(t.ctrlKey?1:0)+(t.shiftKey?1:0)+(t.metaKey?1:0);return 1===s};const getId=(e,t)=>{const s=e.getAttribute("id");if(s)return s;e.setAttribute("id",t);return t};const addSlashes=e=>e.replace(/[\\"']/g,"\\$&");const append=(e,t)=>{t&&e.append(t)};function getSettings(e,t){var s=Object.assign({},_,t);var i=s.dataAttr;var n=s.labelField;var o=s.valueField;var r=s.disabledField;var l=s.optgroupField;var a=s.optgroupLabelField;var c=s.optgroupValueField;var d=e.tagName.toLowerCase();var u=e.getAttribute("placeholder")||e.getAttribute("data-placeholder");if(!u&&!s.allowEmptyOption){let t=e.querySelector('option[value=""]');t&&(u=t.textContent)}var p={placeholder:u,options:[],optgroups:[],items:[],maxItems:null};var init_select=()=>{var t;var d=p.options;var u={};var h=1;let g=0;var readData=e=>{var t=Object.assign({},e.dataset);var s=i&&t[i];"string"===typeof s&&s.length&&(t=Object.assign(t,JSON.parse(s)));return t};var addOption=(e,t)=>{var i=hash_key(e.value);if(null!=i&&(i||s.allowEmptyOption)){if(u.hasOwnProperty(i)){if(t){var a=u[i][l];a?Array.isArray(a)?a.push(t):u[i][l]=[a,t]:u[i][l]=t}}else{var c=readData(e);c[n]=c[n]||e.textContent;c[o]=c[o]||i;c[r]=c[r]||e.disabled;c[l]=c[l]||t;c.$option=e;c.$order=c.$order||++g;u[i]=c;d.push(c)}e.selected&&p.items.push(i)}};var addGroup=e=>{var t,s;s=readData(e);s[a]=s[a]||e.getAttribute("label")||"";s[c]=s[c]||h++;s[r]=s[r]||e.disabled;s.$order=s.$order||++g;p.optgroups.push(s);t=s[c];iterate(e.children,(e=>{addOption(e,t)}))};p.maxItems=e.hasAttribute("multiple")?null:1;iterate(e.children,(e=>{t=e.tagName.toLowerCase();"optgroup"===t?addGroup(e):"option"===t&&addOption(e)}))};var init_textbox=()=>{const t=e.getAttribute(i);if(t){p.options=JSON.parse(t);iterate(p.options,(e=>{p.items.push(e[o])}))}else{var r=e.value.trim()||"";if(!s.allowEmptyOption&&!r.length)return;const t=r.split(s.delimiter);iterate(t,(e=>{const t={};t[n]=e;t[o]=e;p.options.push(t)}));p.items=t}};"select"===d?init_select():init_textbox();return Object.assign({},_,p,t)}var w=0;class TomSelect extends(MicroPlugin(MicroEvent)){constructor(e,t){super();this.control_input=void 0;this.wrapper=void 0;this.dropdown=void 0;this.control=void 0;this.dropdown_content=void 0;this.focus_node=void 0;this.order=0;this.settings=void 0;this.input=void 0;this.tabIndex=void 0;this.is_select_tag=void 0;this.rtl=void 0;this.inputId=void 0;this._destroy=void 0;this.sifter=void 0;this.isOpen=false;this.isDisabled=false;this.isReadOnly=false;this.isRequired=void 0;this.isInvalid=false;this.isValid=true;this.isLocked=false;this.isFocused=false;this.isInputHidden=false;this.isSetup=false;this.ignoreFocus=false;this.ignoreHover=false;this.hasOptions=false;this.currentResults=void 0;this.lastValue="";this.caretPos=0;this.loading=0;this.loadedSearches={};this.activeOption=null;this.activeItems=[];this.optgroups={};this.options={};this.userOptions={};this.items=[];this.refreshTimeout=null;w++;var s;var i=getDom(e);if(i.tomselect)throw new Error("Tom Select already initialized on this element");i.tomselect=this;var n=window.getComputedStyle&&window.getComputedStyle(i,null);s=n.getPropertyValue("direction");const o=getSettings(i,t);this.settings=o;this.input=i;this.tabIndex=i.tabIndex||0;this.is_select_tag="select"===i.tagName.toLowerCase();this.rtl=/rtl/i.test(s);this.inputId=getId(i,"tomselect-"+w);this.isRequired=i.required;this.sifter=new Sifter(this.options,{diacritics:o.diacritics});o.mode=o.mode||(1===o.maxItems?"single":"multi");"boolean"!==typeof o.hideSelected&&(o.hideSelected="multi"===o.mode);"boolean"!==typeof o.hidePlaceholder&&(o.hidePlaceholder="multi"!==o.mode);var r=o.createFilter;if("function"!==typeof r){"string"===typeof r&&(r=new RegExp(r));r instanceof RegExp?o.createFilter=e=>r.test(e):o.createFilter=e=>this.settings.duplicates||!this.options[e]}this.initializePlugins(o.plugins);this.setupCallbacks();this.setupTemplates();const l=getDom("<div>");const a=getDom("<div>");const c=this._render("dropdown");const d=getDom('<div role="listbox" tabindex="-1">');const u=this.input.getAttribute("class")||"";const p=o.mode;var h;addClasses(l,o.wrapperClass,u,p);addClasses(a,o.controlClass);append(l,a);addClasses(c,o.dropdownClass,p);o.copyClassesToDropdown&&addClasses(c,u);addClasses(d,o.dropdownContentClass);append(c,d);getDom(o.dropdownParent||l).appendChild(c);if(isHtmlString(o.controlInput)){h=getDom(o.controlInput);var g=["autocorrect","autocapitalize","autocomplete","spellcheck"];iterate$1(g,(e=>{i.getAttribute(e)&&setAttr(h,{[e]:i.getAttribute(e)})}));h.tabIndex=-1;a.appendChild(h);this.focus_node=h}else if(o.controlInput){h=getDom(o.controlInput);this.focus_node=h}else{h=getDom("<input/>");this.focus_node=a}this.wrapper=l;this.dropdown=c;this.dropdown_content=d;this.control=a;this.control_input=h;this.setup()}setup(){const e=this;const t=e.settings;const s=e.control_input;const i=e.dropdown;const n=e.dropdown_content;const o=e.wrapper;const r=e.control;const l=e.input;const a=e.focus_node;const c={passive:true};const d=e.inputId+"-ts-dropdown";setAttr(n,{id:d});setAttr(a,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":d});const u=getId(a,e.inputId+"-ts-control");const p="label[for='"+escapeQuery(e.inputId)+"']";const h=document.querySelector(p);const g=e.focus.bind(e);if(h){addEvent(h,"click",g);setAttr(h,{for:u});const t=getId(h,e.inputId+"-ts-label");setAttr(a,{"aria-labelledby":t});setAttr(n,{"aria-labelledby":t})}o.style.width=l.style.width;if(e.plugins.names.length){const t="plugin-"+e.plugins.names.join(" plugin-");addClasses([o,i],t)}(null===t.maxItems||t.maxItems>1)&&e.is_select_tag&&setAttr(l,{multiple:"multiple"});t.placeholder&&setAttr(s,{placeholder:t.placeholder});!t.splitOn&&t.delimiter&&(t.splitOn=new RegExp("\\s*"+escape_regex(t.delimiter)+"+\\s*"));t.load&&t.loadThrottle&&(t.load=loadDebounce(t.load,t.loadThrottle));addEvent(i,"mousemove",(()=>{e.ignoreHover=false}));addEvent(i,"mouseenter",(t=>{var s=parentMatch(t.target,"[data-selectable]",i);s&&e.onOptionHover(t,s)}),{capture:true});addEvent(i,"click",(t=>{const s=parentMatch(t.target,"[data-selectable]");if(s){e.onOptionSelect(t,s);preventDefault(t,true)}}));addEvent(r,"click",(t=>{var i=parentMatch(t.target,"[data-ts-item]",r);if(i&&e.onItemSelect(t,i))preventDefault(t,true);else if(""==s.value){e.onClick();preventDefault(t,true)}}));addEvent(a,"keydown",(t=>e.onKeyDown(t)));addEvent(s,"keypress",(t=>e.onKeyPress(t)));addEvent(s,"input",(t=>e.onInput(t)));addEvent(a,"blur",(t=>e.onBlur(t)));addEvent(a,"focus",(t=>e.onFocus(t)));addEvent(s,"paste",(t=>e.onPaste(t)));const doc_mousedown=t=>{const n=t.composedPath()[0];if(o.contains(n)||i.contains(n))n==s&&e.isOpen?t.stopPropagation():preventDefault(t,true);else{e.isFocused&&e.blur();e.inputState()}};const win_scroll=()=>{e.isOpen&&e.positionDropdown()};addEvent(document,"mousedown",doc_mousedown);addEvent(window,"scroll",win_scroll,c);addEvent(window,"resize",win_scroll,c);this._destroy=()=>{document.removeEventListener("mousedown",doc_mousedown);window.removeEventListener("scroll",win_scroll);window.removeEventListener("resize",win_scroll);h&&h.removeEventListener("click",g)};this.revertSettings={innerHTML:l.innerHTML,tabIndex:l.tabIndex};l.tabIndex=-1;l.insertAdjacentElement("afterend",e.wrapper);e.sync(false);t.items=[];delete t.optgroups;delete t.options;addEvent(l,"invalid",(()=>{if(e.isValid){e.isValid=false;e.isInvalid=true;e.refreshState()}}));e.updateOriginalInput();e.refreshItems();e.close(false);e.inputState();e.isSetup=true;l.disabled?e.disable():l.readOnly?e.setReadOnly(true):e.enable();e.on("change",this.onChange);addClasses(l,"tomselected","ts-hidden-accessible");e.trigger("initialize");true===t.preload&&e.preload()}setupOptions(e=[],t=[]){this.addOptions(e);iterate$1(t,(e=>{this.registerOptionGroup(e)}))}setupTemplates(){var e=this;var t=e.settings.labelField;var s=e.settings.optgroupLabelField;var i={optgroup:e=>{let t=document.createElement("div");t.className="optgroup";t.appendChild(e.options);return t},optgroup_header:(e,t)=>'<div class="optgroup-header">'+t(e[s])+"</div>",option:(e,s)=>"<div>"+s(e[t])+"</div>",item:(e,s)=>"<div>"+s(e[t])+"</div>",option_create:(e,t)=>'<div class="create">Add <strong>'+t(e.input)+"</strong>&hellip;</div>",no_results:()=>'<div class="no-results">No results found</div>',loading:()=>'<div class="spinner"></div>',not_loading:()=>{},dropdown:()=>"<div></div>"};e.settings.render=Object.assign({},i,e.settings.render)}setupCallbacks(){var e,t;var s={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",item_select:"onItemSelect",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(e in s){t=this.settings[s[e]];t&&this.on(e,t)}}sync(e=true){const t=this;const s=e?getSettings(t.input,{delimiter:t.settings.delimiter}):t.settings;t.setupOptions(s.options,s.optgroups);t.setValue(s.items||[],true);t.lastQuery=null}onClick(){var e=this;if(e.activeItems.length>0){e.clearActiveItems();e.focus()}else e.isFocused&&e.isOpen?e.blur():e.focus()}
/**
     * @deprecated v1.7
     *
     */onMouseDown(){}onChange(){triggerEvent(this.input,"input");triggerEvent(this.input,"change")}onPaste(e){var t=this;t.isInputHidden||t.isLocked?preventDefault(e):t.settings.splitOn&&setTimeout((()=>{var e=t.inputValue();if(e.match(t.settings.splitOn)){var s=e.trim().split(t.settings.splitOn);iterate$1(s,(e=>{const s=hash_key(e);s&&(this.options[e]?t.addItem(e):t.createItem(e))}))}}),0)}onKeyPress(e){var t=this;if(t.isLocked)preventDefault(e);else{var s=String.fromCharCode(e.keyCode||e.which);if(t.settings.create&&"multi"===t.settings.mode&&s===t.settings.delimiter){t.createItem();preventDefault(e)}else;}}onKeyDown(e){var t=this;t.ignoreHover=true;if(t.isLocked)e.keyCode!==y&&preventDefault(e);else{switch(e.keyCode){case c:if(isKeyDown(O,e)&&""==t.control_input.value){preventDefault(e);t.selectAll();return}break;case u:if(t.isOpen){preventDefault(e,true);t.close()}t.clearActiveItems();return;case f:if(!t.isOpen&&t.hasOptions)t.open();else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1);e&&t.setActiveOption(e)}preventDefault(e);return;case h:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1);e&&t.setActiveOption(e)}preventDefault(e);return;case d:if(t.canSelect(t.activeOption)){t.onOptionSelect(e,t.activeOption);preventDefault(e)}else(t.settings.create&&t.createItem()||document.activeElement==t.control_input&&t.isOpen)&&preventDefault(e);return;case p:t.advanceSelection(-1,e);return;case g:t.advanceSelection(1,e);return;case y:if(t.settings.selectOnTab){if(t.canSelect(t.activeOption)){t.onOptionSelect(e,t.activeOption);preventDefault(e)}t.settings.create&&t.createItem()&&preventDefault(e)}return;case v:case m:t.deleteSelection(e);return}t.isInputHidden&&!isKeyDown(O,e)&&preventDefault(e)}}onInput(e){if(this.isLocked)return;const t=this.inputValue();if(this.lastValue!==t){this.lastValue=t;if(""!=t){this.refreshTimeout&&clearTimeout(this.refreshTimeout);this.refreshTimeout=timeout((()=>{this.refreshTimeout=null;this._onInput()}),this.settings.refreshThrottle)}else this._onInput()}}_onInput(){const e=this.lastValue;this.settings.shouldLoad.call(this,e)&&this.load(e);this.refreshOptions();this.trigger("type",e)}onOptionHover(e,t){this.ignoreHover||this.setActiveOption(t,false)}onFocus(e){var t=this;var s=t.isFocused;if(t.isDisabled||t.isReadOnly){t.blur();preventDefault(e)}else if(!t.ignoreFocus){t.isFocused=true;"focus"===t.settings.preload&&t.preload();s||t.trigger("focus");if(!t.activeItems.length){t.inputState();t.refreshOptions(!!t.settings.openOnFocus)}t.refreshState()}}onBlur(e){if(false!==document.hasFocus()){var t=this;if(t.isFocused){t.isFocused=false;t.ignoreFocus=false;var deactivate=()=>{t.close();t.setActiveItem();t.setCaret(t.items.length);t.trigger("blur")};t.settings.create&&t.settings.createOnBlur?t.createItem(null,deactivate):deactivate()}}}onOptionSelect(e,t){var s,i=this;if(!t.parentElement||!t.parentElement.matches("[data-disabled]"))if(t.classList.contains("create"))i.createItem(null,(()=>{i.settings.closeAfterSelect&&i.close()}));else{s=t.dataset.value;if("undefined"!==typeof s){i.lastQuery=null;i.addItem(s);i.settings.closeAfterSelect&&i.close();!i.settings.hideSelected&&e.type&&/click/.test(e.type)&&i.setActiveOption(t)}}}canSelect(e){return!!(this.isOpen&&e&&this.dropdown_content.contains(e))}onItemSelect(e,t){var s=this;if(!s.isLocked&&"multi"===s.settings.mode){preventDefault(e);s.setActiveItem(t,e);return true}return false}canLoad(e){return!!this.settings.load&&!this.loadedSearches.hasOwnProperty(e)}load(e){const t=this;if(!t.canLoad(e))return;addClasses(t.wrapper,t.settings.loadingClass);t.loading++;const s=t.loadCallback.bind(t);t.settings.load.call(t,e,s)}loadCallback(e,t){const s=this;s.loading=Math.max(s.loading-1,0);s.lastQuery=null;s.clearActiveOption();s.setupOptions(e,t);s.refreshOptions(s.isFocused&&!s.isInputHidden);s.loading||removeClasses(s.wrapper,s.settings.loadingClass);s.trigger("load",e,t)}preload(){var e=this.wrapper.classList;if(!e.contains("preloaded")){e.add("preloaded");this.load("")}}setTextboxValue(e=""){var t=this.control_input;var s=t.value!==e;if(s){t.value=e;triggerEvent(t,"update");this.lastValue=e}}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(e,t){var s=t?[]:["change"];debounce_events(this,s,(()=>{this.clear(t);this.addItems(e,t)}))}setMaxItems(e){0===e&&(e=null);this.settings.maxItems=e;this.refreshState()}setActiveItem(e,t){var s=this;var i;var n,o,r,l;var a;if("single"!==s.settings.mode)if(e){i=t&&t.type.toLowerCase();if("click"===i&&isKeyDown("shiftKey",t)&&s.activeItems.length){a=s.getLastActive();o=Array.prototype.indexOf.call(s.control.children,a);r=Array.prototype.indexOf.call(s.control.children,e);if(o>r){l=o;o=r;r=l}for(n=o;n<=r;n++){e=s.control.children[n];-1===s.activeItems.indexOf(e)&&s.setActiveItemClass(e)}preventDefault(t)}else if("click"===i&&isKeyDown(O,t)||"keydown"===i&&isKeyDown("shiftKey",t))e.classList.contains("active")?s.removeActiveItem(e):s.setActiveItemClass(e);else{s.clearActiveItems();s.setActiveItemClass(e)}s.inputState();s.isFocused||s.focus()}else{s.clearActiveItems();s.isFocused&&s.inputState()}}setActiveItemClass(e){const t=this;const s=t.control.querySelector(".last-active");s&&removeClasses(s,"last-active");addClasses(e,"active last-active");t.trigger("item_select",e);-1==t.activeItems.indexOf(e)&&t.activeItems.push(e)}removeActiveItem(e){var t=this.activeItems.indexOf(e);this.activeItems.splice(t,1);removeClasses(e,"active")}clearActiveItems(){removeClasses(this.activeItems,"active");this.activeItems=[]}setActiveOption(e,t=true){if(e!==this.activeOption){this.clearActiveOption();if(e){this.activeOption=e;setAttr(this.focus_node,{"aria-activedescendant":e.getAttribute("id")});setAttr(e,{"aria-selected":"true"});addClasses(e,"active");t&&this.scrollToOption(e)}}}scrollToOption(e,t){if(!e)return;const s=this.dropdown_content;const i=s.clientHeight;const n=s.scrollTop||0;const o=e.offsetHeight;const r=e.getBoundingClientRect().top-s.getBoundingClientRect().top+n;r+o>i+n?this.scroll(r-i+o,t):r<n&&this.scroll(r,t)}scroll(e,t){const s=this.dropdown_content;t&&(s.style.scrollBehavior=t);s.scrollTop=e;s.style.scrollBehavior=""}clearActiveOption(){if(this.activeOption){removeClasses(this.activeOption,"active");setAttr(this.activeOption,{"aria-selected":null})}this.activeOption=null;setAttr(this.focus_node,{"aria-activedescendant":null})}selectAll(){const e=this;if("single"===e.settings.mode)return;const t=e.controlChildren();if(t.length){e.inputState();e.close();e.activeItems=t;iterate$1(t,(t=>{e.setActiveItemClass(t)}))}}inputState(){var e=this;if(e.control.contains(e.control_input)){setAttr(e.control_input,{placeholder:e.settings.placeholder});if(e.activeItems.length>0||!e.isFocused&&e.settings.hidePlaceholder&&e.items.length>0){e.setTextboxValue();e.isInputHidden=true}else{e.settings.hidePlaceholder&&e.items.length>0&&setAttr(e.control_input,{placeholder:""});e.isInputHidden=false}e.wrapper.classList.toggle("input-hidden",e.isInputHidden)}}inputValue(){return this.control_input.value.trim()}focus(){var e=this;if(!e.isDisabled&&!e.isReadOnly){e.ignoreFocus=true;e.control_input.offsetWidth?e.control_input.focus():e.focus_node.focus();setTimeout((()=>{e.ignoreFocus=false;e.onFocus()}),0)}}blur(){this.focus_node.blur();this.onBlur()}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e=this.settings;var t=e.sortField;"string"===typeof e.sortField&&(t=[{field:e.sortField}]);return{fields:e.searchField,conjunction:e.searchConjunction,sort:t,nesting:e.nesting}}search(e){var t,s;var i=this;var n=this.getSearchOptions();if(i.settings.score){s=i.settings.score.call(i,e);if("function"!==typeof s)throw new Error('Tom Select "score" setting must be a function that returns a function')}if(e!==i.lastQuery){i.lastQuery=e;t=i.sifter.search(e,Object.assign(n,{score:s}));i.currentResults=t}else t=Object.assign({},i.currentResults);i.settings.hideSelected&&(t.items=t.items.filter((e=>{let t=hash_key(e.id);return!(t&&-1!==i.items.indexOf(t))})));return t}refreshOptions(e=true){var t,s,i,n,o,r,l,a,c;var d;const u={};const p=[];var h=this;var g=h.inputValue();const f=g===h.lastQuery||""==g&&null==h.lastQuery;var v=h.search(g);var m=null;var y=h.settings.shouldOpen||false;var b=h.dropdown_content;if(f){m=h.activeOption;m&&(c=m.closest("[data-group]"))}n=v.items.length;"number"===typeof h.settings.maxOptions&&(n=Math.min(n,h.settings.maxOptions));n>0&&(y=true);const getGroupFragment=(e,t)=>{let s=u[e];if(void 0!==s){let e=p[s];if(void 0!==e)return[s,e.fragment]}let i=document.createDocumentFragment();s=p.length;p.push({fragment:i,order:t,optgroup:e});return[s,i]};for(t=0;t<n;t++){let e=v.items[t];if(!e)continue;let n=e.id;let l=h.options[n];if(void 0===l)continue;let a=get_hash(n);let d=h.getOption(a,true);h.settings.hideSelected||d.classList.toggle("selected",h.items.includes(a));o=l[h.settings.optgroupField]||"";r=Array.isArray(o)?o:[o];for(s=0,i=r&&r.length;s<i;s++){o=r[s];let e=l.$order;let t=h.optgroups[o];void 0===t?o="":e=t.$order;const[i,a]=getGroupFragment(o,e);if(s>0){d=d.cloneNode(true);setAttr(d,{id:l.$id+"-clone-"+s,"aria-selected":null});d.classList.add("ts-cloned");removeClasses(d,"active");h.activeOption&&h.activeOption.dataset.value==n&&c&&c.dataset.group===o.toString()&&(m=d)}a.appendChild(d);""!=o&&(u[o]=i)}}h.settings.lockOptgroupOrder&&p.sort(((e,t)=>e.order-t.order));l=document.createDocumentFragment();iterate$1(p,(e=>{let t=e.fragment;let s=e.optgroup;if(!t||!t.children.length)return;let i=h.optgroups[s];if(void 0!==i){let e=document.createDocumentFragment();let s=h.render("optgroup_header",i);append(e,s);append(e,t);let n=h.render("optgroup",{group:i,options:e});append(l,n)}else append(l,t)}));b.innerHTML="";append(b,l);if(h.settings.highlight){removeHighlight(b);v.query.length&&v.tokens.length&&iterate$1(v.tokens,(e=>{highlight(b,e.regex)}))}var add_template=e=>{let t=h.render(e,{input:g});if(t){y=true;b.insertBefore(t,b.firstChild)}return t};h.loading?add_template("loading"):h.settings.shouldLoad.call(h,g)?0===v.items.length&&add_template("no_results"):add_template("not_loading");a=h.canCreate(g);a&&(d=add_template("option_create"));h.hasOptions=v.items.length>0||a;if(y){if(v.items.length>0){m||"single"!==h.settings.mode||void 0==h.items[0]||(m=h.getOption(h.items[0]));if(!b.contains(m)){let e=0;d&&!h.settings.addPrecedence&&(e=1);m=h.selectable()[e]}}else d&&(m=d);if(e&&!h.isOpen){h.open();h.scrollToOption(m,"auto")}h.setActiveOption(m)}else{h.clearActiveOption();e&&h.isOpen&&h.close(false)}}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e,t=false){const s=this;if(Array.isArray(e)){s.addOptions(e,t);return false}const i=hash_key(e[s.settings.valueField]);if(null===i||s.options.hasOwnProperty(i))return false;e.$order=e.$order||++s.order;e.$id=s.inputId+"-opt-"+e.$order;s.options[i]=e;s.lastQuery=null;if(t){s.userOptions[i]=t;s.trigger("option_add",i,e)}return i}addOptions(e,t=false){iterate$1(e,(e=>{this.addOption(e,t)}))}
/**
     * @deprecated 1.7.7
     */registerOption(e){return this.addOption(e)}registerOptionGroup(e){var t=hash_key(e[this.settings.optgroupValueField]);if(null===t)return false;e.$order=e.$order||++this.order;this.optgroups[t]=e;return t}addOptionGroup(e,t){var s;t[this.settings.optgroupValueField]=e;(s=this.registerOptionGroup(t))&&this.trigger("optgroup_add",s,t)}removeOptionGroup(e){if(this.optgroups.hasOwnProperty(e)){delete this.optgroups[e];this.clearCache();this.trigger("optgroup_remove",e)}}clearOptionGroups(){this.optgroups={};this.clearCache();this.trigger("optgroup_clear")}updateOption(e,t){const s=this;var i;var n;const o=hash_key(e);const r=hash_key(t[s.settings.valueField]);if(null===o)return;const l=s.options[o];if(void 0==l)return;if("string"!==typeof r)throw new Error("Value must be set in option data");const a=s.getOption(o);const c=s.getItem(o);t.$order=t.$order||l.$order;delete s.options[o];s.uncacheValue(r);s.options[r]=t;if(a){if(s.dropdown_content.contains(a)){const e=s._render("option",t);replaceNode(a,e);s.activeOption===a&&s.setActiveOption(e)}a.remove()}if(c){n=s.items.indexOf(o);-1!==n&&s.items.splice(n,1,r);i=s._render("item",t);c.classList.contains("active")&&addClasses(i,"active");replaceNode(c,i)}s.lastQuery=null}removeOption(e,t){const s=this;e=get_hash(e);s.uncacheValue(e);delete s.userOptions[e];delete s.options[e];s.lastQuery=null;s.trigger("option_remove",e);s.removeItem(e,t)}clearOptions(e){const t=(e||this.clearFilter).bind(this);this.loadedSearches={};this.userOptions={};this.clearCache();const s={};iterate$1(this.options,((e,i)=>{t(e,i)&&(s[i]=e)}));this.options=this.sifter.items=s;this.lastQuery=null;this.trigger("option_clear")}clearFilter(e,t){return this.items.indexOf(t)>=0}getOption(e,t=false){const s=hash_key(e);if(null===s)return null;const i=this.options[s];if(void 0!=i){if(i.$div)return i.$div;if(t)return this._render("option",i)}return null}getAdjacent(e,t,s="option"){var i,n=this;if(!e)return null;i="item"==s?n.controlChildren():n.dropdown_content.querySelectorAll("[data-selectable]");for(let s=0;s<i.length;s++)if(i[s]==e)return t>0?i[s+1]:i[s-1];return null}getItem(e){if("object"==typeof e)return e;var t=hash_key(e);return null!==t?this.control.querySelector(`[data-value="${addSlashes(t)}"]`):null}addItems(e,t){var s=this;var i=Array.isArray(e)?e:[e];i=i.filter((e=>-1===s.items.indexOf(e)));const n=i[i.length-1];i.forEach((e=>{s.isPending=e!==n;s.addItem(e,t)}))}addItem(e,t){var s=t?[]:["change","dropdown_close"];debounce_events(this,s,(()=>{var s,i;const n=this;const o=n.settings.mode;const r=hash_key(e);if(r&&-1!==n.items.indexOf(r)){"single"===o&&n.close();if("single"===o||!n.settings.duplicates)return}if(null!==r&&n.options.hasOwnProperty(r)){"single"===o&&n.clear(t);if("multi"!==o||!n.isFull()){s=n._render("item",n.options[r]);n.control.contains(s)&&(s=s.cloneNode(true));i=n.isFull();n.items.splice(n.caretPos,0,r);n.insertAtCaret(s);if(n.isSetup){if(!n.isPending&&n.settings.hideSelected){let e=n.getOption(r);let t=n.getAdjacent(e,1);t&&n.setActiveOption(t)}n.isPending||n.settings.closeAfterSelect||n.refreshOptions(n.isFocused&&"single"!==o);false!=n.settings.closeAfterSelect&&n.isFull()?n.close():n.isPending||n.positionDropdown();n.trigger("item_add",r,s);n.isPending||n.updateOriginalInput({silent:t})}if(!n.isPending||!i&&n.isFull()){n.inputState();n.refreshState()}}}}))}removeItem(e=null,t){const s=this;e=s.getItem(e);if(!e)return;var i,n;const o=e.dataset.value;i=nodeIndex(e);e.remove();if(e.classList.contains("active")){n=s.activeItems.indexOf(e);s.activeItems.splice(n,1);removeClasses(e,"active")}s.items.splice(i,1);s.lastQuery=null;!s.settings.persist&&s.userOptions.hasOwnProperty(o)&&s.removeOption(o,t);i<s.caretPos&&s.setCaret(s.caretPos-1);s.updateOriginalInput({silent:t});s.refreshState();s.positionDropdown();s.trigger("item_remove",o,e)}createItem(e=null,t=(()=>{})){3===arguments.length&&(t=arguments[2]);"function"!=typeof t&&(t=()=>{});var s=this;var i=s.caretPos;var n;e=e||s.inputValue();if(!s.canCreate(e)){t();return false}s.lock();var o=false;var create=e=>{s.unlock();if(!e||"object"!==typeof e)return t();var n=hash_key(e[s.settings.valueField]);if("string"!==typeof n)return t();s.setTextboxValue();s.addOption(e,true);s.setCaret(i);s.addItem(n);t(e);o=true};n="function"===typeof s.settings.create?s.settings.create.call(this,e,create):{[s.settings.labelField]:e,[s.settings.valueField]:e};o||create(n);return true}refreshItems(){var e=this;e.lastQuery=null;e.isSetup&&e.addItems(e.items);e.updateOriginalInput();e.refreshState()}refreshState(){const e=this;e.refreshValidityState();const t=e.isFull();const s=e.isLocked;e.wrapper.classList.toggle("rtl",e.rtl);const i=e.wrapper.classList;i.toggle("focus",e.isFocused);i.toggle("disabled",e.isDisabled);i.toggle("readonly",e.isReadOnly);i.toggle("required",e.isRequired);i.toggle("invalid",!e.isValid);i.toggle("locked",s);i.toggle("full",t);i.toggle("input-active",e.isFocused&&!e.isInputHidden);i.toggle("dropdown-active",e.isOpen);i.toggle("has-options",isEmptyObject(e.options));i.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this;if(e.input.validity){e.isValid=e.input.validity.valid;e.isInvalid=!e.isValid}}
/**
     * Determines whether or not more items can be added
     * to the control without exceeding the user-defined maximum.
     *
     * @returns {boolean}
     */isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){const t=this;var s,i;const n=t.input.querySelector('option[value=""]');if(t.is_select_tag){const o=[];const r=t.input.querySelectorAll("option:checked").length;function AddSelected(e,s,i){e||(e=getDom('<option value="'+escape_html(s)+'">'+escape_html(i)+"</option>"));e!=n&&t.input.append(e);o.push(e);(e!=n||r>0)&&(e.selected=true);return e}t.input.querySelectorAll("option:checked").forEach((e=>{e.selected=false}));0==t.items.length&&"single"==t.settings.mode?AddSelected(n,"",""):t.items.forEach((e=>{s=t.options[e];i=s[t.settings.labelField]||"";if(o.includes(s.$option)){const s=t.input.querySelector(`option[value="${addSlashes(e)}"]:not(:checked)`);AddSelected(s,e,i)}else s.$option=AddSelected(s.$option,e,i)}))}else t.input.value=t.getValue();t.isSetup&&(e.silent||t.trigger("change",t.getValue()))}open(){var e=this;if(!(e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull())){e.isOpen=true;setAttr(e.focus_node,{"aria-expanded":"true"});e.refreshState();applyCSS(e.dropdown,{visibility:"hidden",display:"block"});e.positionDropdown();applyCSS(e.dropdown,{visibility:"visible",display:"block"});e.focus();e.trigger("dropdown_open",e.dropdown)}}close(e=true){var t=this;var s=t.isOpen;if(e){t.setTextboxValue();"single"===t.settings.mode&&t.items.length&&t.inputState()}t.isOpen=false;setAttr(t.focus_node,{"aria-expanded":"false"});applyCSS(t.dropdown,{display:"none"});t.settings.hideSelected&&t.clearActiveOption();t.refreshState();s&&t.trigger("dropdown_close",t.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var e=this.control;var t=e.getBoundingClientRect();var s=e.offsetHeight+t.top+window.scrollY;var i=t.left+window.scrollX;applyCSS(this.dropdown,{width:t.width+"px",top:s+"px",left:i+"px"})}}clear(e){var t=this;if(t.items.length){var s=t.controlChildren();iterate$1(s,(e=>{t.removeItem(e,true)}));t.inputState();e||t.updateOriginalInput();t.trigger("clear")}}insertAtCaret(e){const t=this;const s=t.caretPos;const i=t.control;i.insertBefore(e,i.children[s]||null);t.setCaret(s+1)}deleteSelection(e){var t,s,i,n;var o=this;t=e&&e.keyCode===v?-1:1;s=getSelection(o.control_input);const r=[];if(o.activeItems.length){n=getTail(o.activeItems,t);i=nodeIndex(n);t>0&&i++;iterate$1(o.activeItems,(e=>r.push(e)))}else if((o.isFocused||"single"===o.settings.mode)&&o.items.length){const e=o.controlChildren();let i;t<0&&0===s.start&&0===s.length?i=e[o.caretPos-1]:t>0&&s.start===o.inputValue().length&&(i=e[o.caretPos]);void 0!==i&&r.push(i)}if(!o.shouldDelete(r,e))return false;preventDefault(e,true);"undefined"!==typeof i&&o.setCaret(i);while(r.length)o.removeItem(r.pop());o.inputState();o.positionDropdown();o.refreshOptions(false);return true}shouldDelete(e,t){const s=e.map((e=>e.dataset.value));return!(!s.length||"function"===typeof this.settings.onDelete&&false===this.settings.onDelete(s,t))}advanceSelection(e,t){var s,i,n=this;n.rtl&&(e*=-1);if(!n.inputValue().length)if(isKeyDown(O,t)||isKeyDown("shiftKey",t)){s=n.getLastActive(e);i=s?s.classList.contains("active")?n.getAdjacent(s,e,"item"):s:e>0?n.control_input.nextElementSibling:n.control_input.previousElementSibling;if(i){i.classList.contains("active")&&n.removeActiveItem(s);n.setActiveItemClass(i)}}else n.moveCaret(e)}moveCaret(e){}getLastActive(e){let t=this.control.querySelector(".last-active");if(t)return t;var s=this.control.querySelectorAll(".active");return s?getTail(s,e):void 0}setCaret(e){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.setLocked(true)}unlock(){this.setLocked(false)}setLocked(e=this.isReadOnly||this.isDisabled){this.isLocked=e;this.refreshState()}disable(){this.setDisabled(true);this.close()}enable(){this.setDisabled(false)}setDisabled(e){this.focus_node.tabIndex=e?-1:this.tabIndex;this.isDisabled=e;this.input.disabled=e;this.control_input.disabled=e;this.setLocked()}setReadOnly(e){this.isReadOnly=e;this.input.readOnly=e;this.control_input.readOnly=e;this.setLocked()}destroy(){var e=this;var t=e.revertSettings;e.trigger("destroy");e.off();e.wrapper.remove();e.dropdown.remove();e.input.innerHTML=t.innerHTML;e.input.tabIndex=t.tabIndex;removeClasses(e.input,"tomselected","ts-hidden-accessible");e._destroy();delete e.input.tomselect}render(e,t){var s,i;const n=this;if("function"!==typeof this.settings.render[e])return null;i=n.settings.render[e].call(this,t,escape_html);if(!i)return null;i=getDom(i);if("option"===e||"option_create"===e)t[n.settings.disabledField]?setAttr(i,{"aria-disabled":"true"}):setAttr(i,{"data-selectable":""});else if("optgroup"===e){s=t.group[n.settings.optgroupValueField];setAttr(i,{"data-group":s});t.group[n.settings.disabledField]&&setAttr(i,{"data-disabled":""})}if("option"===e||"item"===e){const s=get_hash(t[n.settings.valueField]);setAttr(i,{"data-value":s});if("item"===e){addClasses(i,n.settings.itemClass);setAttr(i,{"data-ts-item":""})}else{addClasses(i,n.settings.optionClass);setAttr(i,{role:"option",id:t.$id});t.$div=i;n.options[s]=t}}return i}_render(e,t){const s=this.render(e,t);if(null==s)throw"HTMLElement expected";return s}clearCache(){iterate$1(this.options,(e=>{if(e.$div){e.$div.remove();delete e.$div}}))}uncacheValue(e){const t=this.getOption(e);t&&t.remove()}canCreate(e){return this.settings.create&&e.length>0&&this.settings.createFilter.call(this,e)}hook(e,t,s){var i=this;var n=i[t];i[t]=function(){var t,o;"after"===e&&(t=n.apply(i,arguments));o=s.apply(i,arguments);if("instead"===e)return o;"before"===e&&(t=n.apply(i,arguments));return t}}}function change_listener(){addEvent((this||e).input,"change",(()=>{this.sync()}))}function checkbox_options(t){var s=this||e;var i=s.onOptionSelect;s.settings.hideSelected=false;const n=Object.assign({className:"tomselect-checkbox",checkedClassNames:void 0,uncheckedClassNames:void 0},t);var o=function UpdateChecked(e,t){if(t){e.checked=true;n.uncheckedClassNames&&e.classList.remove(...n.uncheckedClassNames);n.checkedClassNames&&e.classList.add(...n.checkedClassNames)}else{e.checked=false;n.checkedClassNames&&e.classList.remove(...n.checkedClassNames);n.uncheckedClassNames&&e.classList.add(...n.uncheckedClassNames)}};var r=function UpdateCheckbox(e){setTimeout((()=>{var t=e.querySelector("input."+n.className);t instanceof HTMLInputElement&&o(t,e.classList.contains("selected"))}),1)};s.hook("after","setupTemplates",(()=>{var e=s.settings.render.option;s.settings.render.option=(t,i)=>{var r=getDom(e.call(s,t,i));var l=document.createElement("input");n.className&&l.classList.add(n.className);l.addEventListener("click",(function(e){preventDefault(e)}));l.type="checkbox";const a=hash_key(t[s.settings.valueField]);o(l,!!(a&&s.items.indexOf(a)>-1));r.prepend(l);return r}}));s.on("item_remove",(e=>{var t=s.getOption(e);if(t){t.classList.remove("selected");r(t)}}));s.on("item_add",(e=>{var t=s.getOption(e);t&&r(t)}));s.hook("instead","onOptionSelect",((e,t)=>{if(t.classList.contains("selected")){t.classList.remove("selected");s.removeItem(t.dataset.value);s.refreshOptions();preventDefault(e,true)}else{i.call(s,e,t);r(t)}}))}function clear_button(t){const s=this||e;const i=Object.assign({className:"clear-button",title:"Clear All",html:e=>`<div class="${e.className}" title="${e.title}">&#10799;</div>`},t);s.on("initialize",(()=>{var e=getDom(i.html(i));e.addEventListener("click",(e=>{if(!s.isLocked){s.clear();"single"===s.settings.mode&&s.settings.allowEmptyOption&&s.addItem("");e.preventDefault();e.stopPropagation()}}));s.control.appendChild(e)}))}const insertAfter=(e,t)=>{var s;null==(s=e.parentNode)||s.insertBefore(t,e.nextSibling)};const insertBefore=(e,t)=>{var s;null==(s=e.parentNode)||s.insertBefore(t,e)};const isBefore=(e,t)=>{do{var s;t=null==(s=t)?void 0:s.previousElementSibling;if(e==t)return true}while(t&&t.previousElementSibling);return false};function drag_drop(){var t=this||e;if("multi"!==t.settings.mode)return;var s=t.lock;var i=t.unlock;let n=true;let o;t.hook("after","setupTemplates",(()=>{var e=t.settings.render.item;t.settings.render.item=(s,i)=>{const r=getDom(e.call(t,s,i));setAttr(r,{draggable:"true"});const mousedown=e=>{n||preventDefault(e);e.stopPropagation()};const dragStart=e=>{o=r;setTimeout((()=>{r.classList.add("ts-dragging")}),0)};const dragOver=e=>{e.preventDefault();r.classList.add("ts-drag-over");moveitem(r,o)};const dragLeave=()=>{r.classList.remove("ts-drag-over")};const moveitem=(e,t)=>{void 0!==t&&(isBefore(t,r)?insertAfter(e,t):insertBefore(e,t))};const dragend=()=>{var e;document.querySelectorAll(".ts-drag-over").forEach((e=>e.classList.remove("ts-drag-over")));null==(e=o)||e.classList.remove("ts-dragging");o=void 0;var s=[];t.control.querySelectorAll("[data-value]").forEach((e=>{if(e.dataset.value){let t=e.dataset.value;t&&s.push(t)}}));t.setValue(s)};addEvent(r,"mousedown",mousedown);addEvent(r,"dragstart",dragStart);addEvent(r,"dragenter",dragOver);addEvent(r,"dragover",dragOver);addEvent(r,"dragleave",dragLeave);addEvent(r,"dragend",dragend);return r}}));t.hook("instead","lock",(()=>{n=false;return s.call(t)}));t.hook("instead","unlock",(()=>{n=true;return i.call(t)}))}function dropdown_header(t){const s=this||e;const i=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:e=>'<div class="'+e.headerClass+'"><div class="'+e.titleRowClass+'"><span class="'+e.labelClass+'">'+e.title+'</span><a class="'+e.closeClass+'">&times;</a></div></div>'},t);s.on("initialize",(()=>{var e=getDom(i.html(i));var t=e.querySelector("."+i.closeClass);t&&t.addEventListener("click",(e=>{preventDefault(e,true);s.close()}));s.dropdown.insertBefore(e,s.dropdown.firstChild)}))}function caret_position(){var t=this||e;t.hook("instead","setCaret",(e=>{if("single"!==t.settings.mode&&t.control.contains(t.control_input)){e=Math.max(0,Math.min(t.items.length,e));e==t.caretPos||t.isPending||t.controlChildren().forEach(((s,i)=>{i<e?t.control_input.insertAdjacentElement("beforebegin",s):t.control.appendChild(s)}))}else e=t.items.length;t.caretPos=e}));t.hook("instead","moveCaret",(e=>{if(!t.isFocused)return;const s=t.getLastActive(e);if(s){const i=nodeIndex(s);t.setCaret(e>0?i+1:i);t.setActiveItem();removeClasses(s,"last-active")}else t.setCaret(t.caretPos+e)}))}function dropdown_input(){const t=this||e;t.settings.shouldOpen=true;t.hook("before","setup",(()=>{t.focus_node=t.control;addClasses(t.control_input,"dropdown-input");const e=getDom('<div class="dropdown-input-wrap">');e.append(t.control_input);t.dropdown.insertBefore(e,t.dropdown.firstChild);const s=getDom('<input class="items-placeholder" tabindex="-1" />');s.placeholder=t.settings.placeholder||"";t.control.append(s)}));t.on("initialize",(()=>{t.control_input.addEventListener("keydown",(e=>{switch(e.keyCode){case u:if(t.isOpen){preventDefault(e,true);t.close()}t.clearActiveItems();return;case y:t.focus_node.tabIndex=-1;break}return t.onKeyDown.call(t,e)}));t.on("blur",(()=>{t.focus_node.tabIndex=t.isDisabled?-1:t.tabIndex}));t.on("dropdown_open",(()=>{t.control_input.focus()}));const e=t.onBlur;t.hook("instead","onBlur",(s=>{if(!s||s.relatedTarget!=t.control_input)return e.call(t)}));addEvent(t.control_input,"blur",(()=>t.onBlur()));t.hook("before","close",(()=>{t.isOpen&&t.focus_node.focus({preventScroll:true})}))}))}function input_autogrow(){var t=this||e;t.on("initialize",(()=>{var e=document.createElement("span");var s=t.control_input;e.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ";t.wrapper.appendChild(e);var i=["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"];for(const t of i)e.style[t]=s.style[t];var resize=()=>{e.textContent=s.value;s.style.width=e.clientWidth+"px"};resize();t.on("update item_add item_remove",resize);addEvent(s,"input",resize);addEvent(s,"keyup",resize);addEvent(s,"blur",resize);addEvent(s,"update",resize)}))}function no_backspace_delete(){var t=this||e;var s=t.deleteSelection;this.hook("instead","deleteSelection",(e=>!!t.activeItems.length&&s.call(t,e)))}function no_active_items(){this.hook("instead","setActiveItem",(()=>{}));this.hook("instead","selectAll",(()=>{}))}function optgroup_columns(){var t=this||e;var s=t.onKeyDown;t.hook("instead","onKeyDown",(e=>{var i,n,o,r;if(!t.isOpen||!(e.keyCode===p||e.keyCode===g))return s.call(t,e);t.ignoreHover=true;r=parentMatch(t.activeOption,"[data-group]");i=nodeIndex(t.activeOption,"[data-selectable]");if(r){r=e.keyCode===p?r.previousSibling:r.nextSibling;if(r){o=r.querySelectorAll("[data-selectable]");n=o[Math.min(o.length-1,i)];n&&t.setActiveOption(n)}}}))}function remove_button(t){const s=Object.assign({label:"&times;",title:"Remove",className:"remove",append:true},t);var i=this||e;if(s.append){var n='<a href="javascript:void(0)" class="'+s.className+'" tabindex="-1" title="'+escape_html(s.title)+'">'+s.label+"</a>";i.hook("after","setupTemplates",(()=>{var e=i.settings.render.item;i.settings.render.item=(t,s)=>{var o=getDom(e.call(i,t,s));var r=getDom(n);o.appendChild(r);addEvent(r,"mousedown",(e=>{preventDefault(e,true)}));addEvent(r,"click",(e=>{if(!i.isLocked){preventDefault(e,true);if(!i.isLocked&&i.shouldDelete([o],e)){i.removeItem(o);i.refreshOptions(false);i.inputState()}}}));return o}}))}}function restore_on_backspace(t){const s=this||e;const i=Object.assign({text:e=>e[s.settings.labelField]},t);s.on("item_remove",(function(e){if(s.isFocused&&""===s.control_input.value.trim()){var t=s.options[e];t&&s.setTextboxValue(i.text.call(s,t))}}))}function virtual_scroll(){const t=this||e;const s=t.canLoad;const i=t.clearActiveOption;const n=t.loadCallback;var o={};var r;var l=false;var a;var c=[];t.settings.shouldLoadMore||(t.settings.shouldLoadMore=()=>{const e=r.clientHeight/(r.scrollHeight-r.scrollTop);if(e>.9)return true;if(t.activeOption){var s=t.selectable();var i=Array.from(s).indexOf(t.activeOption);if(i>=s.length-2)return true}return false});if(!t.settings.firstUrl)throw"virtual_scroll plugin requires a firstUrl() method";t.settings.sortField=[{field:"$order"},{field:"$score"}];const canLoadMore=e=>!("number"===typeof t.settings.maxOptions&&r.children.length>=t.settings.maxOptions)&&!(!(e in o)||!o[e]);const clearFilter=(e,s)=>t.items.indexOf(s)>=0||c.indexOf(s)>=0;t.setNextUrl=(e,t)=>{o[e]=t};t.getUrl=e=>{if(e in o){const t=o[e];o[e]=false;return t}t.clearPagination();return t.settings.firstUrl.call(t,e)};t.clearPagination=()=>{o={}};t.hook("instead","clearActiveOption",(()=>{if(!l)return i.call(t)}));t.hook("instead","canLoad",(e=>e in o?canLoadMore(e):s.call(t,e)));t.hook("instead","loadCallback",((e,s)=>{if(l){if(a){const s=e[0];void 0!==s&&(a.dataset.value=s[t.settings.valueField])}}else t.clearOptions(clearFilter);n.call(t,e,s);l=false}));t.hook("after","refreshOptions",(()=>{const e=t.lastValue;var s;if(canLoadMore(e)){s=t.render("loading_more",{query:e});if(s){s.setAttribute("data-selectable","");a=s}}else e in o&&!r.querySelector(".no-results")&&(s=t.render("no_more_results",{query:e}));if(s){addClasses(s,t.settings.optionClass);r.append(s)}}));t.on("initialize",(()=>{c=Object.keys(t.options);r=t.dropdown_content;t.settings.render=Object.assign({},{loading_more:()=>'<div class="loading-more-results">Loading more results ... </div>',no_more_results:()=>'<div class="no-more-results">No more results</div>'},t.settings.render);r.addEventListener("scroll",(()=>{if(t.settings.shouldLoadMore.call(t)&&canLoadMore(t.lastValue)&&!l){l=true;t.load.call(t,t.lastValue)}}))}))}TomSelect.define("change_listener",change_listener);TomSelect.define("checkbox_options",checkbox_options);TomSelect.define("clear_button",clear_button);TomSelect.define("drag_drop",drag_drop);TomSelect.define("dropdown_header",dropdown_header);TomSelect.define("caret_position",caret_position);TomSelect.define("dropdown_input",dropdown_input);TomSelect.define("input_autogrow",input_autogrow);TomSelect.define("no_backspace_delete",no_backspace_delete);TomSelect.define("no_active_items",no_active_items);TomSelect.define("optgroup_columns",optgroup_columns);TomSelect.define("remove_button",remove_button);TomSelect.define("restore_on_backspace",restore_on_backspace);TomSelect.define("virtual_scroll",virtual_scroll);return TomSelect}));var s=t;export{s as default};

