<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/middleware.php';
require_once __DIR__ . '/config/database.php';

// Route top-level custom pages
$uriPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// Subdirectory support: strip the base path from the URI
$basePath = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
if ($basePath !== '' && strpos($uriPath, $basePath) === 0) {
    $uriPath = substr($uriPath, strlen($basePath));
}
if ($uriPath === '') $uriPath = '/';

if ($uriPath === '/pricing' || $uriPath === '/pricing.php') {
    require __DIR__ . '/pricing.php';
    exit;
} elseif ($uriPath === '/services' || $uriPath === '/services.php') {
    require __DIR__ . '/services.php';
    exit;
} elseif (preg_match('#^/l/([^/]+)$#', $uriPath, $matches)) {
    $_GET['slug'] = $matches[1];
    require __DIR__ . '/landing.php';
    exit;
}

// Route blog requests
if ($uriPath === '/blog' || $uriPath === '/blog/') {
    require __DIR__ . '/blog.php';
    exit;
} elseif (preg_match('#^/blog/category/([^/]+)$#', $uriPath, $matches)) {
    $_GET['category'] = $matches[1];
    require __DIR__ . '/blog_category.php';
    exit;
} elseif (preg_match('#^/blog/tag/([^/]+)$#', $uriPath, $matches)) {
    $_GET['tag'] = $matches[1];
    require __DIR__ . '/blog_tag.php';
    exit;
} elseif (preg_match('#^/blog/search/?$#', $uriPath)) {
    require __DIR__ . '/blog_search.php'; // Optional if exists
    exit;
} elseif (preg_match('#^/blog/([^/]+)$#', $uriPath, $matches)) {
    $_GET['slug'] = $matches[1];
    require __DIR__ . '/blog_post.php';
    exit;
}

$now = date('c');
$topServices = $pdo->query("SELECT id, service_name, cac_fee, service_fee, (cac_fee+service_fee) AS total FROM services WHERE status='active' AND service_name NOT LIKE 'Package:%' AND service_name NOT LIKE 'Plan:%' ORDER BY created_at DESC LIMIT 6")->fetchAll();
// 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
  LIMIT 3
")->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)];
}
// SEO meta
$meta = [
  'title' => 'CAC Business Registration in Nigeria | Fast, Affordable & Stress-Free | Go Legal',
  'description' => 'Register your business in Nigeria the right way. Go Legal handles CAC registration, company incorporation, NGO setup, SCUML, TIN & annual returns. Flat fees, no hidden charges. Start today.',
  'canonical' => '/'
];
include __DIR__ . '/includes/header.php';

// Get site logo for display
$stmt = $pdo->prepare("SELECT value FROM settings WHERE key = 'site_logo'");
$stmt->execute();
$siteLogo = $stmt->fetchColumn();
?>

