tribe.events=tribe.events||{},tribe.events.pro=tribe.events.pro||{},tribe.events.pro.admin=tribe.events.pro.admin||{},tribe.events.pro.admin.series=tribe.events.pro.admin.series||{},tribe.events.pro.admin.series.trashHandler={},((e,t)=>{"use strict";t.selectors={dialogElement:"#tec-events-pro-series-trash-dialog"},t.dialogElement=()=>{const n=e(t.selectors.dialogElement);return n.length?n:(e("body").append('<div id="tec-events-pro-series-trash-dialog"></div>'),e("head").append('\n\t\t\t<style>\n\t\t\t.ui-dialog[aria-describedby="tec-events-pro-series-trash-dialog"] {\n\t\t\t\tbackground:#f1f1f1;\n\t\t\t}\n\n\t\t\t.ui-dialog[aria-describedby="tec-events-pro-series-trash-dialog"] .ui-dialog-titlebar-close {\n\t\t\t\ttop: 1em;\n\t\t\t\tpadding-top:.5em\n\t\t\t}\n\t\t\t</style>\n\t\t'),e(t.selectors.dialogElement))},t.findPostId=t=>{const n=document.getElementById("post_ID");if(null!==n)return parseInt(n.value)||0;const s=e(t).closest(".level-0");if(0===s.length)return 0;const r=s[0].getAttribute("id");return r?parseInt(r.replace("post-","")):0},t.getCheckedListCheckboxes=()=>Array.from(document.querySelectorAll('input[type="checkbox"][name="post[]"]:checked')),t.getTotalRelatedRecurringEvents=e=>{const t=document.getElementById(`series-occurrences-count-${e}`);if(null===t)return 0;const n=parseInt(t.getAttribute("data-recurring-events-count"),10);return isNaN(n)?0:n},t.currentBulkAction=t=>{const n=e(t.target).closest(".bulkactions").find('[name="action"]').first();return 1!==n.length?null:n[0].value},t.findPostEditLink=e=>{const t=document.querySelector(`#post-${e} .title a.row-title`);if(null===t)return null;const n=t.cloneNode(!0);return n.setAttribute("target","_blank"),n},t.getCheckedListPostIds=(e=0)=>t.getCheckedListCheckboxes().reduce(((n,s)=>{const r=t.findPostId(s);return t.getTotalRelatedRecurringEvents(r)>=e&&n.push(r),n}),[]),t.getEditListHtml=(e=[])=>{let n="<p><ul>";return e.map((e=>{const s=t.findPostEditLink(e).outerHTML;n+=`<li>${s}</li>`})),n+="</ul></p>",n},t.displayModal=(n,s)=>r=>{s=-1===["trash","delete"].indexOf(s)?"trash":s;const{tecEventsProSeriesTrashHandler:o={}}=window,{messages:i={},dialog:l={}}=o,d=n>1?i[s].plural:i[s].singular,a=t.dialogElement();let c="<p>"+d+"</p>";n>1&&(c+=t.getEditListHtml(t.getCheckedListPostIds(1))),a.html(c),r.preventDefault(),r.stopPropagation();const u={autoOpen:!0,modal:!0,width:"400px",closeOnEscape:!0,closeText:"X",create:t=>{e(t.target).closest(".ui-dialog").find(".ui-dialog-titlebar-close").attr("title",l.closeButtonTooltip)},buttons:[{text:l.okButtonLabel,click:()=>{a.dialog("close")}}]};a.dialog(u)},t.listenForTrashClicks=()=>{const e=t.displayModal(1,"trash"),n=t.displayModal(1,"delete");Array.from(document.querySelectorAll('.trash a.submitdelete, #delete-action a.submitdelete[href*="action=trash"]')).map((n=>{const s=t.findPostId(n);0===s||t.getTotalRelatedRecurringEvents(s)<1||n.addEventListener("click",e)})),Array.from(document.querySelectorAll('.delete a.submitdelete, #delete-action a.submitdelete[href*="action=delete"]')).map((e=>{const s=t.findPostId(e);0===s||t.getTotalRelatedRecurringEvents(s)<1||e.addEventListener("click",n)}))},t.listenForBulkTrashClicks=()=>{const e=document.getElementById("doaction");if(null===e)return;const n=document.getElementById("doaction2"),s=e=>{const n=t.currentBulkAction(e);"trash"!==n&&"delete"!==n||t.getCheckedListCheckboxes().filter((e=>{const n=t.findPostId(e);return t.getTotalRelatedRecurringEvents(n)})).length<=0||t.displayModal(2,n)(e)};Array.from([e,n]).map((e=>{e.addEventListener("click",s)}))},t.hideEmptyTrashButton=()=>{const e=document.getElementById("delete_all");e instanceof Element&&(e.style.display="none")},document.addEventListener("DOMContentLoaded",(()=>{t.dialogElement(),t.listenForTrashClicks(),t.listenForBulkTrashClicks(),t.hideEmptyTrashButton()}))})(jQuery,tribe.events.pro.admin.series.trashHandler),window.tec=window.tec||{},window.tec.eventsPro=window.tec.eventsPro||{},window.tec.eventsPro.customTablesV1=window.tec.eventsPro.customTablesV1||{},window.tec.eventsPro.customTablesV1.seriesTrashHandler={};