import React, { useEffect, useRef } from "react"; import "./Modal.scss"; import { useModalStore } from "../../stores/useModalStore"; import { modalContent } from "../../data/modalContent"; import { playSound } from "../../utils/audioSystem.js"; const Modal = () => { const { isModalOpen, modalID, closeModal } = useModalStore(); const modalRef = useRef(null); const handleClose = () => { playSound("thumpHover"); closeModal(); }; useEffect(() => { const handleEscapeKey = (e) => { if (e.key === "Escape" && isModalOpen) { closeModal(); } }; document.addEventListener("keydown", handleEscapeKey); return () => { document.removeEventListener("keydown", handleEscapeKey); }; }, [isModalOpen, closeModal]); useEffect(() => { const handleOutsideClick = (e) => { if (modalRef.current && !modalRef.current.contains(e.target)) { closeModal(); } }; if (isModalOpen) { document.addEventListener("mousedown", handleOutsideClick); } return () => { document.removeEventListener("mousedown", handleOutsideClick); }; }, [isModalOpen, closeModal]); useEffect(() => { if (isModalOpen) { document.body.style.overflow = "hidden"; document.body.style.cursor = "auto"; } else { document.body.style.overflow = "auto"; } return () => { document.body.style.overflow = "auto"; }; }, [isModalOpen]); if (!isModalOpen || !modalContent[modalID]) return null; const { title, link, linkText, paragraphs } = modalContent[modalID]; return (