(()=>{"use strict";function e(e,t){if(!e||e.dataset.eddModalBound)return;e.dataset.eddModalBound="true";const n=e.querySelector(".edd-modal__close");n&&n.addEventListener("click",(function(e){e.preventDefault(),e.stopPropagation(),t()})),e.addEventListener("click",(function(n){n.target===e&&t()}))}const t=function(e){return(e=e.toLowerCase()).trim()};function n(e){if(!e)return;const t=e.querySelector(".edd-email-tags-filter-search");t&&(t.value="",t.dispatchEvent(new Event("input")),t.focus())}function o(e){const t=document.querySelectorAll(".edd-email-tags-list-item");if(!t.length)return;const n=".edd-email-tags-filter-search",o=".edd-email-tags-list-button",i=document.activeElement;if(!i||!i.matches(n)&&!i.matches(o))return;let c,r=!1;if(i.matches(n)){if("up"===e)return;c=_.find(t,(e=>"none"!==e.style.display)),r=!0}else c=i.parentElement;for(;!r;)c="down"===e?c.nextElementSibling:c.previousElementSibling,r=!c||"none"!==c.style.display;c?c.querySelector(o).focus():"up"===e&&document.querySelector(n).focus()}document.addEventListener("DOMContentLoaded",(function(){const i=function(t){if(t.dialog){const n=t.dialog;if(!n||"function"!=typeof n.showModal)return null;const o=function(){n&&"function"==typeof n.close&&n.close()};return e(n,o),{open:function(){n.showModal(),"function"==typeof t.onOpen&&t.onOpen(n)},close:o,getDialog:function(){return n}}}const n="string"==typeof t.trigger,o=n?document.querySelector(t.trigger):t.trigger,i=t.dialogId||o?.getAttribute("data-dialog-id")||"";let c=i?document.getElementById(i):null;function r(){return!c&&i&&(c=document.getElementById(i)),c}function l(e){const n=e||r();n&&"function"==typeof n.showModal&&(n.showModal(),"function"==typeof t.onOpen&&t.onOpen(n))}function d(){const e=r();e&&"function"==typeof e.close&&e.close()}return n&&t.trigger?(document.body.addEventListener("click",(function(n){const o=n.target.closest(t.trigger);if(!o)return;n.preventDefault();const c=o.getAttribute("data-dialog-id")||i,r=c?document.getElementById(c):null;r&&(e(r,(function(){r&&"function"==typeof r.close&&r.close()})),l(r))})),{open:l,close:d,getDialog:r}):c&&"function"==typeof c.showModal?(e(c,d),o&&o.addEventListener("click",(function(e){e.preventDefault(),l()})),{open:l,close:d,getDialog:r}):null}({trigger:".edd-email-tags-inserter",dialogId:"edd-insert-email-tag-dialog",onOpen:n});i&&(function(e){const t=document.querySelectorAll(".edd-email-tags-list-button");t.length&&_.each(t,(function(t){t.addEventListener("click",(function(){e&&"function"==typeof e.close&&e.close(),window.send_to_editor(t.dataset.to_insert)}))}))}(i),function(){const e=document.querySelector(".edd-email-tags-filter-search");e&&e.addEventListener("input",(function(e){!function(e=""){const n=document.querySelectorAll(".edd-email-tags-list-item"),o=function(e,n){const o=t(n),i=function(e){return-1!==t(e).indexOf(o)};return _.filter(e,(function(e){return i(e.title)||_.some(e.keywords,i)}))}(eddEmailTagsInserter.items,e);_.each(n,(function(e){const t=_.findWhere(o,{tag:e.dataset.tag});e.style.display=t?"block":"none"}))}(e.target.value)}))}(),document.addEventListener("keydown",(function(e){const t=e.key||e.keyCode;t&&("ArrowDown"!==t&&40!==t?"ArrowUp"!==t&&38!==t||o("up"):o("down"))})))}))})();