import{u as c}from"./Dnx2rQWa.js";import{d,w as l,a as m,b as h,c as f,o as g,e as p,n as u}from"./DINJ4NqB.js";import{_ as w}from"./Cw10yt2r.js";const y=d({__name:"RichContent",props:{content:{}},setup(i){const o=i,s=c(),n=p(null),a=e=>{if(!n.value)return;n.value.style.height="0px";const t=n.value.contentDocument;t&&(t.open(),t.write(`
      <!DOCTYPE html>
      <html style="margin: 0; padding: 0; overflow: hidden;">
      <head>
        <link rel="stylesheet" href="https://cdn.ckeditor.com/4.22.1/full-all/contents.css">
        <style>
          /* 1. 强制覆盖 CKEditor 的默认 margin */
          html, body {
            margin: 0 !important;
            padding: 0 !important;
            height: auto !important; /* 严禁设置 100% */
            overflow: hidden !important; 
          }

          body {
            font-size: 13px;
            line-height: 1.6;
            word-wrap: break-word;
            box-sizing: border-box;
          }
        </style>
      </head>
      <body>
        <div id="measure-container" style="display: flow-root;">
          ${e}
        </div>
        <script>
          function sendHeight() {
            const container = document.getElementById('measure-container');
            if (!container) return;

            // 关键：获取 offsetHeight 或 scrollHeight
            // 使用 flow-root 可以包含子元素的 margin，从而计算出真实高度
            const height = container.offsetHeight;
            
            window.parent.postMessage({
              type: 'iframe-height',
              height: height
            }, '*');
          }

          window.addEventListener('load', sendHeight);
          new ResizeObserver(sendHeight).observe(document.body);
          
          // 针对图片，如果图片没高度，加载完后要重测
          document.querySelectorAll('img').forEach(img => {
            img.onload = sendHeight;
          });

          document.body.addEventListener('click', function(e) {
            const targetTag = e.target.closest('a');
            if (!targetTag) return;

            const href = targetTag.getAttribute('href');
            if (href && href.includes('support#contact-us')) {
              e.preventDefault(); // 阻止浏览器跳转行为
              
              // 发送弹窗指令给父级 Vue 页面
              window.parent.postMessage({
                type: 'open-contact-modal'
              }, '*');
            }
          });
        <\/script>
      </body>
      </html>
    `),t.close())},r=e=>{if(e.data?.type==="iframe-height"&&n.value){const t=e.data.height;t>0&&(n.value.style.height=`${t}px`)}else e.data?.type==="open-contact-modal"&&s.setVisible(!0)};return l(()=>o.content,e=>{u(()=>a(e))}),m(()=>{window.addEventListener("message",r),a(o.content)}),h(()=>{window.removeEventListener("message",r)}),(e,t)=>(g(),f("iframe",{ref_key:"iframeRef",ref:n,class:"rich-content-iframe",frameborder:"0",scrolling:"no"},null,512))}}),x=Object.assign(w(y,[["__scopeId","data-v-ddd6b6f1"]]),{__name:"RichContent"});export{x as _};
