'),d=this.input.getAttribute("class")||"",u=i.mode;var h;z(o,i.wrapperClass,d,u),z(a,i.controlClass),Te(o,a),z(l,i.dropdownClass,u),i.copyClassesToDropdown&&z(l,d),z(c,i.dropdownContentClass),Te(l,c),R(i.dropdownParent||o).appendChild(l),q(i.controlInput)?(h=R(i.controlInput),D(["autocorrect","autocapitalize","autocomplete","spellcheck"],(e=>{s.getAttribute(e)&&ee(h,{[e]:s.getAttribute(e)})})),h.tabIndex=-1,a.appendChild(h),this.focus_node=h):i.controlInput?(h=R(i.controlInput),this.focus_node=h):(h=R("
"),this.focus_node=a),this.wrapper=o,this.dropdown=l,this.dropdown_content=c,this.control=a,this.control_input=h,this.setup()}setup(){const e=this,t=e.settings,n=e.control_input,s=e.dropdown,i=e.dropdown_content,r=e.wrapper,o=e.control,l=e.input,c=e.focus_node,d={passive:!0},u=e.inputId+"-ts-dropdown";ee(i,{id:u}),ee(c,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":u});const h=Ce(c,e.inputId+"-ts-control"),p="label[for='"+H(e.inputId)+"']",m=document.querySelector(p),g=e.focus.bind(e);if(m){ke(m,"click",g),ee(m,{for:h});const t=Ce(m,e.inputId+"-ts-label");ee(c,{"aria-labelledby":t}),ee(i,{"aria-labelledby":t})}if(r.style.width=l.style.width,e.plugins.names.length){const t="plugin-"+e.plugins.names.join(" plugin-");z([r,s],t)}(null===t.maxItems||t.maxItems>1)&&e.is_select_tag&&ee(l,{multiple:"multiple"}),t.placeholder&&ee(n,{placeholder:t.placeholder}),!t.splitOn&&t.delimiter&&(t.splitOn=new RegExp("\\s*"+a(t.delimiter)+"+\\s*")),t.load&&t.loadThrottle&&(t.load=Oe(t.load,t.loadThrottle)),ke(s,"mousemove",(()=>{e.ignoreHover=!1})),ke(s,"mouseenter",(t=>{var n=Q(t.target,"[data-selectable]",s);n&&e.onOptionHover(t,n)}),{capture:!0}),ke(s,"click",(t=>{const n=Q(t.target,"[data-selectable]");n&&(e.onOptionSelect(t,n),Ae(t,!0))})),ke(o,"click",(t=>{var s=Q(t.target,"[data-ts-item]",o);s&&e.onItemSelect(t,s)?Ae(t,!0):""==n.value&&(e.onClick(),Ae(t,!0))})),ke(c,"keydown",(t=>e.onKeyDown(t))),ke(n,"keypress",(t=>e.onKeyPress(t))),ke(n,"input",(t=>e.onInput(t))),ke(c,"blur",(t=>e.onBlur(t))),ke(c,"focus",(t=>e.onFocus(t))),ke(n,"paste",(t=>e.onPaste(t)));const f=t=>{const i=t.composedPath()[0];if(!r.contains(i)&&!s.contains(i))return e.isFocused&&e.blur(),void e.inputState();i==n&&e.isOpen?t.stopPropagation():Ae(t,!0)},v=()=>{e.isOpen&&e.positionDropdown()};ke(document,"mousedown",f),ke(window,"scroll",v,d),ke(window,"resize",v,d),this._destroy=()=>{document.removeEventListener("mousedown",f),window.removeEventListener("scroll",v),window.removeEventListener("resize",v),m&&m.removeEventListener("click",g)},this.revertSettings={innerHTML:l.innerHTML,tabIndex:l.tabIndex},l.tabIndex=-1,l.insertAdjacentElement("afterend",e.wrapper),e.sync(!1),t.items=[],delete t.optgroups,delete t.options,ke(l,"invalid",(()=>{e.isValid&&(e.isValid=!1,e.isInvalid=!0,e.refreshState())})),e.updateOriginalInput(),e.refreshItems(),e.close(!1),e.inputState(),e.isSetup=!0,l.disabled?e.disable():l.readOnly?e.setReadOnly(!0):e.enable(),e.on("change",this.onChange),z(l,"tomselected","ts-hidden-accessible"),e.trigger("initialize"),!0===t.preload&&e.preload()}setupOptions(e=[],t=[]){this.addOptions(e),D(t,(e=>{this.registerOptionGroup(e)}))}setupTemplates(){var e=this,t=e.settings.labelField,n=e.settings.optgroupLabelField,s={optgroup:e=>{let t=document.createElement("div");return t.className="optgroup",t.appendChild(e.options),t},optgroup_header:(e,t)=>'",option:(e,n)=>"
"+n(e[t])+"
",item:(e,n)=>"
"+n(e[t])+"
",option_create:(e,t)=>'
Add '+t(e.input)+" …
",no_results:()=>'
No results found
',loading:()=>'
',not_loading:()=>{},dropdown:()=>"
"};e.settings.render=Object.assign({},s,e.settings.render)}setupCallbacks(){var e,t,n={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 n)(t=this.settings[n[e]])&&this.on(e,t)}sync(e=!0){const t=this,n=e?Fe(t.input,{delimiter:t.settings.delimiter}):t.settings;t.setupOptions(n.options,n.optgroups),t.setValue(n.items||[],!0),t.lastQuery=null}onClick(){var e=this;if(e.activeItems.length>0)return e.clearActiveItems(),void e.focus();e.isFocused&&e.isOpen?e.blur():e.focus()}onMouseDown(){}onChange(){U(this.input,"input"),U(this.input,"change")}onPaste(e){var t=this;t.isInputHidden||t.isLocked?Ae(e):t.settings.splitOn&&setTimeout((()=>{var e=t.inputValue();if(e.match(t.settings.splitOn)){var n=e.trim().split(t.settings.splitOn);D(n,(e=>{fe(e)&&(this.options[e]?t.addItem(e):t.createItem(e))}))}}),0)}onKeyPress(e){var t=this;if(!t.isLocked){var n=String.fromCharCode(e.keyCode||e.which);return t.settings.create&&"multi"===t.settings.mode&&n===t.settings.delimiter?(t.createItem(),void Ae(e)):void 0}Ae(e)}onKeyDown(e){var t=this;if(t.ignoreHover=!0,t.isLocked)e.keyCode!==pe&&Ae(e);else{switch(e.keyCode){case ie:if(Se(me,e)&&""==t.control_input.value)return Ae(e),void t.selectAll();break;case oe:return t.isOpen&&(Ae(e,!0),t.close()),void t.clearActiveItems();case de:if(!t.isOpen&&t.hasOptions)t.open();else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1);e&&t.setActiveOption(e)}return void Ae(e);case le:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1);e&&t.setActiveOption(e)}return void Ae(e);case re:return void(t.canSelect(t.activeOption)?(t.onOptionSelect(e,t.activeOption),Ae(e)):(t.settings.create&&t.createItem()||document.activeElement==t.control_input&&t.isOpen)&&Ae(e));case ae:return void t.advanceSelection(-1,e);case ce:return void t.advanceSelection(1,e);case pe:return void(t.settings.selectOnTab&&(t.canSelect(t.activeOption)&&(t.onOptionSelect(e,t.activeOption),Ae(e)),t.settings.create&&t.createItem()&&Ae(e)));case ue:case he:return void t.deleteSelection(e)}t.isInputHidden&&!Se(me,e)&&Ae(e)}}onInput(e){if(this.isLocked)return;const t=this.inputValue();this.lastValue!==t&&(this.lastValue=t,""!=t?(this.refreshTimeout&&clearTimeout(this.refreshTimeout),this.refreshTimeout=ye((()=>{this.refreshTimeout=null,this._onInput()}),this.settings.refreshThrottle)):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,!1)}onFocus(e){var t=this,n=t.isFocused;if(t.isDisabled||t.isReadOnly)return t.blur(),void Ae(e);t.ignoreFocus||(t.isFocused=!0,"focus"===t.settings.preload&&t.preload(),n||t.trigger("focus"),t.activeItems.length||(t.inputState(),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())}onBlur(e){if(!1!==document.hasFocus()){var t=this;if(t.isFocused){t.isFocused=!1,t.ignoreFocus=!1;var n=()=>{t.close(),t.setActiveItem(),t.setCaret(t.items.length),t.trigger("blur")};t.settings.create&&t.settings.createOnBlur?t.createItem(null,n):n()}}}onOptionSelect(e,t){var n,s=this;t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?s.createItem(null,(()=>{s.settings.closeAfterSelect&&s.close()})):void 0!==(n=t.dataset.value)&&(s.lastQuery=null,s.addItem(n),s.settings.closeAfterSelect&&s.close(),!s.settings.hideSelected&&e.type&&/click/.test(e.type)&&s.setActiveOption(t)))}canSelect(e){return!!(this.isOpen&&e&&this.dropdown_content.contains(e))}onItemSelect(e,t){var n=this;return!n.isLocked&&"multi"===n.settings.mode&&(Ae(e),n.setActiveItem(t,e),!0)}canLoad(e){return!!this.settings.load&&!this.loadedSearches.hasOwnProperty(e)}load(e){const t=this;if(!t.canLoad(e))return;z(t.wrapper,t.settings.loadingClass),t.loading++;const n=t.loadCallback.bind(t);t.settings.load.call(t,e,n)}loadCallback(e,t){const n=this;n.loading=Math.max(n.loading-1,0),n.lastQuery=null,n.clearActiveOption(),n.setupOptions(e,t),n.refreshOptions(n.isFocused&&!n.isInputHidden),n.loading||W(n.wrapper,n.settings.loadingClass),n.trigger("load",e,t)}preload(){var e=this.wrapper.classList;e.contains("preloaded")||(e.add("preloaded"),this.load(""))}setTextboxValue(e=""){var t=this.control_input;t.value!==e&&(t.value=e,U(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){Ee(this,t?[]:["change"],(()=>{this.clear(t),this.addItems(e,t)}))}setMaxItems(e){0===e&&(e=null),this.settings.maxItems=e,this.refreshState()}setActiveItem(e,t){var n,s,i,r,o,a,l=this;if("single"!==l.settings.mode){if(!e)return l.clearActiveItems(),void(l.isFocused&&l.inputState());if("click"===(n=t&&t.type.toLowerCase())&&Se("shiftKey",t)&&l.activeItems.length){for(a=l.getLastActive(),(i=Array.prototype.indexOf.call(l.control.children,a))>(r=Array.prototype.indexOf.call(l.control.children,e))&&(o=i,i=r,r=o),s=i;s<=r;s++)e=l.control.children[s],-1===l.activeItems.indexOf(e)&&l.setActiveItemClass(e);Ae(t)}else"click"===n&&Se(me,t)||"keydown"===n&&Se("shiftKey",t)?e.classList.contains("active")?l.removeActiveItem(e):l.setActiveItemClass(e):(l.clearActiveItems(),l.setActiveItemClass(e));l.inputState(),l.isFocused||l.focus()}}setActiveItemClass(e){const t=this,n=t.control.querySelector(".last-active");n&&W(n,"last-active"),z(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),W(e,"active")}clearActiveItems(){W(this.activeItems,"active"),this.activeItems=[]}setActiveOption(e,t=!0){e!==this.activeOption&&(this.clearActiveOption(),e&&(this.activeOption=e,ee(this.focus_node,{"aria-activedescendant":e.getAttribute("id")}),ee(e,{"aria-selected":"true"}),z(e,"active"),t&&this.scrollToOption(e)))}scrollToOption(e,t){if(!e)return;const n=this.dropdown_content,s=n.clientHeight,i=n.scrollTop||0,r=e.offsetHeight,o=e.getBoundingClientRect().top-n.getBoundingClientRect().top+i;o+r>s+i?this.scroll(o-s+r,t):o
{e.setActiveItemClass(t)})))}inputState(){var e=this;e.control.contains(e.control_input)&&(ee(e.control_input,{placeholder:e.settings.placeholder}),e.activeItems.length>0||!e.isFocused&&e.settings.hidePlaceholder&&e.items.length>0?(e.setTextboxValue(),e.isInputHidden=!0):(e.settings.hidePlaceholder&&e.items.length>0&&ee(e.control_input,{placeholder:""}),e.isInputHidden=!1),e.wrapper.classList.toggle("input-hidden",e.isInputHidden))}inputValue(){return this.control_input.value.trim()}focus(){var e=this;e.isDisabled||e.isReadOnly||(e.ignoreFocus=!0,e.control_input.offsetWidth?e.control_input.focus():e.focus_node.focus(),setTimeout((()=>{e.ignoreFocus=!1,e.onFocus()}),0))}blur(){this.focus_node.blur(),this.onBlur()}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e=this.settings,t=e.sortField;return"string"==typeof e.sortField&&(t=[{field:e.sortField}]),{fields:e.searchField,conjunction:e.searchConjunction,sort:t,nesting:e.nesting}}search(e){var t,n,s=this,i=this.getSearchOptions();if(s.settings.score&&"function"!=typeof(n=s.settings.score.call(s,e)))throw new Error('Tom Select "score" setting must be a function that returns a function');return e!==s.lastQuery?(s.lastQuery=e,t=s.sifter.search(e,Object.assign(i,{score:n})),s.currentResults=t):t=Object.assign({},s.currentResults),s.settings.hideSelected&&(t.items=t.items.filter((e=>{let t=fe(e.id);return!(t&&-1!==s.items.indexOf(t))}))),t}refreshOptions(e=!0){var t,n,s,i,r,o,a,l,c,d;const u={},h=[];var p=this,m=p.inputValue();const g=m===p.lastQuery||""==m&&null==p.lastQuery;var f=p.search(m),v=null,b=p.settings.shouldOpen||!1,y=p.dropdown_content;g&&(v=p.activeOption)&&(c=v.closest("[data-group]")),i=f.items.length,"number"==typeof p.settings.maxOptions&&(i=Math.min(i,p.settings.maxOptions)),i>0&&(b=!0);const O=(e,t)=>{let n=u[e];if(void 0!==n){let e=h[n];if(void 0!==e)return[n,e.fragment]}let s=document.createDocumentFragment();return n=h.length,h.push({fragment:s,order:t,optgroup:e}),[n,s]};for(t=0;t0&&(d=d.cloneNode(!0),ee(d,{id:a.$id+"-clone-"+n,"aria-selected":null}),d.classList.add("ts-cloned"),W(d,"active"),p.activeOption&&p.activeOption.dataset.value==i&&c&&c.dataset.group===r.toString()&&(v=d)),l.appendChild(d),""!=r&&(u[r]=s)}}p.settings.lockOptgroupOrder&&h.sort(((e,t)=>e.order-t.order)),a=document.createDocumentFragment(),D(h,(e=>{let t=e.fragment,n=e.optgroup;if(!t||!t.children.length)return;let s=p.optgroups[n];if(void 0!==s){let e=document.createDocumentFragment(),n=p.render("optgroup_header",s);Te(e,n),Te(e,t);let i=p.render("optgroup",{group:s,options:e});Te(a,i)}else Te(a,t)})),y.innerHTML="",Te(y,a),p.settings.highlight&&(se(y),f.query.length&&f.tokens.length&&D(f.tokens,(e=>{ne(y,e.regex)})));var E=e=>{let t=p.render(e,{input:m});return t&&(b=!0,y.insertBefore(t,y.firstChild)),t};if(p.loading?E("loading"):p.settings.shouldLoad.call(p,m)?0===f.items.length&&E("no_results"):E("not_loading"),(l=p.canCreate(m))&&(d=E("option_create")),p.hasOptions=f.items.length>0||l,b){if(f.items.length>0){if(v||"single"!==p.settings.mode||null==p.items[0]||(v=p.getOption(p.items[0])),!y.contains(v)){let e=0;d&&!p.settings.addPrecedence&&(e=1),v=p.selectable()[e]}}else d&&(v=d);e&&!p.isOpen&&(p.open(),p.scrollToOption(v,"auto")),p.setActiveOption(v)}else p.clearActiveOption(),e&&p.isOpen&&p.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e,t=!1){const n=this;if(Array.isArray(e))return n.addOptions(e,t),!1;const s=fe(e[n.settings.valueField]);return null!==s&&!n.options.hasOwnProperty(s)&&(e.$order=e.$order||++n.order,e.$id=n.inputId+"-opt-"+e.$order,n.options[s]=e,n.lastQuery=null,t&&(n.userOptions[s]=t,n.trigger("option_add",s,e)),s)}addOptions(e,t=!1){D(e,(e=>{this.addOption(e,t)}))}registerOption(e){return this.addOption(e)}registerOptionGroup(e){var t=fe(e[this.settings.optgroupValueField]);return null!==t&&(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var n;t[this.settings.optgroupValueField]=e,(n=this.registerOptionGroup(t))&&this.trigger("optgroup_add",n,t)}removeOptionGroup(e){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 n=this;var s,i;const r=fe(e),o=fe(t[n.settings.valueField]);if(null===r)return;const a=n.options[r];if(null==a)return;if("string"!=typeof o)throw new Error("Value must be set in option data");const l=n.getOption(r),c=n.getItem(r);if(t.$order=t.$order||a.$order,delete n.options[r],n.uncacheValue(o),n.options[o]=t,l){if(n.dropdown_content.contains(l)){const e=n._render("option",t);te(l,e),n.activeOption===l&&n.setActiveOption(e)}l.remove()}c&&(-1!==(i=n.items.indexOf(r))&&n.items.splice(i,1,o),s=n._render("item",t),c.classList.contains("active")&&z(s,"active"),te(c,s)),n.lastQuery=null}removeOption(e,t){const n=this;e=ve(e),n.uncacheValue(e),delete n.userOptions[e],delete n.options[e],n.lastQuery=null,n.trigger("option_remove",e),n.removeItem(e,t)}clearOptions(e){const t=(e||this.clearFilter).bind(this);this.loadedSearches={},this.userOptions={},this.clearCache();const n={};D(this.options,((e,s)=>{t(e,s)&&(n[s]=e)})),this.options=this.sifter.items=n,this.lastQuery=null,this.trigger("option_clear")}clearFilter(e,t){return this.items.indexOf(t)>=0}getOption(e,t=!1){const n=fe(e);if(null===n)return null;const s=this.options[n];if(null!=s){if(s.$div)return s.$div;if(t)return this._render("option",s)}return null}getAdjacent(e,t,n="option"){var s,i=this;if(!e)return null;s="item"==n?i.controlChildren():i.dropdown_content.querySelectorAll("[data-selectable]");for(let n=0;n0?s[n+1]:s[n-1];return null}getItem(e){if("object"==typeof e)return e;var t=fe(e);return null!==t?this.control.querySelector(`[data-value="${Me(t)}"]`):null}addItems(e,t){var n=this,s=Array.isArray(e)?e:[e];const i=(s=s.filter((e=>-1===n.items.indexOf(e))))[s.length-1];s.forEach((e=>{n.isPending=e!==i,n.addItem(e,t)}))}addItem(e,t){Ee(this,t?[]:["change","dropdown_close"],(()=>{var n,s;const i=this,r=i.settings.mode,o=fe(e);if((!o||-1===i.items.indexOf(o)||("single"===r&&i.close(),"single"!==r&&i.settings.duplicates))&&null!==o&&i.options.hasOwnProperty(o)&&("single"===r&&i.clear(t),"multi"!==r||!i.isFull())){if(n=i._render("item",i.options[o]),i.control.contains(n)&&(n=n.cloneNode(!0)),s=i.isFull(),i.items.splice(i.caretPos,0,o),i.insertAtCaret(n),i.isSetup){if(!i.isPending&&i.settings.hideSelected){let e=i.getOption(o),t=i.getAdjacent(e,1);t&&i.setActiveOption(t)}i.isPending||i.settings.closeAfterSelect||i.refreshOptions(i.isFocused&&"single"!==r),0!=i.settings.closeAfterSelect&&i.isFull()?i.close():i.isPending||i.positionDropdown(),i.trigger("item_add",o,n),i.isPending||i.updateOriginalInput({silent:t})}(!i.isPending||!s&&i.isFull())&&(i.inputState(),i.refreshState())}}))}removeItem(e=null,t){const n=this;if(!(e=n.getItem(e)))return;var s,i;const r=e.dataset.value;s=Z(e),e.remove(),e.classList.contains("active")&&(i=n.activeItems.indexOf(e),n.activeItems.splice(i,1),W(e,"active")),n.items.splice(s,1),n.lastQuery=null,!n.settings.persist&&n.userOptions.hasOwnProperty(r)&&n.removeOption(r,t),s{}){3===arguments.length&&(t=arguments[2]),"function"!=typeof t&&(t=()=>{});var n,s=this,i=s.caretPos;if(e=e||s.inputValue(),!s.canCreate(e))return t(),!1;s.lock();var r=!1,o=e=>{if(s.unlock(),!e||"object"!=typeof e)return t();var n=fe(e[s.settings.valueField]);if("string"!=typeof n)return t();s.setTextboxValue(),s.addOption(e,!0),s.setCaret(i),s.addItem(n),t(e),r=!0};return n="function"==typeof s.settings.create?s.settings.create.call(this,e,o):{[s.settings.labelField]:e,[s.settings.valueField]:e},r||o(n),!0}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(),n=e.isLocked;e.wrapper.classList.toggle("rtl",e.rtl);const s=e.wrapper.classList;s.toggle("focus",e.isFocused),s.toggle("disabled",e.isDisabled),s.toggle("readonly",e.isReadOnly),s.toggle("required",e.isRequired),s.toggle("invalid",!e.isValid),s.toggle("locked",n),s.toggle("full",t),s.toggle("input-active",e.isFocused&&!e.isInputHidden),s.toggle("dropdown-active",e.isOpen),s.toggle("has-options",Y(e.options)),s.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this;e.input.validity&&(e.isValid=e.input.validity.valid,e.isInvalid=!e.isValid)}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){const t=this;var n,s;const i=t.input.querySelector('option[value=""]');if(t.is_select_tag){const r=[],o=t.input.querySelectorAll("option:checked").length;function a(e,n,s){return e||(e=R(''+be(s)+" ")),e!=i&&t.input.append(e),r.push(e),(e!=i||o>0)&&(e.selected=!0),e}t.input.querySelectorAll("option:checked").forEach((e=>{e.selected=!1})),0==t.items.length&&"single"==t.settings.mode?a(i,"",""):t.items.forEach((e=>{n=t.options[e],s=n[t.settings.labelField]||"",r.includes(n.$option)?a(t.input.querySelector(`option[value="${Me(e)}"]:not(:checked)`),e,s):n.$option=a(n.$option,e,s)}))}else t.input.value=t.getValue();t.isSetup&&(e.silent||t.trigger("change",t.getValue()))}open(){var e=this;e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull()||(e.isOpen=!0,ee(e.focus_node,{"aria-expanded":"true"}),e.refreshState(),K(e.dropdown,{visibility:"hidden",display:"block"}),e.positionDropdown(),K(e.dropdown,{visibility:"visible",display:"block"}),e.focus(),e.trigger("dropdown_open",e.dropdown))}close(e=!0){var t=this,n=t.isOpen;e&&(t.setTextboxValue(),"single"===t.settings.mode&&t.items.length&&t.inputState()),t.isOpen=!1,ee(t.focus_node,{"aria-expanded":"false"}),K(t.dropdown,{display:"none"}),t.settings.hideSelected&&t.clearActiveOption(),t.refreshState(),n&&t.trigger("dropdown_close",t.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var e=this.control,t=e.getBoundingClientRect(),n=e.offsetHeight+t.top+window.scrollY,s=t.left+window.scrollX;K(this.dropdown,{width:t.width+"px",top:n+"px",left:s+"px"})}}clear(e){var t=this;if(t.items.length){var n=t.controlChildren();D(n,(e=>{t.removeItem(e,!0)})),t.inputState(),e||t.updateOriginalInput(),t.trigger("clear")}}insertAtCaret(e){const t=this,n=t.caretPos,s=t.control;s.insertBefore(e,s.children[n]||null),t.setCaret(n+1)}deleteSelection(e){var t,n,s,i,r=this;t=e&&e.keyCode===ue?-1:1,n=we(r.control_input);const o=[];if(r.activeItems.length)i=X(r.activeItems,t),s=Z(i),t>0&&s++,D(r.activeItems,(e=>o.push(e)));else if((r.isFocused||"single"===r.settings.mode)&&r.items.length){const e=r.controlChildren();let s;t<0&&0===n.start&&0===n.length?s=e[r.caretPos-1]:t>0&&n.start===r.inputValue().length&&(s=e[r.caretPos]),void 0!==s&&o.push(s)}if(!r.shouldDelete(o,e))return!1;for(Ae(e,!0),void 0!==s&&r.setCaret(s);o.length;)r.removeItem(o.pop());return r.inputState(),r.positionDropdown(),r.refreshOptions(!1),!0}shouldDelete(e,t){const n=e.map((e=>e.dataset.value));return!(!n.length||"function"==typeof this.settings.onDelete&&!1===this.settings.onDelete(n,t))}advanceSelection(e,t){var n,s,i=this;i.rtl&&(e*=-1),i.inputValue().length||(Se(me,t)||Se("shiftKey",t)?(s=(n=i.getLastActive(e))?n.classList.contains("active")?i.getAdjacent(n,e,"item"):n:e>0?i.control_input.nextElementSibling:i.control_input.previousElementSibling)&&(s.classList.contains("active")&&i.removeActiveItem(n),i.setActiveItemClass(s)):i.moveCaret(e))}moveCaret(e){}getLastActive(e){let t=this.control.querySelector(".last-active");if(t)return t;var n=this.control.querySelectorAll(".active");return n?X(n,e):void 0}setCaret(e){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.setLocked(!0)}unlock(){this.setLocked(!1)}setLocked(e=this.isReadOnly||this.isDisabled){this.isLocked=e,this.refreshState()}disable(){this.setDisabled(!0),this.close()}enable(){this.setDisabled(!1)}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,t=e.revertSettings;e.trigger("destroy"),e.off(),e.wrapper.remove(),e.dropdown.remove(),e.input.innerHTML=t.innerHTML,e.input.tabIndex=t.tabIndex,W(e.input,"tomselected","ts-hidden-accessible"),e._destroy(),delete e.input.tomselect}render(e,t){var n,s;const i=this;if("function"!=typeof this.settings.render[e])return null;if(!(s=i.settings.render[e].call(this,t,be)))return null;if(s=R(s),"option"===e||"option_create"===e?t[i.settings.disabledField]?ee(s,{"aria-disabled":"true"}):ee(s,{"data-selectable":""}):"optgroup"===e&&(n=t.group[i.settings.optgroupValueField],ee(s,{"data-group":n}),t.group[i.settings.disabledField]&&ee(s,{"data-disabled":""})),"option"===e||"item"===e){const n=ve(t[i.settings.valueField]);ee(s,{"data-value":n}),"item"===e?(z(s,i.settings.itemClass),ee(s,{"data-ts-item":""})):(z(s,i.settings.optionClass),ee(s,{role:"option",id:t.$id}),t.$div=s,i.options[n]=t)}return s}_render(e,t){const n=this.render(e,t);if(null==n)throw"HTMLElement expected";return n}clearCache(){D(this.options,(e=>{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,n){var s=this,i=s[t];s[t]=function(){var t,r;return"after"===e&&(t=i.apply(s,arguments)),r=n.apply(s,arguments),"instead"===e?r:("before"===e&&(t=i.apply(s,arguments)),t)}}}function Le(){ke(this.input,"change",(()=>{this.sync()}))}function Ne(e){var t=this,n=t.onOptionSelect;t.settings.hideSelected=!1;const s=Object.assign({className:"tomselect-checkbox",checkedClassNames:void 0,uncheckedClassNames:void 0},e);var i=function(e,t){t?(e.checked=!0,s.uncheckedClassNames&&e.classList.remove(...s.uncheckedClassNames),s.checkedClassNames&&e.classList.add(...s.checkedClassNames)):(e.checked=!1,s.checkedClassNames&&e.classList.remove(...s.checkedClassNames),s.uncheckedClassNames&&e.classList.add(...s.uncheckedClassNames))},r=function(e){setTimeout((()=>{var t=e.querySelector("input."+s.className);t instanceof HTMLInputElement&&i(t,e.classList.contains("selected"))}),1)};t.hook("after","setupTemplates",(()=>{var e=t.settings.render.option;t.settings.render.option=(n,r)=>{var o=R(e.call(t,n,r)),a=document.createElement("input");s.className&&a.classList.add(s.className),a.addEventListener("click",(function(e){Ae(e)})),a.type="checkbox";const l=fe(n[t.settings.valueField]);return i(a,!!(l&&t.items.indexOf(l)>-1)),o.prepend(a),o}})),t.on("item_remove",(e=>{var n=t.getOption(e);n&&(n.classList.remove("selected"),r(n))})),t.on("item_add",(e=>{var n=t.getOption(e);n&&r(n)})),t.hook("instead","onOptionSelect",((e,s)=>{if(s.classList.contains("selected"))return s.classList.remove("selected"),t.removeItem(s.dataset.value),t.refreshOptions(),void Ae(e,!0);n.call(t,e,s),r(s)}))}function Pe(e){const t=this,n=Object.assign({className:"clear-button",title:"Clear All",html:e=>`⨯
`},e);t.on("initialize",(()=>{var e=R(n.html(n));e.addEventListener("click",(e=>{t.isLocked||(t.clear(),"single"===t.settings.mode&&t.settings.allowEmptyOption&&t.addItem(""),e.preventDefault(),e.stopPropagation())})),t.control.appendChild(e)}))}const _e=(e,t)=>{var n;null==(n=e.parentNode)||n.insertBefore(t,e.nextSibling)},$e=(e,t)=>{var n;null==(n=e.parentNode)||n.insertBefore(t,e)},De=(e,t)=>{do{var n;if(e==(t=null==(n=t)?void 0:n.previousElementSibling))return!0}while(t&&t.previousElementSibling);return!1};function Ve(){var e=this;if("multi"!==e.settings.mode)return;var t=e.lock,n=e.unlock;let s,i=!0;e.hook("after","setupTemplates",(()=>{var t=e.settings.render.item;e.settings.render.item=(n,r)=>{const o=R(t.call(e,n,r));ee(o,{draggable:"true"});const a=e=>{s=o,setTimeout((()=>{o.classList.add("ts-dragging")}),0)},l=e=>{e.preventDefault(),o.classList.add("ts-drag-over"),d(o,s)},c=()=>{o.classList.remove("ts-drag-over")},d=(e,t)=>{void 0!==t&&(De(t,o)?_e(e,t):$e(e,t))},u=()=>{var t;document.querySelectorAll(".ts-drag-over").forEach((e=>e.classList.remove("ts-drag-over"))),null==(t=s)||t.classList.remove("ts-dragging"),s=void 0;var n=[];e.control.querySelectorAll("[data-value]").forEach((e=>{if(e.dataset.value){let t=e.dataset.value;t&&n.push(t)}})),e.setValue(n)};return ke(o,"mousedown",(e=>{i||Ae(e),e.stopPropagation()})),ke(o,"dragstart",a),ke(o,"dragenter",l),ke(o,"dragover",l),ke(o,"dragleave",c),ke(o,"dragend",u),o}})),e.hook("instead","lock",(()=>(i=!1,t.call(e)))),e.hook("instead","unlock",(()=>(i=!0,n.call(e))))}function je(e){const t=this,n=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:e=>''},e);t.on("initialize",(()=>{var e=R(n.html(n)),s=e.querySelector("."+n.closeClass);s&&s.addEventListener("click",(e=>{Ae(e,!0),t.close()})),t.dropdown.insertBefore(e,t.dropdown.firstChild)}))}function Be(){var e=this;e.hook("instead","setCaret",(t=>{"single"!==e.settings.mode&&e.control.contains(e.control_input)?(t=Math.max(0,Math.min(e.items.length,t)))==e.caretPos||e.isPending||e.controlChildren().forEach(((n,s)=>{s{if(!e.isFocused)return;const n=e.getLastActive(t);if(n){const s=Z(n);e.setCaret(t>0?s+1:s),e.setActiveItem(),W(n,"last-active")}else e.setCaret(e.caretPos+t)}))}function Re(){const e=this;e.settings.shouldOpen=!0,e.hook("before","setup",(()=>{e.focus_node=e.control,z(e.control_input,"dropdown-input");const t=R('');t.append(e.control_input),e.dropdown.insertBefore(t,e.dropdown.firstChild);const n=R('
');n.placeholder=e.settings.placeholder||"",e.control.append(n)})),e.on("initialize",(()=>{e.control_input.addEventListener("keydown",(t=>{switch(t.keyCode){case oe:return e.isOpen&&(Ae(t,!0),e.close()),void e.clearActiveItems();case pe:e.focus_node.tabIndex=-1}return e.onKeyDown.call(e,t)})),e.on("blur",(()=>{e.focus_node.tabIndex=e.isDisabled?-1:e.tabIndex})),e.on("dropdown_open",(()=>{e.control_input.focus()}));const t=e.onBlur;e.hook("instead","onBlur",(n=>{if(!n||n.relatedTarget!=e.control_input)return t.call(e)})),ke(e.control_input,"blur",(()=>e.onBlur())),e.hook("before","close",(()=>{e.isOpen&&e.focus_node.focus({preventScroll:!0})}))}))}function qe(){var e=this;e.on("initialize",(()=>{var t=document.createElement("span"),n=e.control_input;t.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ",e.wrapper.appendChild(t);var s=["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"];for(const e of s)t.style[e]=n.style[e];var i=()=>{t.textContent=n.value,n.style.width=t.clientWidth+"px"};i(),e.on("update item_add item_remove",i),ke(n,"input",i),ke(n,"keyup",i),ke(n,"blur",i),ke(n,"update",i)}))}function He(){var e=this,t=e.deleteSelection;this.hook("instead","deleteSelection",(n=>!!e.activeItems.length&&t.call(e,n)))}function Ue(){this.hook("instead","setActiveItem",(()=>{})),this.hook("instead","selectAll",(()=>{}))}function Ke(){var e=this,t=e.onKeyDown;e.hook("instead","onKeyDown",(n=>{var s,i,r,o;if(!e.isOpen||n.keyCode!==ae&&n.keyCode!==ce)return t.call(e,n);e.ignoreHover=!0,o=Q(e.activeOption,"[data-group]"),s=Z(e.activeOption,"[data-selectable]"),o&&(o=n.keyCode===ae?o.previousSibling:o.nextSibling)&&(i=(r=o.querySelectorAll("[data-selectable]"))[Math.min(r.length-1,s)])&&e.setActiveOption(i)}))}function ze(e){const t=Object.assign({label:"×",title:"Remove",className:"remove",append:!0},e);var n=this;if(t.append){var s='
'+t.label+" ";n.hook("after","setupTemplates",(()=>{var e=n.settings.render.item;n.settings.render.item=(t,i)=>{var r=R(e.call(n,t,i)),o=R(s);return r.appendChild(o),ke(o,"mousedown",(e=>{Ae(e,!0)})),ke(o,"click",(e=>{n.isLocked||(Ae(e,!0),n.isLocked||n.shouldDelete([r],e)&&(n.removeItem(r),n.refreshOptions(!1),n.inputState()))})),r}}))}}function We(e){const t=this,n=Object.assign({text:e=>e[t.settings.labelField]},e);t.on("item_remove",(function(e){if(t.isFocused&&""===t.control_input.value.trim()){var s=t.options[e];s&&t.setTextboxValue(n.text.call(t,s))}}))}function Je(){const e=this,t=e.canLoad,n=e.clearActiveOption,s=e.loadCallback;var i,r,o={},a=!1,l=[];if(e.settings.shouldLoadMore||(e.settings.shouldLoadMore=()=>{if(i.clientHeight/(i.scrollHeight-i.scrollTop)>.9)return!0;if(e.activeOption){var t=e.selectable();if(Array.from(t).indexOf(e.activeOption)>=t.length-2)return!0}return!1}),!e.settings.firstUrl)throw"virtual_scroll plugin requires a firstUrl() method";e.settings.sortField=[{field:"$order"},{field:"$score"}];const c=t=>!("number"==typeof e.settings.maxOptions&&i.children.length>=e.settings.maxOptions||!(t in o)||!o[t]),d=(t,n)=>e.items.indexOf(n)>=0||l.indexOf(n)>=0;e.setNextUrl=(e,t)=>{o[e]=t},e.getUrl=t=>{if(t in o){const e=o[t];return o[t]=!1,e}return e.clearPagination(),e.settings.firstUrl.call(e,t)},e.clearPagination=()=>{o={}},e.hook("instead","clearActiveOption",(()=>{if(!a)return n.call(e)})),e.hook("instead","canLoad",(n=>n in o?c(n):t.call(e,n))),e.hook("instead","loadCallback",((t,n)=>{if(a){if(r){const n=t[0];void 0!==n&&(r.dataset.value=n[e.settings.valueField])}}else e.clearOptions(d);s.call(e,t,n),a=!1})),e.hook("after","refreshOptions",(()=>{const t=e.lastValue;var n;c(t)?(n=e.render("loading_more",{query:t}))&&(n.setAttribute("data-selectable",""),r=n):t in o&&!i.querySelector(".no-results")&&(n=e.render("no_more_results",{query:t})),n&&(z(n,e.settings.optionClass),i.append(n))})),e.on("initialize",(()=>{l=Object.keys(e.options),i=e.dropdown_content,e.settings.render=Object.assign({},{loading_more:()=>'
Loading more results ...
',no_more_results:()=>'
No more results
'},e.settings.render),i.addEventListener("scroll",(()=>{e.settings.shouldLoadMore.call(e)&&c(e.lastValue)&&(a||(a=!0,e.load.call(e,e.lastValue)))}))}))}return Ie.define("change_listener",Le),Ie.define("checkbox_options",Ne),Ie.define("clear_button",Pe),Ie.define("drag_drop",Ve),Ie.define("dropdown_header",je),Ie.define("caret_position",Be),Ie.define("dropdown_input",Re),Ie.define("input_autogrow",qe),Ie.define("no_backspace_delete",He),Ie.define("no_active_items",Ue),Ie.define("optgroup_columns",Ke),Ie.define("remove_button",ze),Ie.define("restore_on_backspace",We),Ie.define("virtual_scroll",Je),Ie}()}},t={};function n(s){var i=t[s];if(void 0!==i)return i.exports;var r=t[s]={exports:{}};return e[s].call(r.exports,r,r.exports,n),r.exports}n.d=(e,t)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{"use strict";var e=n(891),t=n(371);function s(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function i(e,t,n){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:n;throw new TypeError("Private element is not present on this object")}function r(e,t){return e.get(i(e,t))}var o=new WeakSet,a=new WeakMap,l=class extends e.xI{constructor(...e){var t,n;super(...e),s(t=this,n=o),n.add(t),this.isObserving=!1,this.hasLoadedChoicesPreviously=!1,this.originalOptions=[],function(e,t,n){s(e,t),t.set(e,n)}(this,a,(e=>Array.isArray(e)?e.reduce(((e,t)=>("string"==typeof t&&(e[t]={}),"object"==typeof t&&t.name&&(e[t.name]=t.options||{}),e)),{}):e))}initialize(){this.mutationObserver||(this.mutationObserver=new MutationObserver((e=>{this.onMutations(e)})))}connect(){this.selectElement&&(this.originalOptions=this.createOptionsDataStructure(this.selectElement)),this.initializeTomSelect()}initializeTomSelect(){this.selectElement&&this.selectElement.setAttribute("data-skip-morph",""),this.urlValue?this.tomSelect=i(o,this,h).call(this,this.urlValue,this.hasMinCharactersValue?this.minCharactersValue:null):this.optionsAsHtmlValue?this.tomSelect=i(o,this,u).call(this):(this.tomSelect=i(o,this,d).call(this),this.startMutationObserver())}disconnect(){if(this.stopMutationObserver(),!this.tomSelect)return;let e=[];this.selectElement&&(e=this.selectElement.multiple?Array.from(this.selectElement.options).filter((e=>e.selected)).map((e=>e.value)):[this.selectElement.value]),this.tomSelect.destroy(),this.tomSelect=void 0,this.selectElement&&(this.selectElement.multiple?Array.from(this.selectElement.options).forEach((t=>{t.selected=e.includes(t.value)})):this.selectElement.value=e[0])}urlValueChanged(){this.resetTomSelect()}getMaxOptions(){return this.selectElement?this.selectElement.options.length:50}get selectElement(){return this.element instanceof HTMLSelectElement?this.element:null}get formElement(){if(!(this.element instanceof HTMLInputElement||this.element instanceof HTMLSelectElement))throw new Error("Autocomplete Stimulus controller can only be used on an
or
.");return this.element}dispatchEvent(e,t){this.dispatch(e,{detail:t,prefix:"autocomplete"})}get preload(){return this.hasPreloadValue?"false"!==this.preloadValue&&("true"===this.preloadValue||this.preloadValue):"focus"}resetTomSelect(){if(this.tomSelect){this.dispatchEvent("before-reset",{tomSelect:this.tomSelect}),this.stopMutationObserver();const e=this.element.innerHTML,t=this.tomSelect.getValue();this.tomSelect.destroy(),this.element.innerHTML=e,this.initializeTomSelect(),this.tomSelect.setValue(t)}}changeTomSelectDisabledState(e){this.tomSelect&&(this.stopMutationObserver(),e?this.tomSelect.disable():this.tomSelect.enable(),this.startMutationObserver())}startMutationObserver(){!this.isObserving&&this.mutationObserver&&(this.mutationObserver.observe(this.element,{childList:!0,subtree:!0,attributes:!0,characterData:!0,attributeOldValue:!0}),this.isObserving=!0)}stopMutationObserver(){this.isObserving&&this.mutationObserver&&(this.mutationObserver.disconnect(),this.isObserving=!1)}onMutations(e){let t=!1,n=!1;e.forEach((e=>{switch(e.type){case"attributes":if(e.target===this.element&&"disabled"===e.attributeName){t=!0;break}if(e.target===this.element&&"multiple"===e.attributeName){this.element.hasAttribute("multiple")!==("multiple"===e.oldValue)&&(n=!0);break}}}));const s=this.selectElement?this.createOptionsDataStructure(this.selectElement):[];this.areOptionsEquivalent(s)&&!n||(this.originalOptions=s,this.resetTomSelect()),t&&this.changeTomSelectDisabledState(this.formElement.disabled)}createOptionsDataStructure(e){return Array.from(e.options).map((e=>({value:e.value,text:e.text})))}areOptionsEquivalent(e){const t=this.originalOptions.filter((e=>""!==e.value)),n=e.filter((e=>""!==e.value)),s=this.originalOptions.find((e=>""===e.value)),i=e.find((e=>""===e.value));if(s&&i&&s.text!==i.text)return!1;if(t.length!==n.length)return!1;const r=e=>`${e.value}-${e.text}`,o=new Set(t.map(r)),a=new Set(n.map(r));return o.size===a.size&&[...o].every((e=>a.has(e)))}};function c(){const e={},t=!this.selectElement||this.selectElement.multiple;this.formElement.disabled||t||(e.clear_button={title:""}),t&&(e.remove_button={title:""}),this.urlValue&&(e.virtual_scroll={});const n={render:{no_results:()=>`${this.noResultsFoundTextValue}
`,option_create:(e,t)=>`${this.createOptionTextValue.replace("%placeholder%",`${t(e.input)} `)}
`},plugins:e,onItemAdd:()=>{this.tomSelect?.setTextboxValue("")},closeAfterSelect:!0,onOptionAdd:(e,t)=>{if(!this.tomSelect)return;let n=this.tomSelect.input,s=null;const i=t[this.tomSelect.settings.optgroupField];if(i&&this.tomSelect.optgroups&&(s=this.tomSelect.optgroups[i],s)){const e=n.querySelector(`optgroup[label="${s.label}"]`);e&&(n=e)}const r=document.createElement("option");r.value=e,r.text=t[this.tomSelect.settings.labelField];const o=t.$order;let a=null;for(const[,e]of Object.entries(this.tomSelect.options))if(e.$order===o){a=n.querySelector(`:scope > option[value="${CSS.escape(e[this.tomSelect.settings.valueField])}"]`);break}a?a.insertAdjacentElement("afterend",r):o>=0?n.append(r):n.prepend(r)}};return this.selectElement||this.urlValue||(n.shouldLoad=()=>!1),i(o,this,m).call(this,n,this.tomSelectOptionsValue)}function d(){const e=i(o,this,m).call(this,i(o,this,c).call(this),{maxOptions:this.getMaxOptions()});return i(o,this,f).call(this,e)}function u(){const e=i(o,this,c).call(this),t=e.labelField??"text",n=i(o,this,m).call(this,e,{maxOptions:this.getMaxOptions(),score:e=>{const n=this.tomSelect?.getScoreFunction(e);return e=>n?.({...e,text:i(o,this,p).call(this,e[t])})},render:{...e.render,item:e=>`${e[t]}
`,option:e=>`${e[t]}
`}});return i(o,this,f).call(this,n)}function h(e,t){const n=i(o,this,c).call(this),s=n.labelField??"text",r=i(o,this,m).call(this,n,{firstUrl:t=>`${e}${e.includes("?")?"&":"?"}query=${encodeURIComponent(t)}`,load:function(e,t){const n=this.getUrl(e);fetch(n).then((e=>e.json())).then((n=>{this.setNextUrl(e,n.next_page),t(n.results.options||n.results,n.results.optgroups||[])})).catch((()=>t([],[])))},shouldLoad:e=>null!==t?e.length>=t:!!this.hasLoadedChoicesPreviously||(e.length>0&&(this.hasLoadedChoicesPreviously=!0),e.length>=3),optgroupField:"group_by",score:e=>e=>1,render:{option:e=>`${e[s]}
`,item:e=>`${e[s]}
`,loading_more:()=>`${this.loadingMoreTextValue}
`,no_more_results:()=>`${this.noMoreResultsTextValue}
`,no_results:()=>`${this.noResultsFoundTextValue}
`,option_create:(e,t)=>`${this.createOptionTextValue.replace("%placeholder%",`${t(e.input)} `)}
`},onFocus:()=>{this.resetOnFocusValue&&this.tomSelect&&""===this.tomSelect.control_input.value.trim()&&(this.tomSelect.clearOptions(),this.tomSelect.loadedSearches={},"function"==typeof this.tomSelect.clearPagination&&this.tomSelect.clearPagination(),this.tomSelect.load(""))},preload:this.preload});return i(o,this,f).call(this,r)}function p(e){return e.replace(/(<([^>]+)>)/gi,"")}function m(e,t){return{...e,...t,plugins:i(o,this,g).call(this,{...r(a,this).call(this,e.plugins||{}),...r(a,this).call(this,t.plugins||{})})}}function g(e){return Object.entries(e).reduce(((e,[t,n])=>(!1!==n&&(e[t]=n),e)),{})}function f(e){const n={options:e};this.dispatchEvent("pre-connect",n);const s=new t(this.formElement,e),i={tomSelect:s,options:e};return this.dispatchEvent("connect",i),s}l.values={url:String,optionsAsHtml:Boolean,loadingMoreText:String,noResultsFoundText:String,noMoreResultsText:String,createOptionText:String,minCharacters:Number,tomSelectOptions:Object,preload:String,resetOnFocus:Boolean};var v=class{constructor(e,t,n){this.isResolved=!1,this.promise=e,this.promise.then((e=>(this.isResolved=!0,e))),this.actions=t,this.updatedModels=n}containsOneOfActions(e){return this.actions.filter((t=>e.includes(t))).length>0}areAnyModelsUpdated(e){return this.updatedModels.filter((t=>e.includes(t))).length>0}},b=class{constructor(e,t="post",n="same-origin"){this.url=e,this.method=t,this.credentials=n}buildRequest(e,t,n,s,i,r){const o=this.url.split("?");let[a]=o;const[,l]=o,c=new URLSearchParams(l||""),d={};d.credentials=this.credentials,d.headers={Accept:"application/vnd.live-component+html","X-Requested-With":"XMLHttpRequest","X-Live-Url":window.location.pathname+window.location.search};const u=Object.entries(r).reduce(((e,t)=>e+t.length),0),h=Object.keys(s).length>0;if(0===t.length&&0===u&&"get"===this.method&&this.willDataFitInUrl(JSON.stringify(e),JSON.stringify(n),c,JSON.stringify(s),JSON.stringify(i)))c.set("props",JSON.stringify(e)),c.set("updated",JSON.stringify(n)),Object.keys(i).length>0&&c.set("propsFromParent",JSON.stringify(i)),h&&c.set("children",JSON.stringify(s)),d.method="GET";else{d.method="POST";const o={props:e,updated:n};Object.keys(i).length>0&&(o.propsFromParent=i),h&&(o.children=s),t.length>0&&(1===t.length?(o.args=t[0].args,a+=`/${encodeURIComponent(t[0].name)}`):(a+="/_batch",o.actions=t));const l=new FormData;l.append("data",JSON.stringify(o));for(const[e,t]of Object.entries(r)){const n=t.length;for(let s=0;s0?`?${p}`:""}`,fetchOptions:d}}willDataFitInUrl(e,t,n,s,i){return(new URLSearchParams(e+t+s+i).toString()+n.toString()).length<1500}},y=class{constructor(e,t="post",n="same-origin"){this.requestBuilder=new b(e,t,n)}makeRequest(e,t,n,s,i,r){const{url:o,fetchOptions:a}=this.requestBuilder.buildRequest(e,t,n,s,i,r);return new v(fetch(o,a),t.map((e=>e.name)),Object.keys(n))}},O=class{constructor(e){this.response=e}async getBody(){return this.body||(this.body=await this.response.text()),this.body}getLiveUrl(){return void 0===this.liveUrl&&(this.liveUrl=this.response.headers.get("X-Live-Url")),this.liveUrl}};function E(e){return e.innerHTML?e.outerHTML.slice(0,e.outerHTML.indexOf(e.innerHTML)):e.outerHTML}let w=new WeakMap,A=new Map;function k(e){const t=[];if(!e)return t;let n="",s="",i=[],r=[],o="action";const a=()=>{if(n)return n;if(0===t.length)throw new Error("Could not find any directives");return t[t.length-1].action},l=()=>{t.push({action:n,args:i,modifiers:r,getString:()=>e}),n="",s="",i=[],r=[],o="action"},c=()=>{i.push(s.trim()),s=""},d=()=>{if(i.length>1)throw new Error(`The modifier "${n}()" does not support multiple arguments.`);r.push({name:n,value:i.length>0?i[0]:null}),n="",i=[],o="action"};for(let t=0;t{var n;t.push(...(n=e,n.replace(/[\s]+/g," ").trim()).split(" "))})),t}function C(e){return e.replace(/\[]$/,"").split("[").map((e=>e.replace("]",""))).join(".")}function M(e,t){if(e instanceof HTMLInputElement){if("checkbox"===e.type){const n=x(e,!1);if(null!==n){const s=t.get(n.action);if(Array.isArray(s))return N(e,s);if(Object(s)===s)return N(e,Object.values(s))}return e.hasAttribute("value")?e.checked?e.getAttribute("value"):null:e.checked}return P(e)}return e instanceof HTMLSelectElement?e.multiple?Array.from(e.selectedOptions).map((e=>e.value)):e.value:e.hasAttribute("data-value")?e.dataset.value:"value"in e?e.value:e.hasAttribute("value")?e.getAttribute("value"):null}function T(e,t){if(e instanceof HTMLInputElement){if("file"===e.type)return;if("radio"===e.type)return void(e.checked=e.value==t);if("checkbox"===e.type)return void(Array.isArray(t)?e.checked=t.some((t=>t==e.value)):e.hasAttribute("value")?e.checked=e.value==t:e.checked=t)}if(e instanceof HTMLSelectElement){const n=[].concat(t).map((e=>`${e}`));Array.from(e.options).forEach((e=>{e.selected=n.includes(e.value)}))}else t=void 0===t?"":t,e.value=t}function F(e){if(!e.dataset.model)return[];const t=k(e.dataset.model);return t.forEach((t=>{if(t.args.length>0)throw new Error(`The data-model="${e.dataset.model}" format is invalid: it does not support passing arguments to the model.`);t.action=C(t.action)})),t}function x(e,t=!0){const n=F(e);if(n.length>0)return n[0];if(e.getAttribute("name")){const t=e.closest("form");if(t&&"model"in t.dataset){const n=k(t.dataset.model||"*")[0];if(n.args.length>0)throw new Error(`The data-model="${t.dataset.model}" format is invalid: it does not support passing arguments to the model.`);return n.action=C(e.getAttribute("name")),n}}if(!t)return null;throw new Error(`Cannot determine the model name for "${E(e)}": the element must either have a "data-model" (or "name" attribute living inside a