<?php
require_once 'includes/config.php';
require_once 'includes/functions.php';
requireLogin();
$uid = $_SESSION['user_id'];

// The IPN (payhere-notify.php) is what actually activates Pro — this page is just
// a friendly landing spot for the user's browser redirect, so we re-check status here.
$stmt = $pdo->prepare("SELECT * FROM payhere_payments WHERE user_id = ? ORDER BY id DESC LIMIT 1");
$stmt->execute([$uid]);
$payment = $stmt->fetch();

$user = getCurrentUser();
$nowPro = isProUser($user);

require_once 'includes/header.php';
renderHeader('Payment', 'upgrade');
?>
<div style="max-width:520px;margin:60px auto;text-align:center;font-family:'Plus Jakarta Sans',sans-serif;">
  <?php if ($nowPro): ?>
    <div style="font-size:48px;">🎉</div>
    <h2 style="font-family:'Outfit',sans-serif;color:var(--text-primary);margin:14px 0 8px;">You're Pro!</h2>
    <p style="color:var(--text-muted);font-size:14px;">Your subscription is active. Unlimited AI Tips &amp; AI Analysis are unlocked.</p>
  <?php else: ?>
    <div style="font-size:48px;">⏳</div>
    <h2 style="font-family:'Outfit',sans-serif;color:var(--text-primary);margin:14px 0 8px;">Payment received — confirming…</h2>
    <p style="color:var(--text-muted);font-size:14px;">PayHere is finalizing your payment. This usually takes a few seconds. Refresh this page shortly, or check the Upgrade page.</p>
  <?php endif; ?>
  <a href="<?= SITE_URL ?>/upgrade.php" class="up-btn" style="display:inline-block;margin-top:20px;padding:12px 26px;border-radius:12px;background:linear-gradient(135deg,#6366f1,#a855f7);color:#fff;text-decoration:none;font-weight:700;">Go to Upgrade Page</a>
</div>
<?php require_once 'includes/footer.php'; renderFooter(); ?>
