import React, { useRef, useEffect } from 'react'; import type { SlideLayout, Theme } from '../../types/theme'; import { renderTemplateWithSampleData, createPreviewDocument } from '../../utils/templateRenderer'; interface LayoutPreviewProps { layout: SlideLayout; theme: Theme; className?: string; } export const LayoutPreview: React.FC = ({ layout, theme, className = '' }) => { const iframeRef = useRef(null); useEffect(() => { if (!iframeRef.current) return; const iframe = iframeRef.current; // Render the template with sample data const renderedTemplate = renderTemplateWithSampleData(layout.htmlTemplate, layout); // Create the preview document with theme CSS const themeCssUrl = `${theme.basePath}/${theme.cssFile}`; const previewDocument = createPreviewDocument(renderedTemplate, themeCssUrl); // Write the document to the iframe const iframeDoc = iframe.contentDocument || iframe.contentWindow?.document; if (iframeDoc) { iframeDoc.open(); iframeDoc.write(previewDocument); iframeDoc.close(); } }, [layout, theme]); return (
{layout.name}
{layout.slots.length} slot{layout.slots.length !== 1 ? 's' : ''}