export function createIframeContent(code: string): string {
  return `
  <!DOCTYPE html>
  <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <base target="_blank">
      <style>
        html, body {
          margin: 0;
          padding: 0;
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
          color: inherit;
        }
        body {
          padding: 12px;
        }
        a { color: #0066cc; }
        img { max-width: 100%; height: auto; }
      </style>
    </head>
    <body>
      ${code || '<p>Add custom HTML here</p>'}
      <script>
        function updateHeight() {
          const height = document.documentElement.offsetHeight;
          window.parent.postMessage({ type: 'resize', height: height }, '*');
        }

        updateHeight();

        document.querySelectorAll('img').forEach(img => {
          img.onload = updateHeight;
        });

        new MutationObserver(updateHeight).observe(document.body, {
          childList: true,
          subtree: true,
          attributes: true
        });
      </script>
    </body>
  </html>
`;
}
