// Create toast container if it doesn't exist function ensureToastContainer() { let container = document.querySelector('.toast-container'); if (!container) { container = document.createElement('div'); container.className = 'toast-container'; document.body.appendChild(container); } return container; } // Show a toast notification function showToast(message, type = 'success') { const container = ensureToastContainer(); // Create toast element const toast = document.createElement('div'); toast.className = `toast ${type}`; // Add icon based on type const icon = document.createElement('i'); icon.className = type === 'success' ? 'fas fa-check-circle' : 'fas fa-exclamation-circle'; toast.appendChild(icon); // Add message const messageText = document.createElement('span'); messageText.textContent = message; toast.appendChild(messageText); // Add to container container.appendChild(toast); // Trigger animation setTimeout(() => { toast.classList.add('show'); }, 10); // Remove after 3 seconds setTimeout(() => { toast.classList.remove('show'); setTimeout(() => { container.removeChild(toast); }, 300); }, 3000); }