<?php
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/includes/functions.php';
$pageTitle = 'Projects & Case Studies';
$currentPage = 'projects';
$projects = Database::fetchAll("SELECT * FROM projects WHERE is_active=1 ORDER BY is_featured DESC, sort_order, id DESC");
include __DIR__ . '/includes/header.php';
?>

<section class="pt-28 pb-16 bg-navy-900">
  <div class="max-w-7xl mx-auto px-4">
    <div class="text-center mb-12">
      <div class="inline-flex items-center gap-2 bg-orange-600/10 border border-orange-600/30 rounded-full px-4 py-1.5 text-xs font-medium text-orange-400 uppercase tracking-wider mb-4">
        Proven Track Record
      </div>
      <h1 class="text-4xl md:text-5xl font-black font-display mb-4">Projects & <span class="text-orange-500">Case Studies</span></h1>
      <p class="text-gray-400 max-w-2xl mx-auto">From wellhead valve packages for major E&P operators to complete workshop overhauls for mining fleets — here's a snapshot of the industrial challenges we've solved.</p>
    </div>

    <?php if ($projects): ?>
    <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6 mb-16">
      <?php foreach ($projects as $p): ?>
      <div class="card-dark overflow-hidden hover:border-orange-600/50 transition-all hover:-translate-y-0.5 group">
        <?php if ($p['image']): ?>
        <div class="relative h-48 overflow-hidden bg-navy-700">
          <img src="/uploads/<?= e($p['image']) ?>" alt="<?= e($p['title']) ?>"
            class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"
            onerror="this.onerror=null;this.style.display='none';this.nextElementSibling.style.display='flex'">
          <div class="hidden absolute inset-0 items-center justify-center text-4xl text-gray-600">🏗️</div>
          <?php if ($p['is_featured']): ?>
          <div class="absolute top-3 right-3 bg-orange-600 text-white text-xs font-bold px-2 py-1 rounded-full">Featured</div>
          <?php endif; ?>
        </div>
        <?php endif; ?>
        <div class="p-5">
          <?php if ($p['industry']): ?>
          <div class="inline-flex items-center gap-1 bg-orange-600/10 text-orange-400 text-xs font-medium px-2.5 py-1 rounded-full mb-3"><?= e($p['industry']) ?></div>
          <?php endif; ?>
          <h3 class="font-bold text-white mb-2 leading-snug"><?= e($p['title']) ?></h3>
          <?php if ($p['client_name']): ?>
          <div class="text-sm text-gray-400 mb-2 flex items-center gap-2">
            <?php if ($p['client_logo']): ?>
            <img src="/uploads/<?= e($p['client_logo']) ?>" alt="<?= e($p['client_name']) ?>" class="h-5 object-contain">
            <?php endif; ?>
            <span>Client: <strong class="text-gray-300"><?= e($p['client_name']) ?></strong></span>
          </div>
          <?php endif; ?>
          <?php if ($p['scope']): ?>
          <div class="text-xs text-orange-400 mb-3">Scope: <?= e($p['scope']) ?></div>
          <?php endif; ?>
          <?php if ($p['description']): ?>
          <p class="text-sm text-gray-400 leading-relaxed line-clamp-3"><?= e($p['description']) ?></p>
          <?php endif; ?>
          <?php if ($p['completion_date']): ?>
          <div class="mt-3 text-xs text-gray-500">Completed: <?= date('F Y', strtotime($p['completion_date'])) ?></div>
          <?php endif; ?>
          <?php if ($p['slug'] && $p['body']): ?>
          <a href="/project.php?slug=<?= e($p['slug']) ?>" class="mt-4 inline-flex items-center gap-1 text-sm text-orange-500 hover:text-orange-400 font-medium">
            Read full case study →
          </a>
          <?php endif; ?>
        </div>
      </div>
      <?php endforeach; ?>
    </div>
    <?php else: ?>
    <div class="card-dark p-16 text-center">
      <div class="text-6xl mb-6 opacity-20">🏗️</div>
      <h2 class="text-2xl font-bold mb-2">Our Project Portfolio is Being Updated</h2>
      <p class="text-gray-400 max-w-lg mx-auto">We are currently documenting our most recent precision engineering and sourcing projects. Please check back soon or contact us to see our full credentials.</p>
    </div>
    <?php endif; ?>

    <!-- CTA -->
    <div class="card-dark p-8 text-center border-orange-600/30">
      <h2 class="text-2xl font-bold mb-3">Have a Project in Mind?</h2>
      <p class="text-gray-400 mb-6 max-w-xl mx-auto">Whether it's a complete valve package for wellhead construction, a shutdown supply of gaskets and fittings, or a full workshop overhaul — our team is ready to assess and quote.</p>
      <a href="/contact.php" class="btn-primary px-8 py-3">Discuss Your Project</a>
    </div>
  </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>
