"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.CheckboxFilterDynamic=t()}(window,function(){return function(c,r){(r=r||{}).filterField=r.filterField||".checkbox-filter__filter",r.modalPreview=r.modalPreview||".modal-preview",r.accordionPreview=r.accordionPreview||".accordion-preview",r.accordionBtn=r.accordionBtn||"button.accordion--button",r.previewCheckboxes=r.previewCheckboxes||"div.checkbox.preview",r.checkboxes=r.checkboxes||"div.checkbox:not(.preview)",r.selectedContainer=r.selectedContainer||".checkbox-filter__selected",r.checkboxContainers=r.checkboxContainers||".checkbox-filter__checkboxes",r.openBtn=r.openBtn||".checkbox-filter__open",r.submitBtn=r.submitBtn||".checkbox-filter__submit",r.closeBtns=r.closeBtns||".checkbox-filter__close",r.resultSpan=r.resultSpan||".checkbox-filter__result",r.makeTags=!1!==r.makeTags,r.hiddenTagText=r.hiddenTagText||"remove tag",r.onRemoveTag=r.onRemoveTag||function(){};function n(e){if(a){e&&(a.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(a.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,":not([hidden])")).length&&(e.style.display="")}),k&&(k.textContent=""+o)}}function o(e,t){r.makeTags&&h&&h.appendChild(function(e,t){var n=document.createElement("li"),c=document.createElement("span");c.className="tag filter",c.textContent=t.textContent,c.setAttribute("data-value",e.value);var o=document.createElement("button");return o.type="button",o.innerHTML='<span class="visually-hidden">'.concat(r.hiddenTagText," ").concat(t.textContent,"</span>"),o.addEventListener("click",function(){return e.click()}),c.appendChild(o),n.appendChild(c),n}(e,t))}function i(){x(function(e){var t=e.checkbox,n=-1!==y.indexOf(t);(n&&!t.checked||!n&&t.checked)&&t.click()})}function l(e,t){e.checked!==t.checked&&e.click()}var a=c.querySelector(r.filterField),u=c.querySelector(r.modalPreview),d=c.querySelector(r.accordionPreview),e=c.querySelector(r.accordionBtn),f=c.querySelectorAll(r.previewCheckboxes)||[],s=c.querySelectorAll(r.checkboxes)||[],h=c.querySelector(r.selectedContainer),t=c.querySelectorAll(r.checkboxContainers),p=c.querySelector(r.openBtn),v=c.querySelector(r.submitBtn),b=c.querySelectorAll(r.closeBtns),k=c.querySelector(r.resultSpan),y=[],x=function(e){for(var t=0;t<s.length;t++){var n=s[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())};return x(function(e){var t=e.checkbox,n=e.label;t.checked&&!t.indeterminate&&o(t,n)}),n(!0),function(){if(p&&p.addEventListener("click",function(){y=[],x(function(e){var t=e.checkbox;t.checked&&y.push(t)}),document.addEventListener("keydown",m)}),b)for(var e=b.length;e--;)b[e].addEventListener("click",function(){i(),document.removeEventListener("keydown",m)});if(v&&v.addEventListener("click",function(){document.removeEventListener("keydown",m)}),a){var t=null;a.addEventListener("input",function(){t&&clearTimeout(t),t=setTimeout(n,200)})}}(),function(){if(f.length)for(var e=function(e){var t=f[e].querySelector("input[type=checkbox]"),n=c.querySelector("#"+t.getAttribute("data-original"));t&&(t.addEventListener("change",function(){return l(n,t)}),n.addEventListener("change",function(){return l(t,n)}))},t=f.length;t--;)e(t)}(),e&&d&&e.addEventListener("click",function(){return x(function(e){var t=e.checkboxWrapper;e.checkbox.checked&&!d.contains(t)&&d.appendChild(t)})}),x(function(e){var t=e.checkboxWrapper,n=e.checkbox,c=e.label;n.addEventListener("change",function(){n.checked?(o(n,c),function(e,t){if(u&&!u.querySelector("#"+t.id+"-preview")){var n=e.cloneNode(!0),c=n.querySelector("input"),o=n.querySelector("label");c.name=null,c.id+="-preview",o.for+="-preview",t.addEventListener("change",function(){return l(c,t)}),c.addEventListener("change",function(){return l(t,c)}),u.appendChild(n)}}(t,n)):function(e){if(r.makeTags&&h){var t=h.querySelector('.filter[data-value="'+e.value+'"]');t&&(h.removeChild(t.parentElement),r.onRemoveTag(e,t))}}(n)})}),{}}});