<!DOCTYPE html>
<?php include 'auth.php'; ?>
<?php include 'includes/header.php'; ?>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>USA Contact Submissions</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    /*body {*/
    /*  font-family: 'Segoe UI', sans-serif;*/
    /*  background-color: #f4f6f9;*/
    /*  margin: 0;*/
    /*}*/

    .sidebar {
      height: 100vh;
      width: 250px;
      position: fixed;
      top: 0;
      left: 0;
           background-color: #7d0d0d;
           color: white;
      padding-top: 60px;
      z-index: 1000;
    }

    .sidebar h4 {
      text-align: center;
      margin-bottom: 30px;
      font-weight: bold;
    }

    .sidebar a {
      display: block;
      padding: 12px 20px;
      color: white;
      text-decoration: none;
      transition: 0.3s;
    }

    .sidebar a:hover {
      background-color: #1a2d49;
    }

    .main-content {
      margin-left: 250px;
      padding: 40px;
    }

    .header {
      background-color: white;
      padding: 20px;
      border-bottom: 1px solid #ddd;
    }

    .card {
      background-color: white;
      border-radius: 8px;
      box-shadow: 0 0 15px rgba(0,0,0,0.05);
      padding: 30px;
      overflow-x: auto;
    }

    table {
      width: 100%;
      min-width: 800px;
    }

    .btn-delete {
      color: white;
      background-color: #dc3545;
      border: none;
      padding: 5px 10px;
      border-radius: 4px;
    }

    @media (max-width: 768px) {
      .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        padding: 20px 0;
      }

      .main-content {
        margin-left: 0;
        padding: 20px;
      }

      .header {
        margin-top: 0;
      }
    }
  </style>
</head>
<body>

<!--<div class="sidebar">-->
<!--  <h4>Admin Panel</h4>-->
<!--  <a href="dashboard.php">Dashboard</a>-->
<!--    <a href="main_website_conatcts.php">Main Website's Contacts</a>-->
<!--  <a href="usa_contacts.php">USA Contact Data</a>-->
<!--  <a href="uae_contacts.php">UAE Contact Data</a>-->
<!--  <a href="ghana_contacts.php">Ghana Contact Data</a>-->
<!--    <a href="Bahrain.php">Bahrain Contact Data</a>-->
<!--  <a href="logout.php">Logout</a>-->
<!--</div>-->

<div class="main-content">
  <div class="header">
    <h2>Ghana Contact Submissions</h2>
  </div>

  <div class="card mt-4">
    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    include 'config.php';

    // Delete logic
    if (isset($_GET['delete_id'])) {
      $deleteId = intval($_GET['delete_id']);
      $stmtDel = $conn->prepare("DELETE FROM ghana_contact_submissions WHERE id = ?");
      $stmtDel->execute([$deleteId]);
    //   echo "<p class='text-success'>✅ Record with ID $deleteId deleted successfully.</p>";
    }

    try {
      $stmt = $conn->query("SELECT * FROM ghana_contact_submissions ORDER BY id DESC");
      $data = $stmt->fetchAll(PDO::FETCH_ASSOC);

      if (count($data) > 0) {
        echo "<table class='table table-striped'>
                <thead class='table-dark'>
                  <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>Service</th>
                    <th>Message</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>";
        foreach ($data as $row) {
          echo "<tr>
                  <td>{$row['id']}</td>
                  <td>{$row['name']}</td>
                  <td>{$row['email']}</td>
                  <td>{$row['phone']}</td>
                  <td>{$row['service']}</td>
                  <td>{$row['message']}</td>
                  <td>
                    <a href='?delete_id={$row['id']}' class='btn-delete' onclick=\"return confirm('Are you sure you want to delete this record?');\">Delete</a>
                  </td>
                </tr>";
        }
        echo "</tbody></table>";
      } else {
        echo "<p>No submissions found.</p>";
      }
    } catch (PDOException $e) {
      echo "<p style='color:red;'>❌ Database Error: " . $e->getMessage() . "</p>";
    }
    ?>
  </div>
</div>

</body>
</html>
<?php include 'includes/footer.php'; ?>