<?php $cu = current_user(); ?>
<section class="hero section subtle-bg" id="home" style="border: none; background: transparent; padding: 80px 0;">
  <div class="grid grid-2" style="align-items: center; gap: 48px;">
    <div class="reveal">
      <div class="badge" style="margin-bottom: 20px; background: var(--primary-tint); color: var(--primary); border: none; padding: 6px 16px;">
        <span class="icon" aria-hidden="true" style="margin-right: 8px;"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><circle cx="12" cy="12" r="10" stroke-width="2"/><path d="M12 7v6l4 2" stroke-width="2" stroke-linecap="round"/></svg></span>
        Trusted by 200+ Nigerian Founders
      </div>
      <h1 style="font-size: 56px; line-height: 1.05; margin: 0 0 24px; font-weight: 800; letter-spacing: -0.04em; color: var(--text);">
        Register your business <span class="gradient-text">the right way.</span>
      </h1>
      <p class="lead" style="margin: 0 0 32px; font-size: 20px; max-width: 540px; color: var(--muted);">
        Skip the CAC headaches. We handle everything from name reservation to final certificates, so you can focus on building your brand.
      </p>

        <div class="hero-actions" style="margin-bottom: 40px;">
          <a class="btn primary" href="<?=cta_url('customer/new_application.php')?>" style="padding: 16px 32px; font-size: 16px;">Start Registration</a>
          <a class="btn ghost" href="<?=url('pricing.php')?>" style="padding: 16px 32px; font-size: 16px;">View Pricing</a>
        </div>

      <div class="pills" style="gap: 16px;">
        <div class="pill" style="border: none; background: var(--hairline); padding: 10px 18px; font-weight: 500;">
          <span class="icon" style="color: var(--primary);"><svg viewBox="0 0 24 24" fill="none"><path d="M6 12l4 4 8-8" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span> 
          No Hidden Fees
        </div>
        <div class="pill" style="border: none; background: var(--hairline); padding: 10px 18px; font-weight: 500;">
          <span class="icon" style="color: var(--indigo);"><svg viewBox="0 0 24 24" fill="none"><path d="M12 5v6l4 2" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg></span> 
          Done in Days
        </div>
      </div>
    </div>
    <div class="reveal">
      <div style="position: relative;">
        <div style="position: absolute; top: -10%; left: -10%; width: 120%; height: 120%; background: radial-gradient(circle, var(--primary-tint) 0%, transparent 70%); z-index: -1;"></div>
        <div class="card glass" style="padding: 0; border-radius: 32px; overflow: hidden; border: 1px solid rgba(255,255,255,0.4); box-shadow: var(--shadow-lg);">
          <img src="<?=url('assets/hero-compliance.svg')?>" alt="Compliance Illustration" style="width: 100%; display: block; filter: drop-shadow(0 20px 40px rgba(0,0,0,0.1));">
        </div>
      </div>
    </div>
  </div>
</section>

<section class="section" id="about-cac" style="padding: 80px 0; background: var(--hairline); border-radius: 40px; margin: 40px 0;">
  <div class="container">
    <div class="grid grid-2" style="align-items: center; gap: 64px;">
      <div class="reveal">
        <h2 style="font-size: 36px; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 24px;">Built for the <span class="gradient-text">Nigerian Entrepreneur.</span></h2>
        <p class="lead" style="font-size: 18px; margin-bottom: 32px;">We're not just a registration service. We're your partner in building a compliant, credible brand. Whether you're a solopreneur or a growing team, we ensure your legal foundation is rock solid.</p>
        
        <div style="display: flex; flex-direction: column; gap: 16px;">
          <div style="display: flex; align-items: flex-start; gap: 16px;">
            <div style="width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 4px;">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" style="width: 14px; height: 14px;"><path d="M20 6L9 17l-5-5"/></svg>
            </div>
            <div>
              <h4 style="margin: 0 0 4px; font-weight: 700;">Zero Rejection Goal</h4>
              <p class="muted" style="margin: 0; font-size: 14px;">Our expert audit catch errors before they reach the CAC.</p>
            </div>
          </div>
          <div style="display: flex; align-items: flex-start; gap: 16px;">
            <div style="width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 4px;">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" style="width: 14px; height: 14px;"><path d="M20 6L9 17l-5-5"/></svg>
            </div>
            <div>
              <h4 style="margin: 0 0 4px; font-weight: 700;">Live Tracking</h4>
              <p class="muted" style="margin: 0; font-size: 14px;">Watch your application progress in real-time from your dashboard.</p>
            </div>
          </div>
        </div>
      </div>
      <div class="reveal">
        <div class="card" style="padding: 40px; background: white; box-shadow: var(--shadow);">
          <h3 style="margin: 0 0 20px; font-size: 22px;">What we handle</h3>
          <ul class="list-clean" style="display: grid; gap: 12px;">
            <li style="display: flex; align-items: center; gap: 12px; font-weight: 500;">
              <span style="color: var(--primary);"><?=ui_icon('check', 18)?></span> CAC Business Registration
            </li>
            <li style="display: flex; align-items: center; gap: 12px; font-weight: 500;">
              <span style="color: var(--primary);"><?=ui_icon('check', 18)?></span> TIN & Tax Documentation
            </li>
            <li style="display: flex; align-items: center; gap: 12px; font-weight: 500;">
              <span style="color: var(--primary);"><?=ui_icon('check', 18)?></span> NGO & Company Setup
            </li>
            <li style="display: flex; align-items: center; gap: 12px; font-weight: 500;">
              <span style="color: var(--primary);"><?=ui_icon('check', 18)?></span> Annual Returns Filing
            </li>
          </ul>
          <hr style="margin: 32px 0; border: none; border-top: 1px solid var(--border);">
          <p class="muted" style="font-size: 14px; margin-bottom: 24px;">Ready to make it official? Start your journey today.</p>
          <a class="btn primary" href="<?=cta_url('register.php')?>" style="width: 100%;">Get Started Free</a>
        </div>
      </div>
    </div>
  </div>
