import React, { useEffect, useRef, useState } from "react"; import VideoButton from "../buttons/video-button.jsx"; import Link from "next/link"; const Section = ({ videoUrl, text, videoId, buttonOneText, buttonTwoText, buttonLink = "/", headingLevel = 1, }) => { const videoRef = useRef(null); const [isPlaying, setIsPlaying] = useState(false); const [hasInteracted, setHasInteracted] = useState(false); useEffect(() => { const options = { root: null, rootMargin: "0px", threshold: 0.5, }; const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { setIsPlaying(true); if (!isMobile) { videoRef.current?.play(); } } else { setIsPlaying(false); videoRef.current?.pause(); } }); }, options); if (videoRef.current) { observer.observe(videoRef.current); } return () => { if (videoRef.current) { observer.unobserve(videoRef.current); } }; }, []); let isMobile = false; if (typeof window !== "undefined") { isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); } const Heading = headingLevel === 1 ? "h1" : "h2"; return (