"use client"; import { useEffect, useState, type FC } from "react"; import { createPortal } from "react-dom"; type VideoPlayerProps = { isOpen: boolean; onClose: () => void; videoUrl?: string; }; export const VideoPlayer: FC = ({ isOpen, onClose, videoUrl, }) => { const [mounted, setMounted] = useState(false); // Default to a responsive landscape layout that adapts nicely const [containerStyle, setContainerStyle] = useState( "relative w-full max-w-[640px] aspect-video rounded-2xl overflow-hidden bg-black shadow-2xl transition-all duration-300 ease-out", ); useEffect(() => { setMounted(true); }, []); const handleLoadedMetadata = (e: React.SyntheticEvent) => { const video = e.currentTarget; if (video.videoWidth && video.videoHeight) { const ratio = video.videoWidth / video.videoHeight; if (ratio < 0.8) { // Vertical/portrait video (mobile format like TikTok/selfie) setContainerStyle( "relative w-full max-w-[340px] sm:max-w-[380px] aspect-[9/16] rounded-2xl overflow-hidden bg-black shadow-2xl max-h-[82vh] transition-all duration-300 ease-out", ); } else { // Horizontal/landscape video (standard format) setContainerStyle( "relative w-full max-w-[640px] sm:max-w-[720px] md:max-w-[800px] aspect-video rounded-2xl overflow-hidden bg-black shadow-2xl max-h-[85vh] transition-all duration-300 ease-out", ); } } }; if (!isOpen || !mounted) return null; return createPortal(
e.stopPropagation()}>
, document.body, ); }; export default VideoPlayer;