</section>


<section class="section" style="padding: 80px 0;" id="how">
  <div style="text-align: center; max-width: 700px; margin: 0 auto 60px;">
    <h2 style="font-size: 40px; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 16px;">Registration made <span class="gradient-text">simple.</span></h2>
    <p class="lead" style="font-size: 18px;">Three steps to a fully registered business in Nigeria. No office visits, no paperwork, no stress.</p>
  </div>
  <div class="grid grid-3" style="gap: 32px;">
    <div class="card reveal" style="background: white; border: 1px solid var(--border); box-shadow: var(--shadow-sm); padding: 40px;">
      <div style="width: 48px; height: 48px; border-radius: 12px; background: var(--primary-tint); color: var(--primary); display: flex; align-items: center; justify-content: center; margin-bottom: 24px; font-weight: 800; font-size: 20px;">1</div>
      <h3 style="margin: 0 0 12px; font-size: 20px; font-weight: 700;">Select Service</h3>
      <p class="muted" style="margin: 0; line-height: 1.6;">Choose the registration type that fits your needs — from Business Names to Limited Companies.</p>
    </div>
    <div class="card reveal" style="background: white; border: 1px solid var(--border); box-shadow: var(--shadow-sm); padding: 40px;">
      <div style="width: 48px; height: 48px; border-radius: 12px; background: var(--indigo); color: white; display: flex; align-items: center; justify-content: center; margin-bottom: 24px; font-weight: 800; font-size: 20px;">2</div>
      <h3 style="margin: 0 0 12px; font-size: 20px; font-weight: 700;">Submit Details</h3>
      <p class="muted" style="margin: 0; line-height: 1.6;">Fill in our guided form and upload your IDs. We'll audit everything to ensure a perfect filing.</p>
    </div>
    <div class="card reveal" style="background: white; border: 1px solid var(--border); box-shadow: var(--shadow-sm); padding: 40px;">
      <div style="width: 48px; height: 48px; border-radius: 12px; background: var(--teal); color: white; display: flex; align-items: center; justify-content: center; margin-bottom: 24px; font-weight: 800; font-size: 20px;">3</div>
      <h3 style="margin: 0 0 12px; font-size: 20px; font-weight: 700;">Get Approved</h3>
      <p class="muted" style="margin: 0; line-height: 1.6;">We handle the CAC filing and deliver your digital certificate directly to your portal.</p>
    </div>
  </div>
</section>
  <div style="text-align:center;margin-top:24px">
      <a class="btn primary" href="<?=cta_url('customer/new_application.php')?>">Start My Registration Now</a>
  </div>
</section>



 

