import React, { useRef, useState, useEffect } from "react"; import styles from "../EntranceModal/EntranceModal.module.css"; export default function Modal({ children, title, isOpen, toggleModal }) { const modalRef = useRef(null); const [dragging, setDragging] = useState(false); const [position, setPosition] = useState({ x: "50%", y: "50%" }); const [offset, setOffset] = useState({ x: 0, y: 0 }); const handleMouseDown = (e) => { if (!modalRef.current) return; setDragging(true); const rect = modalRef.current.getBoundingClientRect(); setOffset({ x: e.clientX - rect.left, y: e.clientY - rect.top, }); }; const handleMouseMove = (e) => { if (!dragging) return; setPosition({ x: e.clientX - offset.x, y: e.clientY - offset.y, }); }; const handleMouseUp = () => { setDragging(false); }; useEffect(() => { if (dragging) { window.addEventListener("mousemove", handleMouseMove); window.addEventListener("mouseup", handleMouseUp); } else { window.removeEventListener("mousemove", handleMouseMove); window.removeEventListener("mouseup", handleMouseUp); } return () => { window.removeEventListener("mousemove", handleMouseMove); window.removeEventListener("mouseup", handleMouseUp); }; }, [dragging]); if (isOpen) { document.body.classList.add(styles.activeModal); } else { document.body.classList.remove(styles.activeModal); } return ( <> {isOpen && (