import { Play } from 'lucide-react'; import { useState } from 'react'; import { cn } from '@/lib/utils'; import { useStorefront } from '../context'; import { storefrontText } from '../text'; import type { VideoSection } from '../types'; import { Container, SfButton } from '../ui'; type Video = { provider: 'youtube' | 'vimeo'; id: string }; /** The video behind a YouTube or Vimeo address, or null for anything else. */ export function parseVideo(url: string): Video | null { const youtube = url.match( /^https:\/\/(?:(?:www\.|m\.)?youtube\.com\/(?:watch\?v=|shorts\/)|youtu\.be\/)([A-Za-z0-9_-]{6,20})/, ); if (youtube) { return { provider: 'youtube', id: youtube[1] }; } const vimeo = url.match(/^https:\/\/(?:www\.)?vimeo\.com\/([0-9]{5,12})/); return vimeo ? { provider: 'vimeo', id: vimeo[1] } : null; } /** * A YouTube or Vimeo video. Until the shopper presses play only a picture shows, so the page stays fast * and nothing from the video site loads for shoppers who never watch. */ export function VideoBlock({ section }: { section: VideoSection }) { const { heading, text, videoUrl, cta } = section.content; const split = section.variant === 'split'; const video = parseVideo(videoUrl); if (!video) { return null; } const words = (
{text}
)} {cta && (