<section class="section" id="testimonials" style="padding: 100px 0;">
  <div style="text-align: center; max-width: 700px; margin: 0 auto 60px;">
    <h2 style="font-size: 40px; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 16px;">Trusted by <span class="gradient-text">founders.</span></h2>
    <p class="lead" style="font-size: 18px;">See what Nigerian business owners are saying about their experience with Go Legal.</p>
  </div>
  <?php
    $allTestimonials = [
      ['text'=>'Business name and TIN done in days. Opened a corporate account the same week. No hidden fees.', 'init'=>'AK', 'name'=>'Amaka Kalu', 'role'=>'Lagos'],
      ['text'=>'SCUML arrived earlier than planned. Clear checklist, zero chasing. Predictable execution.', 'init'=>'IS', 'name'=>'Ibrahim Sule', 'role'=>'Abuja'],
      ['text'=>'NGO registration was straightforward. They caught a tiny error before filing. Highly professional.', 'init'=>'CO', 'name'=>'Chidinma Okeke', 'role'=>'PH'],
      ['text'=>'Company incorporation and TIN were correct on first try. Used the docs immediately.', 'init'=>'TA', 'name'=>'Tunde Adeyemi', 'role'=>'Ibadan'],
      ['text'=>'Annual returns filed on time. Receipts and reports were tidy in the portal. Excellent service.', 'init'=>'AB', 'name'=>'Aisha Bello', 'role'=>'Kano'],
      ['text'=>'Status report and certified copies delivered in 48 hours. Protected our privacy.', 'init'=>'EN', 'name'=>'Emeka Nwosu', 'role'=>'Enugu'],
      ['text'=>'Upgraded to a limited company smoothly. Supplier accounts opened fast. Great support.', 'init'=>'FA', 'name'=>'Funke Alabi', 'role'=>'Abeokuta'],
      ['text'=>'Express processing matched our launch date. Fees were transparent throughout.', 'init'=>'ZH', 'name'=>'Zainab Hassan', 'role'=>'Lagos'],
      ['text'=>'Due diligence flagged a filing gap. We fixed it before lender review and avoided delays.', 'init'=>'MO', 'name'=>'Matthew Okon', 'role'=>'Uyo'],
      ['text'=>'Needed business name for a supplier. Uploaded ID, got it fast. Professional team.', 'init'=>'OP', 'name'=>'Omawumi Peters', 'role'=>'Benin'],
    ];
    $slice = array_slice($allTestimonials, 0, 10);
    $count = count($slice);
    $perCol = (int)ceil($count/3);
    $cols = [
      array_slice($slice, 0, $perCol),
      array_slice($slice, $perCol, $perCol),
      array_slice($slice, $perCol*2, $perCol),
    ];
  ?>
  <div class="testimonials" style="border: none; background: transparent; padding: 0;">
    <div class="twrap" style="gap: 24px;">
      <?php foreach ([36,44,40] as $i=>$dur): ?>
      <div class="tcol" style="--dur:<?=$dur?>s">
        <div class="tlist" style="gap: 24px;">
          <?php foreach ($cols[$i] as $t): ?>
          <div class="tcard" style="padding: 32px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); border-radius: 24px;">
            <div class="ttext" style="font-size: 15px; color: var(--text); font-style: italic;">"<?=e($t['text'])?>"</div>
            <div class="tmeta" style="margin-top: 24px;">
              <span class="tavatar" style="background: var(--primary-tint); color: var(--primary); font-weight: 700;"><?=e($t['init'])?></span>
              <div>
                <div style="font-weight: 700; color: var(--text); font-size: 14px;"><?=e($t['name'])?></div>
                <div class="muted" style="font-size: 12px;"><?=e($t['role'])?></div>
              </div>
            </div>
          </div>
          <?php endforeach; ?>
        </div>
        <div class="tlist" aria-hidden="true" style="gap: 24px;">
          <?php foreach ($cols[$i] as $t): ?>
          <div class="tcard" style="padding: 32px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); border-radius: 24px;">
            <div class="ttext" style="font-size: 15px; color: var(--text); font-style: italic;">"<?=e($t['text'])?>"</div>
            <div class="tmeta" style="margin-top: 24px;">
              <span class="tavatar" style="background: var(--primary-tint); color: var(--primary); font-weight: 700;"><?=e($t['init'])?></span>
              <div>
                <div style="font-weight: 700; color: var(--text); font-size: 14px;"><?=e($t['name'])?></div>
                <div class="muted" style="font-size: 12px;"><?=e($t['role'])?></div>
              </div>
            </div>
          </div>
          <?php endforeach; ?>
        </div>
      </div>
      <?php endforeach; ?>
    </div>
  </div>
</section>
  <div style="text-align:center;margin-top:8px">
    <a class="btn primary" href="<?=cta_url('register.php')?>">Join 200+ Nigerian businesses — Register today</a>
  </div>
 </section>



