function _extends(){return(_extends=Object.assign||function(n){for(var i,r,t=1;t<arguments.length;t++){i=arguments[t];for(r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n}).apply(this,arguments)}var CustomSelect=function(n){var i={block:"custom-select",hideCallback:!1,includeValue:!1,keyboard:!0,modifier:!1,placeholder:!1,search:!1,showCallback:!1,transition:0},t=function(){function r(t,r){this._$select=n(t);this._options=_extends({},i,"object"==typeof r&&r);this._activeModifier=this._options.block+"--active";this._dropupModifier=this._options.block+"--dropup";this._optionSelectedModifier=this._options.block+"__option--selected";this._keydown=this._keydown.bind(this);this._dropup=this._dropup.bind(this);this._outside=this._outside.bind(this);this._init()}var t=r.prototype;return t._init=function(){var t=this;this._$element=n('<div class="'+this._options.block+'">\n           <button class="'+this._options.block+"__option "+this._options.block+'__option--value" type="button"><\/button>\n           <div class="'+this._options.block+'__dropdown" style="display: none;"><\/div>\n         <\/div>');this._$select.hide().after(this._$element);this._options.modifier&&this._$element.addClass(this._options.modifier);this._$values=this._$select.find("option");this._values=[];n.each(this._$values,function(i,r){var u=n(r).text().trim();t._values.push(u)});this._$value=this._$element.find("."+this._options.block+"__option--value");this._options.placeholder&&(this._$select.find("[selected]").length?this._options.placeholder=!1:(this._$value.html(this._options.placeholder),this._$select.prop("selectedIndex",-1)));this._$dropdown=this._$element.find("."+this._options.block+"__dropdown");n.each(this._values,function(i,r){var u=t._$values.eq(i).attr("class"),f=n('<button class="'+t._options.block+'__option" type="button">'+r+"<\/button>");r===t._$select.find(":selected").text().trim()?(t._$value.text(r).addClass(u).data("class",u),(t._options.includeValue||t._options.placeholder)&&(f.addClass(u+" "+t._optionSelectedModifier),t._$dropdown.append(f))):(f.addClass(u),t._$dropdown.append(f))});this._$options=this._$dropdown.find("."+this._options.block+"__option");this._options.search&&this._search();this._$value.one("click",function(n){t._show(n)});this._$options.length||this._$value.prop("disabled",!0);this._$options.on("click",function(n){t._select(n)})},t._show=function(t){var i=this;t.preventDefault();this._dropup();n(window).on("resize scroll",this._dropup);this._$element.addClass(this._activeModifier);this._$dropdown.slideDown(this._options.transition,function(){i._options.search&&(i._$input.focus(),i._options.includeValue&&i._scroll());"function"==typeof i._options.showCallback&&i._options.showCallback.call(i._$element[0])});setTimeout(function(){var t="ontouchstart"in document.documentElement?"touchstart":"click";n(window).on(t,i._outside)},0);this._$value.one("click",function(n){n.preventDefault();i._hide()});this._options.keyboard&&(this._options.index=-1,n(window).on("keydown",this._keydown))},t._hide=function(){var t=this;this._options.search&&(this._$input.val("").blur(),this._$options.show(),this._$wrap.scrollTop(0));this._$dropdown.slideUp(this._options.transition,function(){t._$element.removeClass(t._activeModifier).removeClass(t._dropupModifier);"function"==typeof t._options.hideCallback&&t._options.hideCallback.call(t._$element[0]);n(window).off("touchstart click",t._outside).off("resize scroll",t._dropup);t._$value.off("click").one("click",function(n){t._show(n)})});this._options.keyboard&&(this._$options.blur(),n(window).off("keydown",this._keydown))},t._scroll=function(){var t=this;n.each(this._$options,function(i,r){var u=n(r),f,e;if(u.text()===t._$value.text())return f=u.position().top,e=t._$wrap.outerHeight()/2-u.outerHeight()/2,f>e&&t._$wrap.scrollTop(f-e),!1})},t._select=function(t){var r=this,u,i,f;t.preventDefault();u=n(t.currentTarget).text().trim();i=this._values.concat();(this._$value.text(u).removeClass(this._$value.data("class")),this._$values.prop("selected",!1),n.each(i,function(t,f){r._options.includeValue||f!==u||i.splice(t,1);n.each(r._$values,function(t,i){var f=n(i),e;f.text().trim()===u&&(e=f.attr("class"),f.prop("selected",!0),r._$value.addClass(e).data("class",e))})}),this._hide(),this._options.includeValue)?(this._$options.removeClass(this._optionSelectedModifier),n.each(this._$options,function(t,i){var f=n(i);if(f.text().trim()===u)return f.addClass(r._optionSelectedModifier),!1})):(this._$options.length>i.length&&(f=this._$options.eq(i.length),f.remove(),this._$options=this._$options.not(f),this._$options.length||this._$value.prop("disabled",!0)),n.each(this._$options,function(t,u){var f=n(u);f.text(i[t]);f.attr("class",r._options.block+"__option");n.each(r._$values,function(){var r=n(this);r.text().trim()===i[t]&&f.addClass(r.attr("class"))})}));void 0!==t.originalEvent&&this._$select.trigger("change")},t._search=function(){var t=this;this._$input=n('<input class="'+this._options.block+'__input" autocomplete="off">');this._$dropdown.prepend(this._$input);this._$options.wrapAll('<div class="'+this._options.block+'__option-wrap"><\/div>');this._$wrap=this._$element.find("."+this._options.block+"__option-wrap");this._$input.on("focus",function(){t._options.index=-1});this._$input.on("keyup",function(){var i=t._$input.val().trim();i.length?(t._$wrap.scrollTop(0),setTimeout(function(){i===t._$input.val().trim()&&n.each(t._$options,function(t,r){var u=n(r),f=-1!==u.text().trim().toLowerCase().indexOf(i.toLowerCase());u.toggle(f)})},300)):t._$options.show()})},t._dropup=function(){var t=this._$element[0].getBoundingClientRect().bottom,i=n(window).height()-t<this._$dropdown.height();this._$element.toggleClass(this._dropupModifier,i)},t._outside=function(t){var i=n(t.target);i.parents().is(this._$element)||i.is(this._$element)||this._hide()},t._keydown=function(n){var t=this._$options.filter(":visible"),i;switch(n.keyCode){case 40:n.preventDefault();t.eq(this._options.index+1).length?this._options.index+=1:this._options.index=0;t.eq(this._options.index).focus();break;case 38:n.preventDefault();t.eq(this._options.index-1).length&&this._options.index-1>=0?this._options.index-=1:this._options.index=t.length-1;t.eq(this._options.index).focus();break;case 13:case 32:this._$input&&this._$input.is(":focus")||(n.preventDefault(),i=this._$options.add(this._$value).filter(":focus"),i.trigger("click"),i.is(this._$value)||this._$select.trigger("change"),this._$value.focus());break;case 27:n.preventDefault();this._hide();this._$value.focus()}},r._jQueryPlugin=function(t){return this.each(function(){var u=n(this),i=u.data("custom-select");i||(i=new r(this,t),u.data("custom-select",i))})},r}();return n.fn.customSelect=t._jQueryPlugin,n.fn.customSelect.noConflict=function(){return n.fn.customSelect},t}($)