"use client"; import { useEffect, useState, useRef } from 'react'; import { X, ChevronDown, ChevronUp } from 'lucide-react'; import { useDeviceType } from '@/hooks/useDeviceType'; interface TemplatePreviewModalProps { /** Control visibility */ open: boolean; /** Video URL to preview */ videoUrl: string | null; /** Close callback */ onClose: () => void; /** Optional title shown over the video */ title?: string; /** Optional description shown over the video */ description?: string; /** Optional primary action (e.g., Try it) */ onPrimaryAction?: () => void; /** Optional primary action label */ primaryLabel?: string; } /** * Fullscreen, Tailwind-based template preview modal with video content. * Overlays title/description if provided and supports an optional primary action. * Supports expand/collapse for long descriptions and H5 responsive design. */ export function TemplatePreviewModal({ open, videoUrl, onClose, title, description, onPrimaryAction, primaryLabel = 'Try this', }: TemplatePreviewModalProps) { const [isReady, setIsReady] = useState(false); const [isExpanded, setIsExpanded] = useState(false); const [showExpandButton, setShowExpandButton] = useState(false); const descriptionRef = useRef(null); const { isMobile } = useDeviceType(); useEffect(() => { if (!open) { setIsReady(false); setIsExpanded(false); } }, [open]); useEffect(() => { if (isReady && description && descriptionRef.current) { const element = descriptionRef.current; const isOverflowing = element.scrollHeight > element.clientHeight; setShowExpandButton(isOverflowing); } }, [isReady, description]); if (!open || !videoUrl) return null; return ( <>
e.stopPropagation()} >
); } export default TemplatePreviewModal;