document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".cf-export-picker").forEach(function(o){var c="cf_export_columns_"+(o.dataset.formId||"0"),r=o.querySelector(".cf-export-picker__badge"),e=o.querySelector(".cf-export-picker__hint"),t=o.closest(".control-group"),t=t&&t.querySelector(".control-label"),n=t&&t.querySelector("label");function l(){return Array.prototype.slice.call(o.querySelectorAll(".cf-export-item"))}function a(e){return Array.prototype.slice.call((e||o).querySelectorAll('.cf-export-item:not(.cf-export-item--pro) input[type="checkbox"]'))}function i(e,t){e.checked=t,e.closest(".cf-export-item").classList.toggle("is-checked",t)}function s(){try{var e=a().filter(function(e){return e.checked}).map(function(e){return e.value});localStorage.setItem(c,JSON.stringify(e))}catch(e){}}function u(){var e=a(),t=e.filter(function(e){return e.checked}).length;r.textContent=(r.dataset.template||"%s").replace("%s",t),o.querySelector(".cf-export-picker__selected").textContent=t,o.querySelector(".cf-export-picker__total").textContent=e.length,o.querySelectorAll(".cf-export-group").forEach(function(e){var t=a(e),c=t.filter(function(e){return e.checked}).length,e=(e.querySelector(".cf-export-group__count").textContent=c+"/"+t.length,e.querySelector(".cf-export-group__select-all")),c=0<t.length&&c===t.length;e.textContent=c?e.dataset.deselectLabel:e.dataset.selectLabel,e.dataset.action=c?"deselect":"select"})}r&&n&&n.appendChild(r),e&&t&&t.appendChild(e),o.addEventListener("change",function(e){e.target.matches('.cf-export-item input[type="checkbox"]')&&!e.target.closest(".cf-export-item--pro")&&(e.target.closest(".cf-export-item").classList.toggle("is-checked",e.target.checked),u(),s())}),o.addEventListener("click",function(e){var t=e.target.closest(".cf-export-item");t&&(t.classList.contains("cf-export-item--pro")?e.preventDefault():e.target.closest(".cf-export-item__main")||(e=t.querySelector('input[type="checkbox"]'))&&(e.checked=!e.checked,e.dispatchEvent(new Event("change",{bubbles:!0}))))}),o.querySelectorAll(".cf-export-group__toggle").forEach(function(e){e.addEventListener("click",function(){this.closest(".cf-export-group").classList.toggle("is-collapsed")})}),o.querySelectorAll(".cf-export-group__select-all").forEach(function(e){e.addEventListener("click",function(e){e.preventDefault();var e=this.closest(".cf-export-group"),t="deselect"!==this.dataset.action;e.classList.remove("is-collapsed"),a(e).forEach(function(e){e.closest(".cf-export-item").hidden||i(e,t)}),u(),s()})});o.querySelector(".cf-export-picker__search").addEventListener("input",function(){var c=this.value.toLowerCase().trim(),r=!1;l().forEach(function(e){var t=!c||-1<(e.dataset.label||"").indexOf(c);e.hidden=!t,r=r||t}),o.querySelectorAll(".cf-export-group").forEach(function(t){var e=l().some(function(e){return t.contains(e)&&!e.hidden});t.hidden=c&&!e,c&&e&&t.classList.remove("is-collapsed")}),o.querySelector(".cf-export-picker__no-results").hidden=r}),(()=>{var t;try{t=JSON.parse(localStorage.getItem(c))}catch(e){return}Array.isArray(t)&&a().forEach(function(e){i(e,-1<t.indexOf(e.value))})})(),u();n=o.querySelector('.cf-export-group[data-group="context"]');n&&(t=a(n).some(function(e){return e.checked}),n.classList.toggle("is-collapsed",!t))});var e=document.getElementById("filter_form_id");e&&document.querySelector(".cf-export-picker")&&e.addEventListener("change",function(){var e=new URL(window.location.href);e.searchParams.set("filter_form_id",this.value),window.location.href=e.toString()})});