<section class="section" id="faq" style="padding: 100px 0;">
  <div class="container">
    <div style="text-align: center; max-width: 700px; margin: 0 auto 60px;">
      <h2 style="font-size: 36px; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 16px;">Common <span class="gradient-text">Questions.</span></h2>
      <p class="lead" style="font-size: 18px;">Everything you need to know about registering your business in Nigeria.</p>
    </div>
    <div class="card reveal" style="max-width: 840px; margin: 0 auto; padding: 40px; border: none; background: white; box-shadow: var(--shadow-sm);">
      <div style="display: grid; gap: 8px;">
        <details style="border-bottom: 1px solid var(--border);">
          <summary style="padding: 20px 0; font-weight: 600; font-size: 16px; color: var(--text);">What is CAC and why should I register?</summary>
          <div style="padding: 0 0 20px; color: var(--muted); line-height: 1.6;">The Corporate Affairs Commission (CAC) is Nigeria’s corporate registry. Registration gives your business legal recognition, credibility, and access to corporate banking and contracts.</div>
        </details>
        <details style="border-bottom: 1px solid var(--border);">
          <summary style="padding: 20px 0; font-weight: 600; font-size: 16px; color: var(--text);">How much does it cost?</summary>
          <div style="padding: 0 0 20px; color: var(--muted); line-height: 1.6;">Costs vary by registration type (Business Name, Limited Company, or NGO). We provide transparent, flat-fee pricing that includes all statutory fees and professional handling.</div>
        </details>
        <details style="border-bottom: 1px solid var(--border);">
          <summary style="padding: 20px 0; font-weight: 600; font-size: 16px; color: var(--text);">How long does the process take?</summary>
          <div style="padding: 0 0 20px; color: var(--muted); line-height: 1.6;">Most registrations are completed within a few working days. We audit every application to prevent delays caused by rejections.</div>
        </details>
        <details style="border-bottom: 1px solid var(--border);">
          <summary style="padding: 20px 0; font-weight: 600; font-size: 16px; color: var(--text);">What documents do I need?</summary>
          <div style="padding: 0 0 20px; color: var(--muted); line-height: 1.6;">Generally, you'll need a valid ID (NIN, Driver's License, or Passport), passport-sized photos, and your business address. We provide a detailed checklist during the process.</div>
        </details>
      </div>
      <div style="margin-top: 40px; text-align: center;">
        <p class="muted" style="margin-bottom: 16px;">Have more questions?</p>
        <a class="btn secondary" href="<?=url('blog')?>">Read our Guide</a>
      </div>
    </div>
  </div>
</section>

<section class="section" style="text-align: center; padding: 100px 0; background: linear-gradient(135deg, var(--primary), var(--indigo)); color: white; border-radius: 40px; margin: 40px 24px; position: relative; overflow: hidden;" id="start">
  <div style="position: absolute; inset: 0; opacity: 0.1; background-image: radial-gradient(circle at 2px 2px, white 1px, transparent 0); background-size: 24px 24px;"></div>
  <div class="reveal" style="max-width: 700px; margin: 0 auto; position: relative; z-index: 1;">
    <h2 style="font-size: 48px; font-weight: 800; letter-spacing: -0.04em; margin: 0 0 20px; color: white;">Your business journey starts <span style="opacity: 0.8;">today.</span></h2>
    <p class="lead" style="font-size: 20px; color: rgba(255,255,255,0.9); margin-bottom: 40px;">Stop putting it off. Make your business official and open doors to bank accounts, contracts, and investors.</p>
    <div style="display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;">
      <a class="btn" href="<?=cta_url('customer/new_application.php')?>" style="padding: 16px 40px; font-size: 16px; background: white; color: var(--primary); border: none; font-weight: 800;">Register My Business</a>
      <a class="btn" href="<?=url('pricing.php')?>" style="padding: 16px 40px; font-size: 16px; background: rgba(255,255,255,0.1); color: white; border: 1px solid rgba(255,255,255,0.3); font-weight: 800; backdrop-filter: blur(10px);">See Pricing</a>
    </div>
    <p style="margin-top: 32px; font-size: 14px; opacity: 0.7;">No hidden fees &middot; All-inclusive flat rates &middot; Expert support</p>
  </div>
</section>
<?php include __DIR__ . '/includes/footer.php'; ?>
