import{_ as H,$,p as I,V as B,O as E,o as r,c as u,e as i,t as c,f as v,b as g,F as R,h as M,j as p,n as x,q as k,w as q,v as A,r as b,P as V}from"../index.js";const D={class:"rte-wrap"},F={class:"rte-topbar"},N={key:0,class:"rte-merge-bar"},U={class:"rte-merge-label"},j={value:""},L=["value"],O={key:1,class:"rte-tabs"},P={class:"rte-body"},G=["value","placeholder"],J=["id","placeholder"],K={__name:"RichTextEditor",props:{modelValue:{type:String,default:""},placeholder:{type:String,default:""},mergeTags:{type:Array,default:null},minHeight:{type:String,default:"200px"}},emits:["update:modelValue"],setup(s,{emit:C}){$(e=>({v3c52e434:s.minHeight}));const d=s,f=C,m=`crm-rte-${Math.random().toString(36).slice(2)}`,o=b("visual"),n=b(""),h=b(!1);let t=null;I(()=>{n.value=d.modelValue||"",window.tinymce&&(h.value=!0,window.tinymce.init({selector:`#${m}`,plugins:"link lists",toolbar:"bold italic underline strikethrough | forecolor | bullist numlist | blockquote | alignleft aligncenter alignright | link unlink | removeformat",menubar:!1,statusbar:!1,branding:!1,min_height:parseInt(d.minHeight,10)||200,content_style:"body { font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #1d2327; margin: 8px 12px; }",setup(e){t=e,e.on("input change keyup",()=>{const a=e.getContent();n.value=a,f("update:modelValue",a)}),e.on("init",()=>{e.setContent(d.modelValue||"")})}}))}),B(()=>{t&&(t.destroy(),t=null)}),E(()=>d.modelValue,e=>{n.value=e||"",t&&t.initialized&&t.getContent()!==e&&t.setContent(e||"")});function y(e){e!==o.value&&(e==="text"?t&&t.initialized&&(n.value=t.getContent()):V(()=>{t&&t.initialized&&(t.setContent(n.value),t.focus())}),o.value=e)}function w(e){n.value=e.target.value,f("update:modelValue",e.target.value)}function _(e){if(o.value==="visual"&&t&&t.initialized)t.insertContent(e),t.focus();else{const a=document.getElementById(`${m}-raw`);if(a){const l=a.selectionStart??n.value.length,T=a.selectionEnd??l,S=n.value.slice(0,l),z=n.value.slice(T);n.value=S+e+z,f("update:modelValue",n.value),V(()=>{a.focus(),a.setSelectionRange(l+e.length,l+e.length)})}}}return(e,a)=>(r(),u("div",D,[i("div",F,[s.mergeTags&&s.mergeTags.length?(r(),u("div",N,[i("span",U,c(v(g)("Insert:","pressio-crm")),1),i("select",{class:"rte-merge-select",onChange:a[0]||(a[0]=l=>{_(l.target.value),l.target.value=""})},[i("option",j,c(v(g)("— variable —","pressio-crm")),1),(r(!0),u(R,null,M(s.mergeTags,l=>(r(),u("option",{key:l.value,value:l.value},c(l.label),9,L))),128))],32)])):p("",!0),h.value?(r(),u("div",O,[i("button",{type:"button",class:x(["rte-tab",{"rte-tab--active":o.value==="visual"}]),onClick:a[1]||(a[1]=l=>y("visual"))},c(v(g)("Visual","pressio-crm")),3),i("button",{type:"button",class:x(["rte-tab",{"rte-tab--active":o.value==="text"}]),onClick:a[2]||(a[2]=l=>y("text"))},c(v(g)("Text","pressio-crm")),3)])):p("",!0)]),i("div",P,[i("div",{style:k({display:o.value==="visual"?"block":"none"})},[i("textarea",{id:m,value:s.modelValue,placeholder:s.placeholder,class:"rte-tinymce-target"},null,8,G)],4),o.value==="text"||!h.value?q((r(),u("textarea",{key:0,id:`${m}-raw`,"onUpdate:modelValue":a[3]||(a[3]=l=>n.value=l),placeholder:s.placeholder,style:k({minHeight:s.minHeight}),class:"crm-textarea rte-raw",onInput:w},null,44,J)),[[A,n.value]]):p("",!0)])]))}},W=H(K,[["__scopeId","data-v-73df6b1d"]]);export{W as R};
