(()=>{var e="[data-bulk-action-checkbox]",t="[data-bulk-action-select-all-checkbox]",c="[data-bulk-action-footer]",n="[data-bulk-action-num-objects]",o="[data-bulk-action-num-objects-in-listing]",a={checkedObjects:new Set,numObjects:0,selectAllInListing:!1,shouldShowAllInListingText:!0};function d(e){var t=document.querySelector(".actions [data-dropdown]");null!==t&&(!0===e?t.classList.remove("hidden"):t.classList.add("hidden"))}function r(e){return wagtailConfig.STRINGS.BULK_ACTIONS[wagtailConfig.BULK_ACTION_ITEM_TYPE]?wagtailConfig.STRINGS.BULK_ACTIONS[wagtailConfig.BULK_ACTION_ITEM_TYPE][e]:wagtailConfig.STRINGS.BULK_ACTIONS.ITEM[e]}function l(n){document.querySelectorAll(t).forEach((function(e){e.checked=n.target.checked}));var o=new Event("change");document.querySelectorAll(e).forEach((function(e){e.checked!==n.target.checked&&(e.checked=n.target.checked,n.target.checked?e.dispatchEvent(o):e.classList.remove("show"))})),n.target.checked?d(!1):(d(!0),a.checkedObjects.clear(),document.querySelector(c).classList.add("hidden"))}function i(l){a.selectAllInListing&&(a.selectAllInListing=!1);var i=a.checkedObjects.size;l.target.checked?a.checkedObjects.add(Number(l.target.dataset.objectId)):(document.querySelectorAll(t).forEach((function(e){e.checked=!1})),a.checkedObjects.delete(Number(l.target.dataset.objectId)));var u=a.checkedObjects.size;if(0===u?(d(!0),document.querySelector(c).classList.add("hidden"),document.querySelectorAll(e).forEach((function(e){return e.classList.remove("show")}))):1===u&&0===i&&(d(!1),document.querySelectorAll(e).forEach((function(e){e.classList.add("show")})),document.querySelector(c).classList.remove("hidden")),u===a.numObjects?(document.querySelectorAll(t).forEach((function(e){e.checked=!0})),a.shouldShowAllInListingText&&document.querySelector(o).classList.remove("u-hidden")):a.shouldShowAllInListingText&&document.querySelector(o).classList.add("u-hidden"),u>0){var s;s=1===u?r("SINGULAR"):u===a.numObjects?r("ALL").replace("{0}",u):r("PLURAL").replace("{0}",u),document.querySelector(n).textContent=s}}function u(e){e.preventDefault(),a.selectAllInListing=!0,document.querySelector(n).textContent="".concat(r("ALL_IN_LISTING"),"."),document.querySelector(o).classList.add("u-hidden")}function s(e){e.preventDefault();var t=e.target.getAttribute("href"),c=new URLSearchParams(window.location.search);if(a.selectAllInListing){c.append("id","all");var n=document.querySelector("[data-bulk-action-parent-id]");if(n){var o=n.dataset.bulkActionParentId;c.append("childOf",o)}}else a.checkedObjects.forEach((function(e){c.append("id",e)}));window.location.href="".concat(t,"&").concat(c.toString())}document.addEventListener("DOMContentLoaded",(function(){var n=new Event("change");document.querySelectorAll(e).forEach((function(e){a.numObjects++,e.addEventListener("change",i)})),document.querySelectorAll(t).forEach((function(e){e.addEventListener("change",l)})),document.querySelectorAll("".concat(c," .bulk-action-btn")).forEach((function(e){return e.addEventListener("click",s)}));var d=document.querySelector(o);d?d.addEventListener("click",u):a.shouldShowAllInListingText=!1,document.querySelectorAll(e).forEach((function(e){e.checked&&e.dispatchEvent(n)}))})),window.headerSearch&&document.querySelector(window.headerSearch.termInput).addEventListener("search-success",(function(){document.querySelectorAll(t).forEach((function(e){e.checked=!1})),document.querySelector(c).classList.add("hidden"),document.querySelectorAll(t).forEach((function(e){e.removeEventListener("change",l),e.addEventListener("change",l)})),a.checkedObjects.clear(),a.numObjects=0,document.querySelectorAll(e).forEach((function(e){a.numObjects++,e.addEventListener("change",i)}))}))})();