<?php

include "../includes/member_auth.php";
include "../config/database.php";

$stmt = $pdo->prepare("
SELECT
subscriptions.*,
plans.plan_name,
plans.frequency,
plans.duration,
plans.amount
FROM subscriptions
INNER JOIN plans
ON subscriptions.plan_id = plans.id
WHERE subscriptions.user_id=?
ORDER BY subscriptions.id DESC
");

$stmt->execute([$_SESSION['user_id']]);

$schemes = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>My Schemes</title>

<link rel="stylesheet" href="../assets/css/admin.css">
<link rel="stylesheet" href="../assets/css/member.css">
<link rel="stylesheet" href="../assets/css/responsive.css">

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">

</head>

<body>

<?php include "../includes/member_sidebar.php"; ?>

<div class="sidebar-overlay"></div>

<?php include "../includes/member_topbar.php"; ?>

<div class="main-content">

<div class="activity-header-bar">

<div class="activity-title-wrap">

<i class="fas fa-layer-group"></i>

<h3>My Schemes</h3>

</div>

</div>

<div class="plans-grid">

<?php if(count($schemes)>0): ?>

<?php foreach($schemes as $scheme): ?>

<div class="plan-card">

<div class="plan-top">

<div class="plan-icon">

<i class="fas fa-piggy-bank"></i>

</div>

<div>

<h4><?= htmlspecialchars($scheme['plan_name']); ?></h4>

<div class="plan-frequency">

📅 <?= htmlspecialchars($scheme['frequency']); ?>

•

⏳ <?= htmlspecialchars($scheme['duration']); ?>

</div>

</div>

</div>

<div class="plan-price">

₦<?= number_format($scheme['amount'],2); ?>

</div>

<div class="per-hand">

Per Hand

</div>

<div class="plan-description">

<strong>Hands:</strong> <?= $scheme['hands']; ?><br>

<strong>Total Investment:</strong>

₦<?= number_format($scheme['total_amount'],2); ?>

</div>

<a
href="scheme_details.php?id=<?= $scheme['id']; ?>"
class="fund-wallet-btn">

View Details

</a>

</div>

<?php endforeach; ?>

<?php else: ?>

<p>You have not joined any scheme yet.</p>

<?php endif; ?>

</div>

</div>

<script src="../assets/js/admin.js"></script>

</body>

</html>