"use strict";!function(t){var e="mc-modal",a="data-modal-background-click",d="data-modal-prefix-class",n="data-modal-text",o="data-modal-content-id",i="data-modal-describedby-id",l="data-modal-title",r="data-modal-focus-toid",s="data-modal-close-text",c="mc-modal-close",u="mc-modal-close",m="data-content-back-id",b="data-focus-back",f="mc-modal-content",g="modal-title",A="mc-modal-page",v="mc-modal",p="mc-modal-overlay",h="Close modal",y="data-background-click",C="mc-no-scroll",E=function findById(e){return t.getElementById(e)},k=function removeClass(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," ")},x=function hasClass(t,e){return t.classList?t.classList.contains(e):new RegExp("(^|)"+e+"(|$)","gi").test(t.className)};function remove(t){t.parentNode.removeChild(t)}var I=function searchParent(t,e){for(var a=!1,d=t.parentNode;d&&!1===a;)!0===x(d,e)?a=!0:d=d.parentNode;return!0===a?d.getAttribute("id"):""},L=function closeModal(t){if(""!==t.modalFocusBackId){var e=E(t.modalFocusBackId).closest(".mc-events");e&&e.insertAdjacentElement("beforeEnd",t.modalContent.firstChild)}if(remove(t.modal),remove(t.overlay),t.modalFocusBackId){var a=E(t.modalFocusBackId);a&&a.focus()}},B=function attach(B){var j=arguments.length<=1||void 0===arguments[1]||arguments[1];(function $listModals(){var a=arguments.length<=0||void 0===arguments[0]?t:arguments[0];return[].slice.call(a.querySelectorAll("."+e))})(B).forEach((function(e){var a=Math.random().toString(32).slice(2,12),d=E(A),n=t.querySelector("body");if(e.setAttribute("id","label_modal_"+a),e.setAttribute("aria-haspopup","dialog"),null===d||0===d.length){var o=t.createElement("DIV");o.setAttribute("id",A),function wrapInner(t,e){for("string"==typeof e&&(e=document.createElement(e)),t.appendChild(e);t.firstChild!==e;)e.appendChild(t.firstChild)}(n,o),d=o}})),j&&["click","keydown"].forEach((function(B){t.body.addEventListener(B,(function(j){var T=I(j.target,e);if((!0===x(j.target,e)||""!==T)&&"click"===B){var M=t.querySelector("body"),w=""!==T?E(T):j.target,D=!0===w.hasAttribute(d)?w.getAttribute(d)+"-":"",F=!0===w.hasAttribute(n)?w.getAttribute(n):"",P=!0===w.hasAttribute(o)?w.getAttribute(o):"",_=!0===w.hasAttribute(i)?w.getAttribute(i):"",N=!0===w.hasAttribute(l)?w.getAttribute(l):"",S=!0===w.hasAttribute(s)?w.getAttribute(s):h,q=!0===w.hasAttribute(a)?w.getAttribute(a):"",O=!0===w.hasAttribute(r)?w.getAttribute(r):"",H=E(A);M.insertAdjacentHTML("beforeEnd",function createOverlay(t){var e=p,a=t.text||h,d=t.prefixClass+"modal-overlay",n="disabled"===t.backgroundEnabled?"disabled":"enabled";return'<span\n                    id="'+e+'"\n                    class="'+d+'"\n                    '+y+'="'+n+'"\n                    title="'+a+'"\n                    >\n                    <span class="invisible">'+a+"</span>\n                  </span>"}({text:S,backgroundEnabled:q,prefixClass:D})),M.insertAdjacentElement("beforeEnd",function createModal(t){var e=document.createElement("dialog"),a=document.createElement("div"),d=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");n.setAttribute("id",f),o.classList.add("mc-modal-title-container");var i=v,l=t.modalPrefixClass+"modal",r=t.modalPrefixClass+"modal__wrapper",s=t.modalPrefixClass+"modal-close",A='<span class="'+t.modalPrefixClass+'modal-close__text">\n                                          '+t.modalCloseText+"\n                                         </span>",p=t.modalPrefixClass+"modal__content",h=t.modalPrefixClass+"modal-title",y=""!==t.modalTitle?'<h1 id="'+g+'" class="'+h+'">\n                                          '+t.modalTitle+"\n                                         </h1>":"",C='<button type="button" class="'+u+" "+s+'" id="'+c+'" '+m+'="'+t.modalContentId+'" '+b+'="'+t.modalFocusBackId+'"><span class="dashicons dashicons-no" aria-hidden="true"></span>\n                               '+A+"\n                              </button>",k=t.modalText;if(""===k&&t.modalContentId){var x=E(t.modalContentId);x&&n.insertAdjacentElement("beforeEnd",x)}else n.insertAdjacentHTML("beforeEnd",k);return e.setAttribute("id",i),e.classList.add(l),e.setAttribute("role","dialog"),e.setAttribute("aria-describedby",t.modalDescribedById+" open"),e.setAttribute("aria-labelledby",g),a.setAttribute("role","document"),a.classList.add(r),o.insertAdjacentHTML("afterBegin",y),o.insertAdjacentHTML("afterBegin",C),d.classList.add(p),d.insertAdjacentElement("afterbegin",o),d.insertAdjacentElement("beforeEnd",n),a.insertAdjacentElement("afterBegin",d),e.insertAdjacentElement("afterBegin",a),e}({modalText:F,modalPrefixClass:D,backgroundEnabled:P,modalTitle:N,modalCloseText:S,modalCloseTitle:S,modalContentId:P,modalDescribedById:_,modalFocusBackId:w.getAttribute("id")})),H.setAttribute("inert",""),function addClass(t,e){t.classList?t.classList.add(e):t.className+=" "+e}(M,C);var V=E(c);if(""!==O){var $=E(O);$?$.focus():V.focus()}else V.focus();j.preventDefault()}var R=I(j.target,u);if((j.target.getAttribute("id")===c||""!==R||j.target.getAttribute("id")===p||!0===x(j.target,u))&&"click"===B){M=t.querySelector("body"),H=E(A);var K=E(v),W=E(f)?E(f):"",z=E(p),G=(Q=E(c)).getAttribute(b),J=Q.getAttribute(m);q=z.getAttribute(y);j.target.getAttribute("id")===p&&"disabled"===q||(L({modal:K,modalContent:W,overlay:z,modalFocusBackId:G,contentBackId:J,backgroundEnabled:q,fromId:j.target.getAttribute("id")}),H.removeAttribute("inert"),k(M,C))}if(E(v)&&"keydown"===B){M=t.querySelector("body"),H=E(A),K=E(v),W=E(f)?E(f):"",z=E(p),G=(Q=E(c)).getAttribute(b),J=Q.getAttribute(m);var Q,U=[].slice.call(K.querySelectorAll("a[href], area[href], input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]"));function checkElementVisibility(t){return t.checkVisibility()}U=U.filter(checkElementVisibility),27===j.keyCode&&(L({modal:K,modalContent:W,overlay:z,modalFocusBackId:G,contentBackId:J}),H.removeAttribute("inert"),k(M,C)),9===j.keyCode&&U.indexOf(j.target)>=0&&(j.shiftKey?j.target===U[0]&&(U.at(-1).focus(),j.preventDefault()):j.target===U.at(-1)&&(U[0].focus(),j.preventDefault())),9===j.keyCode&&-1===U.indexOf(j.target)&&(j.preventDefault(),U[0].focus())}}),!0)}))};document.addEventListener("DOMContentLoaded",(function onLoad(){B(),document.removeEventListener("DOMContentLoaded",onLoad)})),window.accessibleModalWindowAria=B}(document);