    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function copyToClipboard(elementId) {
        const input = document.querySelector(elementId);
        input.select();
        input.setSelectionRange(0, 99999); // For mobile devices
        document.execCommand("copy");
        alert("Link copiado para a área de transferência!");
    }

    // WhatsApp Integration Fix
    let currentWhatsappMessage = '';
    
    function openWhatsAppModal(id, message, phone = '') {
        document.getElementById('whatsapp-message-global').value = message;
        document.getElementById('whatsapp-phone-global').value = phone;
        
        // If we have a phone number (at least 10 digits), we can go straight to WhatsApp
        if (phone && phone.length >= 10) {
            const whatsappUrl = `https://api.whatsapp.com/send?phone=${phone}&text=${encodeURIComponent(message)}`;
            window.open(whatsappUrl, '_blank');
            return; // Don't show modal
        }

        // Otherwise, show the global modal
        const openModals = document.querySelectorAll('.modal.show');
        openModals.forEach(m => {
            const modalInstance = bootstrap.Modal.getInstance(m);
            if (modalInstance) modalInstance.hide();
        });

        const modal = new bootstrap.Modal(document.getElementById('globalWhatsappModal'));
        modal.show();
    }

    function confirmSendWhatsApp() {
        const phoneInput = document.getElementById('whatsapp-phone-global');
        const message = document.getElementById('whatsapp-message-global').value;
        const phoneNumber = phoneInput.value.replace(/\D/g, ''); // Remove non-digits
        
        if (phoneNumber.length >= 10) {
            const whatsappUrl = `https://api.whatsapp.com/send?phone=${phoneNumber}&text=${encodeURIComponent(message)}`;
            window.open(whatsappUrl, '_blank');
            // Close modal
            const modalElement = document.getElementById('globalWhatsappModal');
            const modal = bootstrap.Modal.getInstance(modalElement);
            modal.hide();
        } else {
            alert('Por favor, digite um número de telefone válido com DDD (ex: 41999998888).');
        }
    }

    function sendWhatsApp(linkId, message) {
        // Keeping this for backward compatibility if needed, but the new way is openWhatsAppModal
        const numberInput = document.getElementById('whatsapp-number-' + linkId);
        const phoneNumber = numberInput.value ? numberInput.value.replace(/\D/g, '') : '';
        
        if (phoneNumber) {
            const whatsappUrl = `https://api.whatsapp.com/send?phone=${phoneNumber}&text=${encodeURIComponent(message)}`;
            window.open(whatsappUrl, '_blank');
        } else {
            alert('Por favor, digite um número de telefone válido.');
        }
    }
</script>
</body>
</html>
