/*! choices.js v3.0.2 | (c) 2017 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Choices=t():e.Choices=t()}(this,function(){return function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return e[n].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var i={};return t.m=e,t.c=i,t.p="/src/scripts/dist/",t(0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function s(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function o(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t0&&void 0!==arguments[0]?arguments[0]:"[data-choice]",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(r(this,e),(0,w.isType)("String",t)){var n=document.querySelectorAll(t);if(n.length>1)for(var s=1;s"'+e+'"'},maxItemText:function(e){return"Only "+e+" values can be added."},uniqueItemText:"Only unique values can be added.",classNames:{containerOuter:"choices",containerInner:"choices__inner",input:"choices__input",inputCloned:"choices__input--cloned",list:"choices__list",listItems:"choices__list--multiple",listSingle:"choices__list--single",listDropdown:"choices__list--dropdown",item:"choices__item",itemSelectable:"choices__item--selectable",itemDisabled:"choices__item--disabled",itemChoice:"choices__item--choice",placeholder:"choices__placeholder",group:"choices__group",groupHeading:"choices__heading",button:"choices__button",activeState:"is-active",focusState:"is-focused",openState:"is-open",disabledState:"is-disabled",highlightedState:"is-highlighted",hiddenState:"is-hidden",flippedState:"is-flipped",loadingState:"is-loading",noResults:"has-no-results",noChoices:"has-no-choices"},fuseOptions:{include:"score"},callbackOnInit:null,callbackOnCreateTemplates:null};if(this.idNames={itemChoice:"item-choice"},this.config=(0,w.extend)(a,e.userDefaults,i),["auto","always"].includes(this.config.renderSelectedChoices)||(this.config.renderSelectedChoices="auto"),this.store=new f.default(this.render),this.initialised=!1,this.currentState={},this.prevState={},this.currentValue="",this.element=t,this.passedElement=(0,w.isType)("String",t)?document.querySelector(t):t,!this.passedElement)return this.config.silent||console.error("Passed element not found"),!1;this.isTextElement="text"===this.passedElement.type,this.isSelectOneElement="select-one"===this.passedElement.type,this.isSelectMultipleElement="select-multiple"===this.passedElement.type,this.isSelectElement=this.isSelectOneElement||this.isSelectMultipleElement,this.isValidElementType=this.isTextElement||this.isSelectElement,this.isIe11=!(!navigator.userAgent.match(/Trident/)||!navigator.userAgent.match(/rv[ :]11/)),this.isScrollingOnIe=!1,this.config.shouldSortItems===!0&&this.isSelectOneElement&&(this.config.silent||console.warn("shouldSortElements: Type of passed element is 'select-one', falling back to false.")),this.highlightPosition=0,this.canSearch=this.config.searchEnabled,this.placeholder=!1,this.isSelectOneElement||(this.placeholder=!!this.config.placeholder&&(this.config.placeholderValue||this.passedElement.getAttribute("placeholder"))),this.presetChoices=this.config.choices,this.presetItems=this.config.items,this.passedElement.value&&(this.presetItems=this.presetItems.concat(this.passedElement.value.split(this.config.delimiter))),this.baseId=(0,w.generateId)(this.passedElement,"choices-"),this.render=this.render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this.wasTap=!0;var l="classList"in document.documentElement;l||this.config.silent||console.error("Choices: Your browser doesn't support Choices");var c=(0,w.isElement)(this.passedElement)&&this.isValidElementType;if(c){if("active"===this.passedElement.getAttribute("data-choice"))return!1;this.init()}else this.config.silent||console.error("Incompatible input passed")}return a(e,[{key:"init",value:function(){if(!this.initialised){this.initialised=!0,this._createTemplates(),this._createInput(),this.store.subscribe(this.render),this.render(),this._addEventListeners();var e=this.config.callbackOnInit;e&&(0,w.isType)("Function",e)&&e.call(this)}}},{key:"destroy",value:function(){if(this.initialised){this._removeEventListeners(),this.passedElement.classList.remove(this.config.classNames.input,this.config.classNames.hiddenState),this.passedElement.removeAttribute("tabindex");var e=this.passedElement.getAttribute("data-choice-orig-style");e?(this.passedElement.removeAttribute("data-choice-orig-style"),this.passedElement.setAttribute("style",e)):this.passedElement.removeAttribute("style"),this.passedElement.removeAttribute("aria-hidden"),this.passedElement.removeAttribute("data-choice"),this.passedElement.value=this.passedElement.value,this.containerOuter.element.parentNode.insertBefore(this.passedElement,this.containerOuter.element),this.containerOuter.element.parentNode.removeChild(this.containerOuter.element),this.clearStore(),this.config.templates=null,this.initialised=!1}}},{key:"renderGroups",value:function(e,t,i){var n=this,s=i||document.createDocumentFragment(),o=this.config.sortFilter;return this.config.shouldSort&&e.sort(o),e.forEach(function(e){var i=t.filter(function(t){return n.isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===n.config.renderSelectedChoices||!t.selected)});if(i.length>=1){var o=n._getTemplate("choiceGroup",e);s.appendChild(o),n.renderChoices(i,s,!0)}}),s}},{key:"renderChoices",value:function(e,t){var i=this,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=t||document.createDocumentFragment(),r=this.config,a=r.renderSelectedChoices,l=r.searchResultLimit,c=r.renderChoiceLimit,u=this.isSearching?w.sortByScore:this.config.sortFilter,h=function(e){var t="auto"!==a||(i.isSelectOneElement||!e.selected);if(t){var n=i._getTemplate("choice",e);s.appendChild(n)}},d=e;"auto"!==a||this.isSelectOneElement||(d=e.filter(function(e){return!e.selected}));var f=d.reduce(function(e,t){return t.placeholder?e.placeholderChoices.push(t):e.normalChoices.push(t),e},{placeholderChoices:[],normalChoices:[]}),p=f.placeholderChoices,v=f.normalChoices;(this.config.shouldSort||this.isSearching)&&v.sort(u);var m=d.length,g=[].concat(o(p),o(v));this.isSearching?m=l:c>0&&!n&&(m=c);for(var y=0;y1&&void 0!==arguments[1]?arguments[1]:null,n=i||document.createDocumentFragment();if(this.config.shouldSortItems&&!this.isSelectOneElement&&e.sort(this.config.sortFilter),this.isTextElement){var s=this.store.getItemsReducedToValues(e),o=s.join(this.config.delimiter);this.passedElement.setAttribute("value",o),this.passedElement.value=o}else{var r=document.createDocumentFragment();e.forEach(function(e){var i=t._getTemplate("option",e);r.appendChild(i)}),this.passedElement.innerHTML="",this.passedElement.appendChild(r)}return e.forEach(function(e){var i=t._getTemplate("item",e);n.appendChild(i)}),n}},{key:"render",value:function(){if(this.currentState=this.store.getState(),this.currentState!==this.prevState){if((this.currentState.choices!==this.prevState.choices||this.currentState.groups!==this.prevState.groups||this.currentState.items!==this.prevState.items)&&this.isSelectElement){var e=this.store.getGroupsFilteredByActive(),t=this.store.getChoicesFilteredByActive(),i=document.createDocumentFragment();if(this.choiceList.clear(),this.config.resetScrollPosition&&this.choiceList.scrollTo(0),e.length>=1&&this.isSearching!==!0){var n=t.filter(function(e){return e.placeholder===!0&&e.groupId===-1});n.length>=1&&(i=this.renderChoices(n,i)),i=this.renderGroups(e,t,i)}else t.length>=1&&(i=this.renderChoices(t,i));var s=this.store.getItemsFilteredByActive(),o=this._canAddItem(s,this.input.getValue());if(i.childNodes&&i.childNodes.length>0)o.response?(this.choiceList.append(i),this._highlightChoice()):this.choiceList.append(this._getTemplate("notice",o.notice));else{var r=void 0,a=void 0;this.isSearching?(a=(0,w.isType)("Function",this.config.noResultsText)?this.config.noResultsText():this.config.noResultsText,r=this._getTemplate("notice",a,"no-results")):(a=(0,w.isType)("Function",this.config.noChoicesText)?this.config.noChoicesText():this.config.noChoicesText,r=this._getTemplate("notice",a,"no-choices")),this.choiceList.append(r)}}if(this.currentState.items!==this.prevState.items){var l=this.store.getItemsFilteredByActive();if(this.itemList.clear(),l&&l.length){var c=this.renderItems(l);c.childNodes&&this.itemList.append(c)}}this.prevState=this.currentState}}},{key:"highlightItem",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!e)return this;var i=e.id,n=e.groupId,s=n>=0?this.store.getGroupById(n):null;if(this.store.dispatch((0,S.highlightItem)(i,!0)),t){var o={id:i,value:e.value,label:e.label};s&&s.value&&(o.groupValue=s.value),(0,w.triggerEvent)(this.passedElement,"highlightItem",o)}return this}},{key:"unhighlightItem",value:function(e){if(!e)return this;var t=e.id,i=e.groupId,n=i>=0?this.store.getGroupById(i):null,s={id:t,value:e.value,label:e.label};return n&&n.value&&(s.groupValue=n.value),this.store.dispatch((0,S.highlightItem)(t,!1)),(0,w.triggerEvent)(this.passedElement,"highlightItem",s),this}},{key:"highlightAll",value:function(){var e=this,t=this.store.getItems();return t.forEach(function(t){return e.highlightItem(t)}),this}},{key:"unhighlightAll",value:function(){var e=this,t=this.store.getItems();return t.forEach(function(t){return e.unhighlightItem(t)}),this}},{key:"removeItemsByValue",value:function(e){var t=this;if(!e||!(0,w.isType)("String",e))return this;var i=this.store.getItemsFilteredByActive();return i.forEach(function(i){i.value===e&&t._removeItem(i)}),this}},{key:"removeActiveItems",value:function(e){var t=this,i=this.store.getItemsFilteredByActive();return i.forEach(function(i){i.active&&e!==i.id&&t._removeItem(i)}),this}},{key:"removeHighlightedItems",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this.store.getItemsFilteredByActive();return i.forEach(function(i){i.highlighted&&i.active&&(e._removeItem(i),t&&e._triggerChange(i.value))}),this}},{key:"showDropdown",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.dropdown.isActive?this:(this.containerOuter.open(this.dropdown.getVerticalPos()),this.dropdown.show(),this.input.activate(e),(0,w.triggerEvent)(this.passedElement,"showDropdown",{}),this)}},{key:"hideDropdown",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.dropdown.isActive?(this.containerOuter.close(),this.dropdown.hide(),this.input.deactivate(e),(0,w.triggerEvent)(this.passedElement,"hideDropdown",{}),this):this}},{key:"toggleDropdown",value:function(){return this.dropdown.isActive?this.hideDropdown():this.showDropdown(!0),this}},{key:"getValue",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this.store.getItemsFilteredByActive(),n=[];return i.forEach(function(i){var s=t?i.value:i;(e.isTextElement||i.active)&&n.push(s)}),this.isSelectOneElement?n[0]:n}},{key:"setValue",value:function(e){var t=this;if(!this.initialised)return this;var i=[].concat(o(e)),n=function(e){var i=(0,w.getType)(e).toLowerCase(),n={object:function(){e.value&&(t.isTextElement?t._addItem(e.value,e.label,e.id,void 0,e.customProperties,e.placeholder):t._addChoice(e.value,e.label,!0,!1,-1,e.customProperties,e.placeholder))},string:function(){t.isTextElement?t._addItem(e):t._addChoice(e,e,!0,!1,-1,null)}};n[i]()};return i.forEach(function(e){return n(e)}),this}},{key:"setValueByChoice",value:function(e){var t=this;if(this.isTextElement)return this;var i=this.store.getChoices(),n=(0,w.isType)("Array",e)?e:[e];return n.forEach(function(e){var n=i.find(function(t){return t.value===e});n?n.selected?t.config.silent||console.warn("Attempting to select choice already selected"):t._addItem(n.value,n.label,n.id,n.groupId,n.customProperties,n.placeholder,n.keyCode):t.config.silent||console.warn("Attempting to select choice that does not exist")}),this}},{key:"setChoices",value:function(e,t,i){var n=this,s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return this.initialised&&this.isSelectElement&&(0,w.isType)("Array",e)&&t?(s&&this._clearChoices(),e&&e.length&&(this.containerOuter.removeLoadingState(),e.forEach(function(e){e.choices?n._addGroup(e,e.id||null,t,i):n._addChoice(e[t],e[i],e.selected,e.disabled,void 0,e.customProperties,e.placeholder)})),this):this}},{key:"clearStore",value:function(){return this.store.dispatch((0,S.clearAll)()),this}},{key:"clearInput",value:function(){var e=!this.isSelectOneElement;return this.input.clear(e),!this.isTextElement&&this.config.searchEnabled&&(this.isSearching=!1,this.store.dispatch((0,S.activateChoices)(!0))),this}},{key:"enable",value:function(){return this.initialised?(this.passedElement.disabled=!1,this.containerOuter.isDisabled&&(this._addEventListeners(),this.passedElement.removeAttribute("disabled"),this.input.enable(),this.containerOuter.enable()),this):this}},{key:"disable",value:function(){return this.initialised?(this.passedElement.disabled=!0,this.containerOuter.isDisabled||(this._removeEventListeners(),this.passedElement.setAttribute("disabled",""),this.input.disable(),this.containerOuter.disable()),this):this}},{key:"ajax",value:function(e){var t=this;return this.initialised&&this.isSelectElement?(requestAnimationFrame(function(){return t._handleLoadingState(!0)}),e(this._ajaxCallback()),this):this}},{key:"_triggerChange",value:function(e){e&&(0,w.triggerEvent)(this.passedElement,"change",{value:e})}},{key:"_handleButtonAction",value:function(e,t){if(e&&t&&this.config.removeItems&&this.config.removeItemButton){var i=t.parentNode.getAttribute("data-id"),n=e.find(function(e){return e.id===parseInt(i,10)});this._removeItem(n),this._triggerChange(n.value),this.isSelectOneElement&&this._selectPlaceholderChoice()}}},{key:"_selectPlaceholderChoice",value:function(){var e=this.store.getPlaceholderChoice();e&&(this._addItem(e.value,e.label,e.id,e.groupId,null,e.placeholder),this._triggerChange(e.value))}},{key:"_handleItemAction",value:function(e,t){var i=this,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(e&&t&&this.config.removeItems&&!this.isSelectOneElement){var s=t.getAttribute("data-id");e.forEach(function(e){e.id!==parseInt(s,10)||e.highlighted?!n&&e.highlighted&&i.unhighlightItem(e):i.highlightItem(e)}),this.input.focus()}}},{key:"_handleChoiceAction",value:function(e,t){if(e&&t){var i=t.getAttribute("data-id"),n=this.store.getChoiceById(i),s=e[0]&&e[0].keyCode?e[0].keyCode:null,o=this.dropdown.isActive;if(n.keyCode=s,(0,w.triggerEvent)(this.passedElement,"choice",{choice:n}),n&&!n.selected&&!n.disabled){var r=this._canAddItem(e,n.value);r.response&&(this._addItem(n.value,n.label,n.id,n.groupId,n.customProperties,n.placeholder,n.keyCode),this._triggerChange(n.value))}this.clearInput(),o&&this.isSelectOneElement&&(this.hideDropdown(),this.containerOuter.focus())}}},{key:"_handleBackspace",value:function(e){if(this.config.removeItems&&e){var t=e[e.length-1],i=e.some(function(e){return e.highlighted});this.config.editItems&&!i&&t?(this.input.setValue(t.value),this.input.setWidth(),this._removeItem(t),this._triggerChange(t.value)):(i||this.highlightItem(t,!1),this.removeHighlightedItems(!0))}}},{key:"_canAddItem",value:function(e,t){var i=!0,n=(0,w.isType)("Function",this.config.addItemText)?this.config.addItemText(t):this.config.addItemText;(this.isSelectMultipleElement||this.isTextElement)&&this.config.maxItemCount>0&&this.config.maxItemCount<=e.length&&(i=!1,n=(0,w.isType)("Function",this.config.maxItemText)?this.config.maxItemText(this.config.maxItemCount):this.config.maxItemText),this.isTextElement&&this.config.addItems&&i&&this.config.regexFilter&&(i=(0,w.regexFilter)(t,this.config.regexFilter));var s=!e.some(function(e){return(0,w.isType)("String",t)?e.value===t.trim():e.value===t});return s||this.config.duplicateItems||this.isSelectOneElement||!i||(i=!1,n=(0,w.isType)("Function",this.config.uniqueItemText)?this.config.uniqueItemText(t):this.config.uniqueItemText),{response:i,notice:n}}},{key:"_handleLoadingState",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],t=this.itemList.getChild("."+this.config.classNames.placeholder);e?(this.containerOuter.addLoadingState(),this.isSelectOneElement?t?t.innerHTML=this.config.loadingText:(t=this._getTemplate("placeholder",this.config.loadingText),this.itemList.append(t)):this.input.setPlaceholder(this.config.loadingText)):(this.containerOuter.removeLoadingState(),this.isSelectOneElement?t.innerHTML=this.placeholder||"":this.input.setPlaceholder(this.placeholder||""))}},{key:"_ajaxCallback",value:function(){var e=this;return function(t,i,n){if(t&&i){var s=(0,w.isType)("Object",t)?[t]:t;s&&(0,w.isType)("Array",s)&&s.length?(e._handleLoadingState(!1),s.forEach(function(t){if(t.choices){var s=t.id||null;e._addGroup(t,s,i,n)}else e._addChoice(t[i],t[n],t.selected,t.disabled,void 0,t.customProperties,t.placeholder)}),e.isSelectOneElement&&e._selectPlaceholderChoice()):e._handleLoadingState(!1)}}}},{key:"_searchChoices",value:function(e){var t=(0,w.isType)("String",e)?e.trim():e,i=(0,w.isType)("String",this.currentValue)?this.currentValue.trim():this.currentValue;if(t.length>=1&&t!==i+" "){var n=this.store.getSearchableChoices(),s=t,o=(0,w.isType)("Array",this.config.searchFields)?this.config.searchFields:[this.config.searchFields],r=Object.assign(this.config.fuseOptions,{keys:o}),a=new c.default(n,r),l=a.search(s);return this.currentValue=t,this.highlightPosition=0,this.isSearching=!0,this.store.dispatch((0,S.filterChoices)(l)),l.length}return 0}},{key:"_handleSearch",value:function(e){if(e&&this.input.isFocussed){var t=this.store.getChoices(),i=t.some(function(e){return!e.active});if(e&&e.length>=this.config.searchFloor){var n=this.config.searchChoices?this._searchChoices(e):0;(0,w.triggerEvent)(this.passedElement,"search",{value:e,resultCount:n})}else i&&(this.isSearching=!1,this.store.dispatch((0,S.activateChoices)(!0)))}}},{key:"_addEventListeners",value:function(){document.addEventListener("keyup",this._onKeyUp),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("click",this._onClick),document.addEventListener("touchmove",this._onTouchMove),document.addEventListener("touchend",this._onTouchEnd),document.addEventListener("mousedown",this._onMouseDown),document.addEventListener("mouseover",this._onMouseOver),this.isSelectOneElement&&(this.containerOuter.element.addEventListener("focus",this._onFocus),this.containerOuter.element.addEventListener("blur",this._onBlur)),this.input.element.addEventListener("focus",this._onFocus),this.input.element.addEventListener("blur",this._onBlur),this.input.addEventListeners()}},{key:"_removeEventListeners",value:function(){document.removeEventListener("keyup",this._onKeyUp),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("click",this._onClick),document.removeEventListener("touchmove",this._onTouchMove),document.removeEventListener("touchend",this._onTouchEnd),document.removeEventListener("mousedown",this._onMouseDown),document.removeEventListener("mouseover",this._onMouseOver),this.isSelectOneElement&&(this.containerOuter.element.removeEventListener("focus",this._onFocus),this.containerOuter.element.removeEventListener("blur",this._onBlur)),this.input.element.removeEventListener("focus",this._onFocus),this.input.element.removeEventListener("blur",this._onBlur),this.input.removeEventListeners()}},{key:"_onKeyDown",value:function(e){var t,i=this;if(e.target===this.input.element||this.containerOuter.element.contains(e.target)){var n=e.target,o=this.store.getItemsFilteredByActive(),r=this.input.isFocussed,a=this.dropdown.isActive,l=this.itemList.hasChildren,c=String.fromCharCode(e.keyCode),u=46,h=8,d=13,f=65,p=27,v=38,m=40,g=33,y=34,b=e.ctrlKey||e.metaKey;!this.isTextElement&&/[a-zA-Z0-9-_ ]/.test(c)&&this.showDropdown(!0),this.canSearch=this.config.searchEnabled;var E=function(){b&&l&&(i.canSearch=!1,i.config.removeItems&&!i.input.element.value&&i.input.element===document.activeElement&&i.highlightAll())},_=function(){if(i.isTextElement&&n.value){var t=i.input.element.value,s=i._canAddItem(o,t);s.response&&(i.hideDropdown(),i._addItem(t),i._triggerChange(t),i.clearInput())}if(n.hasAttribute("data-button")&&(i._handleButtonAction(o,n),e.preventDefault()),a){e.preventDefault();var r=i.dropdown.getChild("."+i.config.classNames.highlightedState);r&&(o[0]&&(o[0].keyCode=d),i._handleChoiceAction(o,r))}else i.isSelectOneElement&&(i.showDropdown(!0),e.preventDefault())},S=function(){a&&(i.hideDropdown(),i.containerOuter.focus())},I=function(){if(a||i.isSelectOneElement){i.showDropdown(!0),i.canSearch=!1;var t=e.keyCode===m||e.keyCode===y?1:-1,n=e.metaKey||e.keyCode===y||e.keyCode===g,s=void 0;if(n)s=t>0?Array.from(i.dropdown.element.querySelectorAll("[data-choice-selectable]")).pop():i.dropdown.element.querySelector("[data-choice-selectable]");else{var o=i.dropdown.element.querySelector("."+i.config.classNames.highlightedState);s=o?(0,w.getAdjacentEl)(o,"[data-choice-selectable]",t):i.dropdown.element.querySelector("[data-choice-selectable]")}s&&((0,w.isScrolledIntoView)(s,i.choiceList,t)||i._scrollToChoice(s,t),i._highlightChoice(s)),e.preventDefault()}},A=function(){!r||e.target.value||i.isSelectOneElement||(i._handleBackspace(o),e.preventDefault())},T=(t={},s(t,f,E),s(t,d,_),s(t,p,S),s(t,v,I),s(t,g,I),s(t,m,I),s(t,y,I),s(t,h,A),s(t,u,A),t);T[e.keyCode]&&T[e.keyCode]()}}},{key:"_onKeyUp",value:function(e){if(e.target===this.input.element){var t=this.input.element.value,i=this.store.getItemsFilteredByActive(),n=this._canAddItem(i,t);if(this.isTextElement)if(t){if(n.notice){var s=this._getTemplate("notice",n.notice);this.dropdown.element.innerHTML=s.outerHTML}n.response===!0?this.showDropdown():n.notice||this.hideDropdown()}else this.hideDropdown();else{var o=46,r=8;e.keyCode!==o&&e.keyCode!==r||e.target.value?this.canSearch&&n.response&&this._handleSearch(this.input.element.value):!this.isTextElement&&this.isSearching&&(this.isSearching=!1,this.store.dispatch((0,S.activateChoices)(!0)))}this.canSearch=this.config.searchEnabled}}},{key:"_onTouchMove",value:function(){this.wasTap===!0&&(this.wasTap=!1)}},{key:"_onTouchEnd",value:function(e){var t=e.target||e.touches[0].target;this.wasTap===!0&&this.containerOuter.element.contains(t)&&(t!==this.containerOuter.element&&t!==this.containerInner.element||this.isSelectOneElement||(this.isTextElement?this.input.focus():this.showDropdown(!0)),e.stopPropagation()),this.wasTap=!0}},{key:"_onMouseDown",value:function(e){var t=e.target;if(t===this.choiceList&&this.isIe11&&(this.isScrollingOnIe=!0),this.containerOuter.element.contains(t)&&t!==this.input.element){var i=this.store.getItemsFilteredByActive(),n=e.shiftKey,s=(0,w.findAncestorByAttrName)(t,"data-button"),o=(0,w.findAncestorByAttrName)(t,"data-item"),r=(0,w.findAncestorByAttrName)(t,"data-choice");s?this._handleButtonAction(i,s):o?this._handleItemAction(i,o,n):r&&this._handleChoiceAction(i,r),e.preventDefault()}}},{key:"_onClick",value:function(e){var t=e.target,i=this.dropdown.isActive,n=this.store.getItemsFilteredByActive();if(this.containerOuter.element.contains(t))i?this.isSelectOneElement&&t!==this.input.element&&!this.dropdown.element.contains(t)&&this.hideDropdown(!0):this.isTextElement?document.activeElement!==this.input.element&&this.input.focus():this.canSearch?this.showDropdown(!0):(this.showDropdown(),this.containerOuter.focus());else{var s=n.some(function(e){return e.highlighted});s&&this.unhighlightAll(),this.containerOuter.removeFocusState(),this.hideDropdown()}}},{key:"_onMouseOver",value:function(e){(e.target===this.dropdown||this.dropdown.element.contains(e.target))&&e.target.hasAttribute("data-choice")&&this._highlightChoice(e.target)}},{key:"_onFocus",value:function(e){var t=this,i=e.target;if(this.containerOuter.element.contains(i)){var n={text:function(){i===t.input.element&&t.containerOuter.addFocusState()},"select-one":function(){t.containerOuter.addFocusState(),i===t.input.element&&t.showDropdown()},"select-multiple":function(){i===t.input.element&&(t.containerOuter.addFocusState(),t.showDropdown(!0))}};n[this.passedElement.type]()}}},{key:"_onBlur",value:function(e){var t=this,i=e.target;if(this.containerOuter.element.contains(i)&&!this.isScrollingOnIe){var n=this.store.getItemsFilteredByActive(),s=n.some(function(e){return e.highlighted}),o={text:function(){i===t.input.element&&(t.containerOuter.removeFocusState(),s&&t.unhighlightAll(),t.hideDropdown())},"select-one":function(){t.containerOuter.removeFocusState(),i===t.containerOuter.element&&(t.canSearch||t.hideDropdown()),i===t.input.element&&t.hideDropdown()},"select-multiple":function(){i===t.input.element&&(t.containerOuter.removeFocusState(),t.hideDropdown(),s&&t.unhighlightAll())}};o[this.passedElement.type]()}else this.isScrollingOnIe=!1,this.input.element.focus()}},{key:"_scrollToChoice",value:function(e,t){var i=this;if(e){var n=this.choiceList.height,s=e.offsetHeight,o=e.offsetTop+s,r=this.choiceList.scrollPos+n,a=t>0?this.choiceList.scrollPos+o-r:e.offsetTop,l=function e(){var n=4,s=i.choiceList.scrollPos,o=!1,r=void 0,l=void 0;t>0?(r=(a-s)/n,l=r>1?r:1,i.choiceList.scrollTo(s+l),s1?r:1,i.choiceList.scrollTo(s-l),s>a&&(o=!0)),o&&requestAnimationFrame(function(i){e(i,a,t)})};requestAnimationFrame(function(e){l(e,a,t)})}}},{key:"_highlightChoice",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=Array.from(this.dropdown.element.querySelectorAll("[data-choice-selectable]")),n=t;if(i&&i.length){var s=Array.from(this.dropdown.element.querySelectorAll("."+this.config.classNames.highlightedState)),o=this.dropdown.isActive;s.forEach(function(t){t.classList.remove(e.config.classNames.highlightedState),t.setAttribute("aria-selected","false")}),n?this.highlightPosition=i.indexOf(n):(n=i.length>this.highlightPosition?i[this.highlightPosition]:i[i.length-1],n||(n=i[0])),n.classList.add(this.config.classNames.highlightedState),n.setAttribute("aria-selected","true"),o&&(this.input.setActiveDescendant(n.id),this.containerOuter.setActiveDescendant(n.id))}}},{key:"_addItem",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o=arguments.length>5&&void 0!==arguments[5]&&arguments[5],r=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,a=(0,w.isType)("String",e)?e.trim():e,l=r,c=this.store.getItems(),u=t||a,h=parseInt(i,10)||-1,d=n>=0?this.store.getGroupById(n):null,f=c?c.length+1:1;return this.config.prependValue&&(a=this.config.prependValue+a.toString()),this.config.appendValue&&(a+=this.config.appendValue.toString()),this.store.dispatch((0,S.addItem)(a,u,f,h,n,s,o,l)),this.isSelectOneElement&&this.removeActiveItems(f),d&&d.value?(0,w.triggerEvent)(this.passedElement,"addItem",{id:f,value:a,label:u,groupValue:d.value,keyCode:l}):(0,w.triggerEvent)(this.passedElement,"addItem",{id:f,value:a,label:u,keyCode:l}),this}},{key:"_removeItem",value:function(e){if(!e||!(0,w.isType)("Object",e))return this;var t=e.id,i=e.value,n=e.label,s=e.choiceId,o=e.groupId,r=o>=0?this.store.getGroupById(o):null;return this.store.dispatch((0,S.removeItem)(t,s)),r&&r.value?(0,w.triggerEvent)(this.passedElement,"removeItem",{id:t,value:i,label:n,groupValue:r.value}):(0,w.triggerEvent)(this.passedElement,"removeItem",{id:t,value:i,label:n}),this}},{key:"_addChoice",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:-1,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null,r=arguments.length>6&&void 0!==arguments[6]&&arguments[6],a=arguments.length>7&&void 0!==arguments[7]?arguments[7]:null;if("undefined"!=typeof e&&null!==e){var l=this.store.getChoices(),c=t||e,u=l?l.length+1:1,h=this.baseId+"-"+this.idNames.itemChoice+"-"+u;this.store.dispatch((0,S.addChoice)(e,c,u,s,n,h,o,r,a)),i&&this._addItem(e,c,u,void 0,o,r,a)}}},{key:"_clearChoices",value:function(){this.store.dispatch((0,S.clearChoices)())}},{key:"_addGroup",value:function(e,t){var i=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"value",s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"label",o=(0,w.isType)("Object",e)?e.choices:Array.from(e.getElementsByTagName("OPTION")),r=t||Math.floor((new Date).valueOf()*Math.random()),a=!!e.disabled&&e.disabled;o?(this.store.dispatch((0,S.addGroup)(e.label,r,!0,a)),o.forEach(function(e){var t=e.disabled||e.parentNode&&e.parentNode.disabled;i._addChoice(e[n],(0,w.isType)("Object",e)?e[s]:e.innerHTML,e.selected,t,r,e.customProperties,e.placeholder)})):this.store.dispatch((0,S.addGroup)(e.label,e.id,!1,e.disabled))}},{key:"_getTemplate",value:function(e){if(!e)return null;for(var t=this.config.templates,i=arguments.length,n=Array(i>1?i-1:0),s=1;s