<?php
declare(strict_types=1);
if (!isset($pdo)) {
    require_once __DIR__ . '/includes/functions.php';
    require_once __DIR__ . '/includes/middleware.php';
    $pdo = require __DIR__ . '/config/database.php';
}

// Showcase: pull from packages with computed totals
$rows = $pdo->query("
  SELECT p.id, p.name, p.discount_type, p.discount_value,
         COALESCE(SUM((s.cac_fee+s.service_fee)*pi.quantity),0) AS base
  FROM packages p
  LEFT JOIN package_items pi ON pi.package_id=p.id
  LEFT JOIN services s ON s.id=pi.service_id
  WHERE p.status='active'
  GROUP BY p.id
  ORDER BY p.created_at DESC
")->fetchAll();
$showcase = [];
foreach ($rows as $r) {
  $base = (float)($r['base'] ?? 0);
  $discount = 0.0;
  if (($r['discount_type'] ?? 'none') === 'percent') $discount = $base * ((float)$r['discount_value']/100);
  elseif (($r['discount_type'] ?? 'none') === 'fixed') $discount = (float)$r['discount_value'];
  $showcase[] = ['id'=>$r['id'],'name'=>$r['name'],'total'=>max(0,$base - $discount)];
}

$meta = [
  'title' => 'Affordable CAC Registration Pricing | No Hidden Fees | Go Legal',
  'description' => 'Transparent, all-inclusive pricing for CAC business name registration, company incorporation, and NGO setup in Nigeria. No hidden charges, just expert results.',
  'canonical' => url('pricing.php')
];
include __DIR__ . '/includes/header.php';
$cu = current_user();
?>

<section class="section" style="padding-top:48px; padding-bottom: 48px;">
  <div style="text-align:center;margin-bottom:48px;max-width:700px;margin-left:auto;margin-right:auto;">
    <h1 style="font-size:42px; margin:0 0 16px; letter-spacing:-0.02em;">One Flat Fee. <span class="gradient-text">Zero Surprises.</span></h1>
    <p class="lead">We don't do hidden charges or "agent fees." Our pricing is 100% transparent and covers everything: CAC statutory fees, professional handling, name reservation, and your digital certificate delivery.</p>
  </div>
  <div class="grid grid-3">
    <?php foreach ($showcase as $svc): 
      $isReco = stripos((string)$svc['name'],'Hustle Starter')!==false;
    ?>
      <div class="card reveal" style="display:flex;flex-direction:column;justify-content:space-between">
        <div>
          <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:24px">
            <strong style="font-size:18px"><?=e($svc['name'])?></strong>
            <?php if ($isReco): ?><span class="badge-reco" style="padding:4px 12px;font-weight:700"><?=ui_icon('approved',14)?> Recommended</span><?php endif; ?>
          </div>
          <div style="margin-bottom:32px">
            <div class="muted" style="font-size:13px;font-weight:600;text-transform:uppercase;margin-bottom:4px">All‑inclusive price</div>
            <div style="font-size:36px;font-weight:800;color:var(--text)">₦<?=e(money((float)$svc['total']))?></div>
          </div>
          <ul class="list-clean" style="margin-bottom:32px;line-height:2">
            <li><?=ui_icon('check',16)?> CAC Filing Fees Included</li>
            <li><?=ui_icon('check',16)?> Professional Handling</li>
            <li><?=ui_icon('check',16)?> Document Preparation</li>
            <li><?=ui_icon('check',16)?> Digital Certificate Delivery</li>
            <li><?=ui_icon('check',16)?> Dedicated Expert Support</li>
          </ul>
        </div>
        <a class="btn primary" style="width:100%;justify-content:center" href="<?=cta_url('customer/new_application.php')?>">Get started</a>
      </div>
    <?php endforeach; ?>
  </div>
  <div class="card reveal" style="margin-top: 48px; background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);">
    <div style="text-align:center;">
        <h3 style="margin-top:0">Looking for something specific?</h3>
        <p class="muted">We also offer single a-la-carte services like TIN registration, Annual Returns, and Status Reports.</p>
        <a class="btn secondary" href="<?=url('services.php')?>" style="margin-top: 12px;">Browse all services</a>
    </div>
  </div>
</section>

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