var C=(c,r,t)=>new Promise((p,i)=>{var m=l=>{try{o(t.next(l))}catch(d){i(d)}},u=l=>{try{o(t.throw(l))}catch(d){i(d)}},o=l=>l.done?p(l.value):Promise.resolve(l.value).then(m,u);o((t=t.apply(c,r)).next())});import{r as T,dx as x,j as L,dy as j}from"./main-40.js";import{S as R}from"./bf-200-122.js";function P({id:c,value:r,formFields:t,smartTags:p=!0,onChangeHandler:i,toolbarMnu:m,menubar:u,height:o,width:l,disabled:d,plugins:k,mapAllFieldWithTable:v,mapAllField:$}){const s=`${c}-settings`,h="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.9.11",[y,F]=T.useState(typeof window.tinymce!="undefined"),A=y&&window.tinymce.baseURI.source===h,M=()=>C(this,null,function*(){(yield j({src:h+"/tinymce.min.js",integrity:"sha256-SnRzknLClR3GaNw9oN4offMGFiPbXQTP7q0yFLPPwgY=",id:"tinymceCDN"}))||console.warn("Is your internet working properly to load script?");const n=setInterval(()=>{typeof window.tinymce!="undefined"&&(clearInterval(n),F(!0))},100)});T.useEffect(()=>(y||M(),E(),()=>{var n;const e=((n=window.tinymce)==null?void 0:n.get(s))||null;e&&e.remove()}),[y]);const g=e=>e.type==="signature"?`<img width="250" src="\${${e.key}}" alt="${e.key}" />`:`\${${e.key}}`,I=()=>{let e='<table border="1" style="border-collapse: collapse; width: 100%;">';return t==null||t.map(n=>{!x.includes(n.type)&&(e+=`<tr style="border: 1px solid #dddddd; text-align: left; padding: 8px;"><td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">${n.name}</td><td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">${g(n)}</td></tr>`)}),e+="</table>",e},S=()=>{let e="";return t==null||t.map(n=>{!x.includes(n.type)&&(e+=`<p>${n.name}: ${g(n)}</p>`)}),e},E=()=>{window&&window.tinymce&&window.tinymce.init({selector:`textarea#${s}`,menubar:u,height:o||150,width:l||"100%",branding:!1,resize:"verticle",convert_urls:!1,theme:"modern",plugins:k||`directionality fullscreen image link media charmap hr lists textcolor colorpicker ${A?"":"wordpress"}`,toolbar:m||"formatselect | fontsizeselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | removeformat toogleCode wp_code | addFormField | addSmartField | mapAllFieldWithTable | mapAllField",image_advtab:!0,default_link_target:"_blank",setup(e){var n;e.on("Paste Change input Undo Redo",()=>{i(e.getContent())}),t&&e.addButton("addFormField",{text:"Form Fields ",tooltip:"Add Form Field Value in Message",type:"menubutton",icon:!1,menu:t==null?void 0:t.map(a=>!x.includes(a.type)&&{text:a.name,onClick(){e.insertContent(g(a))}})}),p&&e.addButton("addSmartField",{text:"Smart Tag Fields",tooltip:"Add Smart Tag Field Value in Message",type:"menubutton",icon:!1,menu:(n=R)==null?void 0:n.map(a=>({text:a.label,onClick(){e.insertContent(`\${${a.name}}`)}}))}),v&&e.addButton("mapAllFieldWithTable",{text:"Map All Field With Table",tooltip:"Map All Field With Table",icon:!1,onclick(){e.insertContent(I())}}),$&&e.addButton("mapAllField",{text:"Map All Field",tooltip:"Map All Field",icon:!1,onclick(){e.insertContent(S())}}),e.addButton("toogleCode",{text:"</>",tooltip:"Toggle preview",icon:!1,onclick(a){const{$:b}=a.control,w=b(`#${s}`),_=b(e.iframeElement);if(w.value=e.getContent({source_view:!0}),_.toggleClass("btcd-mce-tinymce-hidden"),w.toggleClass("btcd-mce-tinymce-visible"),b("iframe.btcd-mce-tinymce-hidden").length>0)w.prependTo(".mce-edit-area");else{const f=document.getElementById(s);f instanceof HTMLTextAreaElement&&e.setContent(f.value)}}})}})};return L.jsx("textarea",{id:s,className:"btcd-paper-inp mt-1 w-10",rows:5,value:r,onChange:e=>i(e.target.value),style:{width:"95.5%",height:"auto"},disabled:d})}export{P as T};
