import { useEffect, useRef, useState } from "react"; import PropTypes from "prop-types"; import { Layout } from "antd"; import ContentRenderer from "./ContentRenderer"; import HeaderLogo from "./HeaderLogo"; import ScrollIcon from "../icons/ScrollIcon"; import { useMediaQuery } from "react-responsive"; import ImageCarousel from "./ImageCarousel"; import CloseButton from "./CloseButton"; import MenuButton from "./MenuButton"; import { useSettingsContext } from "../contexts/SettingsContext"; const { Content } = Layout; const Page = ({ pageData, theme = null, visible = true, id = 0, showClose = false, isSubPage = false, showMenu = true, onClose = () => {}, }) => { const isLargeMobile = useMediaQuery({ maxWidth: 1200 }); const isMobile = useMediaQuery({ maxWidth: 800 }); const mobileImage = isMobile && !pageData.showProperties && !pageData.showContactForm && !pageData.hideMobileImage; const contentRef = useRef(null); const [isImageShrunk, setIsImageShrunk] = useState(false); const [safariBlurToggle, setSafariBlurToggle] = useState(false); const shrinkDistance = 1; const settings = useSettingsContext(); const themes = settings?.themes || []; if (theme == null) { theme = settings?.globalThemes?.page || settings?.themes[0]; } // Reset scroll position and image state when visible becomes false useEffect(() => { if (!visible && contentRef.current) { contentRef.current.scrollTop = 0; setIsImageShrunk(false); } }, [visible]); // SafariBlurToggle animation when isImageShrunk changes useEffect(() => { if (!mobileImage) return; let animationId; let timeoutId; const startTime = Date.now(); const duration = 750; // 0.75 seconds const animate = () => { const elapsed = Date.now() - startTime; if (elapsed < duration) { setSafariBlurToggle((prev) => !prev); animationId = requestAnimationFrame(animate); } else { // Stop toggling after 0.75s setSafariBlurToggle(false); } }; // Start the animation animationId = requestAnimationFrame(animate); return () => { if (animationId) { cancelAnimationFrame(animationId); } if (timeoutId) { clearTimeout(timeoutId); } }; }, [isImageShrunk, mobileImage]); useEffect(() => { if (!contentRef.current || !mobileImage) return; const handleScroll = () => { // Don't shrink image if page is not visible if (!visible) return; const el = contentRef.current; const scrollTop = el.scrollTop; const scrollHeight = el.scrollHeight; const clientHeight = el.clientHeight; // Check if the container can be scrolled (is overflowing) const canScroll = scrollHeight > clientHeight; const shouldShrink = scrollTop > shrinkDistance; // If container can't be scrolled, keep image shrunk if it's already shrunk if (!canScroll && isImageShrunk) { return; // Keep the image shrunk } // If container can be scrolled, allow image to un-shrink when at top if (canScroll) { if (scrollTop <= shrinkDistance) { setIsImageShrunk(false); } else if (shouldShrink) { setIsImageShrunk(true); } } else if (shouldShrink) { // If container can't be scrolled but we're past threshold, shrink setIsImageShrunk(true); } }; const el = contentRef.current; el.addEventListener("scroll", handleScroll); return () => { el.removeEventListener("scroll", handleScroll); }; }, [mobileImage, visible, isImageShrunk]); return (