import React, { useState } from "react"; import { ContentfulVideoEmbed } from "./contentful-video-embed"; import { PlayButton } from "./helper"; import { VideoLinkComponentProps } from "./types"; import { VimeoEmbed } from "./vimeo-embed"; import { YoutubeEmbed } from "./youtube-embed"; import { NextImage } from "@shared/components/next-image"; import { cx } from "@shared/utils"; // Owns all video state (active/hover) so ImagePromoBar stays state-free for video. export const VideoLink: React.FC = ({ videoLink, imageWidth = 660, imageHeight = 660, useOriginalImageAspectRatio = false, isAboveTheFold = false, }) => { const [activeVideo, setActiveVideo] = useState(""); const [isHovered, setIsHovered] = useState(false); const videoSourceType = videoLink?.videoSourceType; const videoHref = (videoSourceType === "contentful" ? videoLink?.videoAssetUrl : videoLink?.link) ?? ""; // The video's own poster - never the promo bar's plain image field. const posterImage = videoLink?.image; if (!videoHref) { if (!posterImage) { return null; } return (
); } const videoPopup = videoLink?.videoPopup ?? false; const isPlaying = Boolean(activeVideo && activeVideo === videoHref); const handlePlayClick = () => { setActiveVideo(videoHref); }; const handleCloseVideo = (e: React.MouseEvent) => { e.stopPropagation(); setActiveVideo(""); }; const embedSelector = () => { if (videoSourceType === "contentful") { return ( ); } if (videoHref.includes("vimeo")) { return ; } return ; }; const contentVideo = embedSelector(); return ( <>
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {/* Preview Image & Play Button */}
{posterImage && ( )}
{/* Inline Player (if not popup) */} {!videoPopup && isPlaying && (
{contentVideo}
)}
{/* Video Popup Overlay */} {videoPopup && isPlaying && (
e.stopPropagation()} > {contentVideo}
)} ); }; export default VideoLink; export { ContentfulVideoEmbed } from "./contentful-video-embed"; export { PlayButton } from "./helper"; export { VimeoEmbed } from "./vimeo-embed"; export { YoutubeEmbed } from "./youtube-embed"; export type { PlayButtonProps, VideoEmbedProps, VideoLinkComponentProps, VideoLinkProps, } from "./types";