<?php
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/includes/functions.php';
$pageTitle = 'Certifications & Standards';
$currentPage = 'certifications';
$certs = Database::fetchAll("SELECT * FROM certifications WHERE is_active=1 ORDER BY sort_order, id");
include __DIR__ . '/includes/header.php';
?>

<section class="pt-28 pb-8 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">
        Quality Assured
      </div>
      <h1 class="text-4xl md:text-5xl font-black font-display mb-4">Standards & <span class="text-orange-500">Certifications</span></h1>
      <p class="text-gray-400 max-w-2xl mx-auto">Every product we source is supplied with full documentation — material test reports, third-party inspection certificates, and manufacturer certification confirming compliance with the applicable API, ASME, NACE, and ISO standards.</p>
    </div>

    <!-- Trust Strip -->
    <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-16">
      <?php foreach ([
        ['🏆', 'API Certified', 'Wellhead & pipeline standards'],
        ['🔬', 'Full MTRs', 'Mill traceability on all orders'],
        ['🌍', 'Global Sourcing', 'Certified manufacturers worldwide'],
        ['📋', 'TPI Available', '3rd-party inspection on request'],
      ] as [$ic, $t, $s]): ?>
      <div class="card-dark p-5 text-center">
        <div class="text-3xl mb-2"><?= $ic ?></div>
        <div class="font-semibold text-sm text-white"><?= $t ?></div>
        <div class="text-xs text-gray-400 mt-1"><?= $s ?></div>
      </div>
      <?php endforeach; ?>
    </div>

    <!-- Certifications Grid -->
    <?php if ($certs): ?>
    <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6 mb-16">
      <?php foreach ($certs as $c): ?>
      <div class="card-dark overflow-hidden hover:border-orange-600/50 transition-colors group">
        <!-- Standard badge header -->
        <div class="bg-gradient-to-r from-orange-600 to-orange-500 p-5 flex items-center justify-between">
          <div>
            <div class="text-xs font-semibold text-orange-100 uppercase tracking-widest mb-1"><?= e($c['issuing_body']) ?></div>
            <div class="text-2xl font-black text-white"><?= e($c['standard']) ?></div>
          </div>
          <div class="w-14 h-14 rounded-xl bg-white/20 flex items-center justify-center text-2xl">🏅</div>
        </div>
        <!-- Content -->
        <div class="p-5">
          <h3 class="font-bold text-white mb-2"><?= e($c['name']) ?></h3>
          <p class="text-sm text-gray-400 leading-relaxed mb-4"><?= e($c['description']) ?></p>
          <?php if ($c['cert_number']): ?>
          <div class="text-xs text-orange-400 mb-3">Cert No: <?= e($c['cert_number']) ?></div>
          <?php endif; ?>
          <?php if ($c['validity_date']): ?>
          <div class="text-xs text-gray-500 mb-3">Valid until: <?= date('F Y', strtotime($c['validity_date'])) ?></div>
          <?php endif; ?>
          <div class="flex gap-2">
            <?php if ($c['cert_pdf']): ?>
            <a href="/uploads/<?= e($c['cert_pdf']) ?>" target="_blank" class="btn-primary text-xs py-2 px-4">⬇ Download PDF</a>
            <?php endif; ?>
            <?php if ($c['cert_image']): ?>
            <a href="/uploads/<?= e($c['cert_image']) ?>" target="_blank" class="btn-outline text-xs py-2 px-4">🔍 View Certificate</a>
            <?php endif; ?>
            <?php if (!$c['cert_pdf'] && !$c['cert_image']): ?>
            <span class="text-xs text-gray-500 italic">Certificate available on request</span>
            <?php endif; ?>
          </div>
        </div>
      </div>
      <?php endforeach; ?>
    </div>
    <?php else: ?>
    <!-- Fallback static cards if no DB records yet -->
    <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6 mb-16">
      <?php foreach ([
        ['API 6A', 'American Petroleum Institute', 'Wellhead & Christmas Tree Equipment', 'Gate valves, choke valves, and plug valves for wellhead applications up to 20,000 PSI. Most stringent API valve standard — confirms design qualification, material traceability, and production testing.'],
        ['API 6D', 'American Petroleum Institute', 'Pipeline Valves', 'Ball valves, check valves, gate valves for pipeline petroleum and natural gas service. Covers hydrostatic shell, seat, and closure testing requirements.'],
        ['ASME B16.5', 'ASME', 'Pipe Flanges & Flanged Fittings', 'NPS ½ through NPS 24 flanges and flanged fittings. Covers pressure-temperature ratings, materials, dimensions, tolerances, marking, and testing.'],
        ['ASME B16.20', 'ASME', 'Metallic Gaskets', 'Ring-Joint, Spiral-Wound, and Jacketed gaskets for ASME B16.5 and B16.47 flanges. Covers dimensional and material specifications.'],
        ['NACE MR0175', 'NACE International', 'Sour Service Materials', 'Sulfide stress cracking resistant metallic materials for H₂S-containing oil and gas environments. Required for all sour service and HPHT applications.'],
        ['ISO 9001:2015', 'ISO', 'Quality Management System', 'Internationally recognised quality management standard. Demonstrates our ability to consistently provide products that meet customer and regulatory requirements.'],
      ] as [$std, $body, $name, $desc]): ?>
      <div class="card-dark overflow-hidden hover:border-orange-600/50 transition-colors">
        <div class="bg-gradient-to-r from-orange-600 to-orange-500 p-5 flex items-center justify-between">
          <div>
            <div class="text-xs font-semibold text-orange-100 uppercase tracking-widest mb-1"><?= $body ?></div>
            <div class="text-2xl font-black text-white"><?= $std ?></div>
          </div>
          <div class="w-14 h-14 rounded-xl bg-white/20 flex items-center justify-center text-2xl">🏅</div>
        </div>
        <div class="p-5">
          <h3 class="font-bold text-white mb-2"><?= $name ?></h3>
          <p class="text-sm text-gray-400 leading-relaxed"><?= $desc ?></p>
          <div class="mt-4 text-xs text-gray-500 italic">Certificate available on request</div>
        </div>
      </div>
      <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <!-- Documentation CTA -->
    <div class="card-dark p-8 text-center border-orange-600/30">
      <div class="text-4xl mb-4">📋</div>
      <h2 class="text-2xl font-bold mb-3">Need Full Documentation?</h2>
      <p class="text-gray-400 mb-6 max-w-xl mx-auto">We provide complete documentation packages for every order — Mill Test Reports (MTR), Manufacturer Certificates of Conformance, Third-Party Inspection Reports, Dimensional Inspection Reports, and Heat/Lot Traceability. Available for E&P operator vendor pre-qualification.</p>
      <div class="flex flex-col sm:flex-row gap-4 justify-center">
        <a href="/contact.php" class="btn-primary px-8 py-3">Request Documentation Package</a>
        <a href="/downloads.php" class="btn-outline px-8 py-3">Browse Tech Library</a>
      </div>
    </div>
  </div>
</section>

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