import { useEffect, useRef } from 'react'; import { createPortal } from 'react-dom'; import { OVERLAY_Z_MODAL } from '../../lib/overlayLayers'; import { __ } from '../../lib/i18n'; import { NavIcon } from '../NavIcon'; type Props = { open: boolean; subject: string; html: string; onClose: () => void; }; /** * Email preview dialog — subject strip + scrollable HTML (wrapped by API), footer Close. */ export function EmailPreviewModal(props: Props) { const { open, subject, html, onClose } = props; const panelRef = useRef(null); useEffect(() => { if (!open) { return; } const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } }; document.addEventListener('keydown', onKey); const prev = document.body.style.overflow; document.body.style.overflow = 'hidden'; return () => { document.removeEventListener('keydown', onKey); document.body.style.overflow = prev; }; }, [open, onClose]); useEffect(() => { if (!open || !panelRef.current) { return; } const focusable = panelRef.current.querySelector( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])' ); focusable?.focus(); }, [open]); if (!open || typeof document === 'undefined') { return null; } return createPortal(
✉️ {__('Subject', 'sikshya')}

{subject || '—'}