"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(e,t){"function"==typeof define&&define.amd?define(t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=t():e.CheckboxFilter=t()}(window,function(){return function(e,r){r=r||{};function n(e){if(l){e&&(l.value="");var o=0;[].slice.call(t).forEach(function(e){e.style.display="none"}),x(function(e){var t=e.checkboxWrapper,n=e.checkbox,c=e.label;c&&-1!==c.textContent.toUpperCase().indexOf(l.value.toUpperCase())?(t.removeAttribute("hidden"),n.removeAttribute("hidden"),o++):(t.setAttribute("hidden","true"),n.setAttribute("hidden","true"))}),[].slice.call(t).forEach(function(e){e.querySelectorAll("".concat(r.checkboxes||"div.checkbox",":not([hidden])")).length&&(e.style.display="")}),k(o)}}function c(e,t){var n=document.createElement("span");n.className="tag filter",n.textContent=t.textContent,n.setAttribute("data-value",e.value);var c=document.createElement("button");return c.type="button",c.innerHTML='<span class="visually-hidden">'.concat(r.hiddenTagText||"Remove tag","</span>"),c.addEventListener("click",function(){e.checked=!1,a.removeChild(n),"function"==typeof r.onRemoveTag&&r.onRemoveTag(e,n)}),n.appendChild(c),n}function o(){var e=a.children.length;b&&(b.textContent=e),p&&(0<e?p.classList.remove("hidden"):p.classList.add("hidden"))}function i(){y&&(a.innerHTML=""),x(function(e){var t=e.checkbox,n=e.label;-1!==v.indexOf(t)?t.checked=!0:t.checked=!1,t.checked&&y&&a.appendChild(c(t,n))})}var l=e.querySelector(r.filterfield||".checkbox-filter__filter"),u=e.querySelectorAll(r.checkboxes||"div.checkbox")||[],a=e.querySelector(r.selectedContainer||".checkbox-filter__selected"),t=e.querySelectorAll(r.checkboxContainers||".checkbox-filter__checkboxes"),d=e.querySelector(r.openBtn||".checkbox-filter__open"),f=e.querySelector(r.submitBtn||".checkbox-filter__submit"),h=e.querySelectorAll(r.closeBtns||".checkbox-filter__close"),s=e.querySelector(r.resultSpan||".checkbox-filter__result"),p=e.querySelector(r.countSpanWrapper||".checkbox-filter__count-wrapper"),b=e.querySelector(r.countSpan||".checkbox-filter__count"),v=[],y=!1!==r.makeTags||r.makeTags,k=function(e){s&&(s.textContent=e)},x=function(e){for(var t=u.length;t--;){var n=u[t],c=n.querySelector("input[type=checkbox]"),o=n.querySelector("label");c&&o&&e({checkboxWrapper:n,checkbox:c,label:o})}},m=function(e){27===(e.keyCode||e.which)&&(e.preventDefault(),i(),o())};return v=[],x(function(e){var t=e.checkbox,n=e.label;t.checked&&!t.indeterminate&&y&&a.appendChild(c(t,n))}),o(),n(!0),function(){if(l){var e=null;l.addEventListener("input",function(){e&&clearTimeout(e),e=setTimeout(n,200)})}if(x(function(e){var t=e.checkbox,n=e.label;t.addEventListener("change",function(){t.checked?y&&a.appendChild(c(t,n)):y&&function(e){for(var t=a.querySelectorAll(".filter"),n=t.length;n--;)t[n].getAttribute("data-value")===e.value&&a.removeChild(t[n])}(t)})}),d&&d.addEventListener("click",function(e){v=[];var n=0;x(function(e){var t=e.checkbox;t.checked&&v.push(t),n++}),k(n),document.addEventListener("keydown",m)}),h)for(var t=h.length;t--;)h[t].addEventListener("click",function(){i(),o(),document.removeEventListener("keydown",m)});f&&f.addEventListener("click",function(){o(),document.removeEventListener("keydown",m)})}(),{}}});