<?php
header('Content-Type: text/html; charset=utf-8');
session_start();
include 'db.php';

// Fetch companies
$companies = $pdo->query("SELECT id, name FROM companies ORDER BY name ASC LIMIT 20")->fetchAll();

// Fetch blog posts (optional)
$blogPosts = $pdo->query("SELECT id, title FROM blogs ORDER BY created_at DESC LIMIT 10")->fetchAll();

// Fetch recent reviews (without title column)
$reviews = $pdo->query("
  SELECT r.id, r.company_id, c.name AS company_name, r.rating
  FROM reviews r
  JOIN companies c ON r.company_id = c.id
  ORDER BY r.created_at DESC
  LIMIT 10
")->fetchAll();

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Sitemap - Review Stream</title>
  <link rel="stylesheet" href="style.css">
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">

  <style>
    body {
      background-color: #f9f9f9;
      font-family: 'Inter', sans-serif;
      margin: 0;
      padding: 0;
      color: #333;
    }

    .hero {
      background: linear-gradient(90deg, #007BFF, #00b67a);
      color: white;
      text-align: center;
      padding: 40px 20px;
      border-radius: 12px;
      margin-bottom: 40px;
      box-shadow: 0 6px 14px rgba(0,0,0,0.1);
	  margin-top: 30px !important;
    }

    .hero h1 {
      margin: 0;
      font-size: 34px;
      font-weight: 700;
    }

    .sitemap-container {
      max-width: 1100px;
      margin: 0 auto;
      padding: 30px 20px;
      background: #fff;
      border-radius: 10px;
      box-shadow: 0 4px 10px rgba(0,0,0,0.06);
    }

    .sitemap-section {
      margin-bottom: 40px;
    }

    .sitemap-section h2 {
      font-size: 20px;
      font-weight: 600;
      border-bottom: 2px solid #e0e0e0;
      padding-bottom: 6px;
      margin-bottom: 15px;
      color: #007BFF;
    }

    .sitemap-section ul {
      list-style: none;
      padding-left: 0;
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
      gap: 12px;
    }

    .sitemap-section ul li {
      font-size: 15px;
    }

    .sitemap-section ul li a {
      color: #333;
      text-decoration: none;
      transition: color 0.2s ease;
    }

    .sitemap-section ul li a:hover {
      color: #007BFF;
    }

    @media (max-width: 600px) {
      .sitemap-section ul {
        grid-template-columns: 1fr;
      }
    }
	
	.topbar {
  background-color: #007BFF; /* Blue */
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 15px;
  position: relative;
}

.logo {
  display: flex;
  align-items: center;
  font-weight: bold;
  font-size: 18px;
}

.logo-icon {
  background: linear-gradient(135deg, #a2d4f5, #fefb72);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}

.menu-toggle {
  font-size: 1.5em;
  color: #fff;
  cursor: pointer;
  display: none;
}

.menu {
  display: flex;
  gap: 15px;
}

.menu a, .menu button {
  color: #fff;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

/* Mobile styles */
@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }

  .menu {
    flex-direction: column;
    background-color: #007BFF;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    display: none;
    padding: 10px 0;
    z-index: 1000;
  }

  .menu.active {
    display: flex;
  }

  .menu a, .menu button {
    padding: 10px 15px;
  }
}

#suggestions{
  position: absolute;
  background: #fff;
  border: 1px solid #ccc;
  max-height: 180px;
  overflow-y: auto;
  width: 250px;
  display: none;
  z-index: 9999;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  color: #333;
  line-height: 10px !important;
  text-align:left !important;
}
  </style>
</head>
<body>

<div class="topbar">
  <div class="logo">
    <div class="logo-icon">
      <i class="fas fa-shield-alt" style="color:#4A90E2; font-size: 25px; box-shadow: 0 1px 3px rgba(0,0,0,0.2); margin-left: 8px"></i>
    </div>
    REVIEW STREAM
  </div>

  <div class="menu-toggle" onclick="toggleMenu()">
    <i class="fas fa-bars"></i>
  </div>

  <div class="menu" id="topMenu">
    <a href="index.php">Home</a>
    <a href="companies.php">Companies</a>
	<a href="blog.php">Newsroom</a>
    <?php if(isset($_SESSION['user_id'])): ?>
      <a href="logout.php">Logout</a>
    <?php else: ?>
      <a href="login.php">Login</a>
    <?php endif; ?>
    <button class="dark-mode-toggle" onclick="document.body.classList.toggle('dark-mode')">🌓</button>
  </div>
</div>

<div class="hero">
  <h1>Website Sitemap</h1>
</div>

<div class="sitemap-container">

  <div class="sitemap-section">
    <h2>Main Pages</h2>
    <ul>
      <li><a href="index.php">Home</a></li>
      <li><a href="companies.php">All Companies</a></li>
      <li><a href="blog.php">Newsroom</a></li>
      <li><a href="sitemap.php">Sitemap</a></li>
    </ul>
  </div>

  <div class="sitemap-section">
    <h2>Support Pages</h2>
    <ul>
      <li><a href="aboutus.php">About Us</a></li>
      <li><a href="contact.php">Contact</a></li>
      <li><a href="privacy_policy.php">Privacy Policy</a></li>
      <li><a href="terms.php">Terms of Use</a></li>
    </ul>
  </div>

  <div class="sitemap-section">
    <h2>User Area</h2>
    <ul>
      <?php if (isset($_SESSION['user_id'])): ?>
        <li><a href="dashboard.php">My Dashboard</a></li>
        <li><a href="logout.php">Logout</a></li>
      <?php else: ?>
        <li><a href="login.php">Login</a></li>
        <li><a href="register.php">Register</a></li>
      <?php endif; ?>
    </ul>
  </div>

  <div class="sitemap-section">
    <h2>Popular Companies</h2>
    <ul>
      <?php foreach ($companies as $c): ?>
        <li><a href="company_details.php?id=<?= $c['id'] ?>"><?= htmlspecialchars($c['name']) ?></a></li>
      <?php endforeach; ?>
    </ul>
  </div>

  <?php if (!empty($blogPosts)): ?>
    <div class="sitemap-section">
      <h2>Recent Blog Posts</h2>
      <ul>
        <?php foreach ($blogPosts as $post): ?>
          <li><a href="blog_detail.php?id=<?= $post['id'] ?>"><?= htmlspecialchars($post['title']) ?></a></li>
        <?php endforeach; ?>
      </ul>
    </div>
  <?php endif; ?>

  <?php if (!empty($reviews)): ?>
    <div class="sitemap-section">
      <h2>Recent Company Reviews</h2>
      <ul>
        <?php foreach ($reviews as $review): ?>
          <li>
            <a href="review.php?id=<?= $review['company_id'] ?>">
             <?= htmlspecialchars($review['company_name']) ?> — Rated <?= htmlspecialchars($review['rating']) ?>/5

            </a>
          </li>
        <?php endforeach; ?>
      </ul>
    </div>
  <?php endif; ?>

</div>

<?php include 'footer.php'; ?>

</body>
</html>
