document.addEventListener("DOMContentLoaded", function() {
    setupSharingModal();
});

function setupSharingModal() {
    // Get the modal
    var modalSharing = document.getElementById("sharingModal");

    // Get all links that should open in the modal
    var linkObjs = document.querySelectorAll(".sharing-modal-link");

    // Get the iframe inside the modal
    var modalSharingIframe = document.getElementById("modalSharingIframe");

    // Get the close button
    var closeBtn = document.querySelector(".close-btn-sharing");

    // Loop through each link and add a click event listener
    linkObjs.forEach(link => {
        link.addEventListener("click", function(event) {
            event.preventDefault(); // Prevent default link behavior
            var url = this.href; // Get the link URL
            modalSharingIframe.src = url; // Load the URL inside the iframe
            modalSharing.style.display = "flex"; // Show the modal
        });
    });
	if (closeBtn) {
		// Close the modal when clicking the close button
		closeBtn.onclick = function() {
			modalSharing.style.display = "none";
			modalSharingIframe.src = ""; // Reset iframe to stop loading content
		};
	}
}
