var e;let t="*";"undefined"!=typeof __DEV__&&__DEV__&&(t=sessionStorage.getItem("ctc_debug")||"*",window.ctcDebug=e=>{t="string"==typeof e?e:"*",sessionStorage.setItem("ctc_debug",t)}),"undefined"!=typeof __DEV__&&__DEV__;const n=["__proto__","prototype","constructor","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],o=function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return e&&"object"==typeof e&&(e=>"string"==typeof e&&e.length>0&&/^[a-zA-Z0-9_-]+$/.test(e)&&!n.includes(e))(t)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:o},i=("undefined"!=typeof document&&document.createElement("div"),"undefined"!=typeof DOMParser?new DOMParser:null),a="undefined"!=typeof document?document.createElement("textarea"):null,r=(window.ht_ctc_admin_var,null===(e=window.ht_ctc_admin_var)||void 0===e||null===(e=e.initialSettings)||void 0===e||e.ht_ctc_chat_options,function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"form-group";const i=document.createElement("div"),a=e.class_pr||"",r=e.class_field||"";i.className=`${n} ${a}`.trim(),e.id&&(i.id=`wrapper-${e.id}`),((e,t)=>{e&&t&&(t.data_watch&&(e.setAttribute("data-watch",t.data_watch),t.data_show_on_change&&e.setAttribute("data-show-on-change",t.data_show_on_change),void 0!==t.data_show_when?e.setAttribute("data-show-when",t.data_show_when):t.data_hide_when||t.data_show_on_change||e.setAttribute("data-show-when","1"),t.data_hide_when&&e.setAttribute("data-hide-when",t.data_hide_when)),t.action_onchange&&e.setAttribute("data-action-onchange",t.action_onchange),t.action_onclick&&e.setAttribute("data-action-onclick",t.action_onclick))})(i,e);let l="",d="";return e.option_group&&e.id&&(l=((e,t,n)=>{if(!e||!t)return"";const i=`${t}[${n}]`.split(/\[|\]/).filter(e=>e);let a=e;for(const e of i)if(a=o(a,e),!a)return"";return void 0!==a?a:""})(t.initialSettings,e.option_group,e.id),""!==l&&void 0!==l||void 0===e.default||(l=e.default),d=`${e.option_group}[${e.id}]`),{wrapper:i,value:l,name:d,inputClass:r,field:e}}),l=(e,t,n)=>{var o;e.id;const l=r(e,n,"form-group ctc-enterkey-newline"),d=l.wrapper,c=l.value,s=l.name,p=l.inputClass,u=`${e.id}_${Date.now()}_${Math.floor(1e3*Math.random())}`;let _=c?(e=>{var t;if("string"!=typeof e)return e;if(null!==(t=window.wp)&&void 0!==t&&null!==(t=t.htmlEntities)&&void 0!==t&&t.decodeEntities)return window.wp.htmlEntities.decodeEntities(e);const n=e.replace(/<\/\s*textarea\s*>/gi,"&lt;/textarea&gt;");return i?i.parseFromString(`<textarea>${n}</textarea>`,"text/html").querySelector("textarea").value:a?(a.innerHTML=n,a.value):e})(c):"";if("undefined"!=typeof wp&&null!==(o=wp)&&void 0!==o&&null!==(o=o.editor)&&void 0!==o&&o.autop&&(_=wp.editor.autop(_)),e.label){const t=document.createElement("label");t.htmlFor=u,t.textContent=e.label,d.appendChild(t)}const h=document.createElement("textarea");h.id=u,h.name=s,h.className=p,h.rows=e.rows||10,h.value=_,d.appendChild(h),((e,t)=>{if("field_hidden"!==t.field_type){if(t.help){const n=document.createElement("p");n.className="help-text",n.innerHTML=Array.isArray(t.help)?t.help.join("<br>"):t.help,e.appendChild(n)}if(t.help_click){const n=e.querySelector("label");if(n){const e=document.createElement("button");e.type="button",e.className="help-toggle",e.setAttribute("aria-label","Toggle more information"),e.innerHTML='<span class="dashicons dashicons-editor-help"></span>',n.appendChild(e)}const o=document.createElement("p");o.className="help-text help-click-text",o.innerHTML=Array.isArray(t.help_click)?t.help_click.join("<br>"):t.help_click,e.appendChild(o)}}})(d,e);const f=()=>{if(!window.wp||!wp.editor)return;wp.editor.remove(u);const t=e.editor_type||"full",n={fontsize_formats:"6px 8px 10px 12px 13px 14px 15px 16px 18px 20px 24px 28px 32px 36px",content_style:"body { background-color: #26a69a; }",elementpath:!0},o="lite"===t?{...n,toolbar1:"bold link italic underline forecolor backcolor fontsizeselect fontselect undo redo removeformat",toolbar2:!1,height:150}:{...n,wordpress_adv_hidden:!1,height:250,toolbar1:"formatselect | bold italic | bullist numlist | blockquote | alignleft aligncenter alignright | link unlink | wp_more | wp_adv",toolbar2:"fontsizeselect fontselect | strikethrough hr | forecolor backcolor pastetext | removeformat | charmap | outdent indent | undo redo | wp_help"};o.setup=function(e){e.on("input change keyup paste",function(){"true"!==h.dataset.ctcSyncingFromServer&&(e.save(),h.dispatchEvent(new Event("input",{bubbles:!0})),h.dispatchEvent(new Event("change",{bubbles:!0})))})},wp.editor.initialize(u,{textarea_name:s,editor_height:"lite"===t?150:250,mediaButtons:"lite"!==t,quicktags:!0,tinymce:o})};if(h.isConnected)f();else{const e=new MutationObserver(()=>{h.isConnected&&(e.disconnect(),f())});e.observe(document.body,{childList:!0,subtree:!0})}return d},d=l;export{l as createBlockEditorTinymce,d as default};