<?php include('../config.php'); ?>
<?php include('../header/header.php'); ?>

<section class="py-5">
  <div class="container py-5">
    <!-- PAGE TITLE -->
    <div class="text-center mb-5">
      <h2 class="section-title">Courses & Categories</h2>
      <p class="text-muted">Choose your preferred course and apply today.</p>
    </div>
    <!-- ============================= -->
    <!-- DYNAMIC DATABASE COURSES -->
    <!-- ============================= -->
    <?php
    $categories = $pdo->query("SELECT * FROM course_categories")->fetchAll();
    foreach ($categories as $cat):
    ?>
    <div class="mb-5">
      <h3 class="text-primary"><?= $cat['name']; ?></h3>
      <p class="text-muted"><?= $cat['description']; ?></p>
      <div class="row g-4">
        <?php
        $stmt = $pdo->prepare("SELECT * FROM courses WHERE category_id = ?");
        $stmt->execute([$cat['id']]);
        $courses = $stmt->fetchAll();
        foreach ($courses as $course):
        ?>
        <div class="col-md-4">
          <div class="card h-100 shadow-sm border-0">
            <div class="card-body">
              <h5 class="fw-bold"><?= $course['title']; ?></h5>

              <p class="text-muted small">
                <?= substr($course['description'], 0, 100); ?>...
              </p>

              <p><strong>Duration:</strong> <?= $course['duration']; ?></p>
              <p><strong>Fee:</strong> KES <?= number_format($course['price']); ?></p>

              <a href="login.php?course_id=<?= $course['id']; ?>" 
                 class="btn btn-primary btn-sm w-100">
                Apply Now
              </a>
            </div>
          </div>
        </div>
        <?php endforeach; ?>
      </div>
    </div>
    <?php endforeach; ?>
  </div>
</section>
<!-- ============================= -->
<!-- STATIC COURSE SECTION (YOUR DESIGN FIXED) -->
<!-- ============================= -->
<div class="section padding_layout_1 light_silver service_list">
  <div class="container">
    <div class="row">
      <div class="col-md-4 service_blog">
        <div class="service_cont">
          <h3 class="service_head">Backend Development</h3>
          <ul>
            <li>➤ Node.js</li>
            <li>➤ Python (Django, Flask)</li>
            <li>➤ Ruby on Rails</li>
            <li>➤ Java Spring Boot</li>
          </ul>
          <a class="btn btn-primary btn-sm" href="login.php?course=backend">Apply Now</a>
        </div>
      </div>

      <div class="col-md-4 service_blog">
        <div class="service_cont">
          <h3 class="service_head">Graphic Design</h3>
          <ul>
            <li>➤ Photoshop</li>
            <li>➤ CorelDraw</li>
            <li>➤ Illustrator</li>
            <li>➤ InDesign</li>
          </ul>
          <a class="btn btn-primary btn-sm" href="login.php?course=graphics">Apply Now</a>
        </div>
      </div>

      <div class="col-md-4 service_blog">
        <div class="service_cont">
          <h3 class="service_head">Web Development</h3>
          <ul>
            <li>➤ HTML & CSS</li>
            <li>➤ JavaScript</li>
            <li>➤ PHP</li>
          </ul>
          <a class="btn btn-primary btn-sm" href="login.php?course=web">Apply Now</a>
        </div>
      </div>

    </div>
  </div>
</div>
<!-- SECOND STATIC SECTION -->
<div class="section padding_layout_1 light_silver service_list">
  <div class="container">
    <div class="row">

      <div class="col-md-4 service_blog">
        <div class="service_cont">
          <h3 class="service_head">Databases</h3>
          <ul>
            <li>➤ MySQL</li>
            <li>➤ PostgreSQL</li>
            <li>➤ SQL Server</li>
          </ul>
          <a class="btn btn-primary btn-sm" href="login.php?course=databases">Apply Now</a>
        </div>
      </div>
      <div class="col-md-4 service_blog">
        <div class="service_cont">
          <h3 class="service_head">Computer Packages</h3>
          <ul>
            <li>➤ MS Word</li>
            <li>➤ MS Excel</li>
            <li>➤ PowerPoint</li>
            <li>➤ QuickBooks</li>
          </ul>
          <a class="btn btn-primary btn-sm" href="login.php?course=packages">Apply Now</a>
        </div>
      </div>
      <div class="col-md-4 service_blog">
        <div class="service_cont">
          <h3 class="service_head">IT Support</h3>
          <ul>
            <li>➤ Networking</li>
            <li>➤ Computer Repair</li>
            <li>➤ ICT Support</li>
          </ul>
          <a class="btn btn-primary btn-sm" href="login.php?course=it">Apply Now</a>
        </div>
      </div>
    </div>
  </div>
</div>
<?php include('../footer/footer.php'); ?>