<?php
// admin_dashboard.php
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Admin Dashboard - Send Newsletter</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f6f8;
      color: #333;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }
    .container {
      background: #fff;
      border: 2px solid #b90000ff;
      border-radius: 12px;
      padding: 40px 60px;
      text-align: center;
      box-shadow: 0 0 15px rgba(0,0,0,0.1);
    }
    h1 {
      color: #b90000ff;
      margin-bottom: 20px;
    }
    button {
      background-color: #b90000ff;
      color: white;
      border: none;
      padding: 12px 30px;
      font-size: 16px;
      border-radius: 6px;
      cursor: pointer;
      transition: 0.3s;
    }
    button:hover {
      background-color: black;
    }
    #message {
      margin-top: 20px;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>📨 Send Newsletter</h1>
    <p>Click below to send the newsletter to all subscribers.</p>
    <button id="sendNewsletterBtn">Send Newsletter</button>
    <p id="message"></p>
  </div>

  <script>
    document.getElementById('sendNewsletterBtn').addEventListener('click', () => {
      const messageBox = document.getElementById('message');
      messageBox.textContent = "Sending...";
      messageBox.style.color = "orange";

      fetch("send_newsletter_backend.php")
        .then(res => res.text())
        .then(data => {
          messageBox.textContent = data.includes("sent") ? "✅ Newsletter sent successfully!" : data;
          messageBox.style.color = data.includes("sent") ? "green" : "red";
        })
        .catch(() => {
          messageBox.textContent = "Error sending newsletter.";
          messageBox.style.color = "red";
        });
    });
  </script>
</body>
</html>
