(()=>{"use strict";function t(t,e){if(!t||t.dataset.eddModalBound)return;t.dataset.eddModalBound="true";const n=t.querySelector(".edd-modal__close");n&&n.addEventListener("click",(function(t){t.preventDefault(),t.stopPropagation(),e()})),t.addEventListener("click",(function(n){n.target===t&&e()}))}document.addEventListener("DOMContentLoaded",(function(){const e=document.querySelector(".edd-email-styles-inserter"),n=e?function(e){if(e.dialog){const n=e.dialog;if(!n||"function"!=typeof n.showModal)return null;const o=function(){n&&"function"==typeof n.close&&n.close()};return t(n,o),{open:function(){n.showModal(),"function"==typeof e.onOpen&&e.onOpen(n)},close:o,getDialog:function(){return n}}}const n="string"==typeof e.trigger,o=n?document.querySelector(e.trigger):e.trigger,c=e.dialogId||o?.getAttribute("data-dialog-id")||"";let l=c?document.getElementById(c):null;function i(){return!l&&c&&(l=document.getElementById(c)),l}function r(t){const n=t||i();n&&"function"==typeof n.showModal&&(n.showModal(),"function"==typeof e.onOpen&&e.onOpen(n))}function s(){const t=i();t&&"function"==typeof t.close&&t.close()}return n&&e.trigger?(document.body.addEventListener("click",(function(n){const o=n.target.closest(e.trigger);if(!o)return;n.preventDefault();const l=o.getAttribute("data-dialog-id")||c,i=l?document.getElementById(l):null;i&&(t(i,(function(){i&&"function"==typeof i.close&&i.close()})),r(i))})),{open:r,close:s,getDialog:i}):l&&"function"==typeof l.showModal?(t(l,s),o&&o.addEventListener("click",(function(t){t.preventDefault(),r()})),{open:r,close:s,getDialog:i}):null}({trigger:e}):null;!function(t){const e=document.querySelectorAll(".edd-email-styles__button");e.length&&e.forEach((function(e){e.addEventListener("click",(function(){const n=e.dataset.formatName;t&&"function"==typeof t.close&&t.close(),n&&function(t){const e=eddEmailStyles||{},n=e.editorId||"edd-email-content",o=e.formats||[],c=globalThis.tinymce?.get(n);if(!c||!t)return;const l=o.find((function(e){return e.name===t}));if(!l)return;const i=(r=l.classes)?Array.isArray(r)?r.join(" "):r:"";var r;const s=function(t){if(!t||"object"!=typeof t)return"";const e=[];return Object.keys(t).forEach((function(n){const o=t[n];null!=o&&""!==o&&e.push(n+":"+o)})),e.join("; ")}(l.styles),u=i?' class="'+i.replaceAll(/"/g,"&quot;")+'"':"",d=s?' style="'+s.replaceAll(/"/g,"&quot;")+'"':"";if(c.focus(),l.block){const t=l.block||"div",e=c.selection.getContent({format:"html"}),n="<"+t+u+d+">"+(e?.trim()?e:"&nbsp;")+"</"+t+">";c.execCommand("mceInsertContent",!1,n)}else if("a"===l.selector){const t=c.selection.getContent({format:"html"});let n="#",o=e.linkPlaceholder||"Link";if(t?.trim()){const e=document.createElement("div");e.innerHTML=t;const c=e.querySelector("a");c?(n=c.dataset.href||n,o=c.innerHTML):o=t}const l='<a href="'+(n||"#").replaceAll(/"/g,"&quot;")+'"'+u+d+">"+o+"</a>";c.execCommand("mceInsertContent",!1,l)}}(n)}))}))}(n)}))})();