<?php

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

if (!isset($_GET['id'])) {
    header("Location: members.php");
    exit();
}

$user_id = (int) $_GET['id'];

$stmt = $pdo->prepare("SELECT * FROM users WHERE id=?");
$stmt->execute([$user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$user) {
    die("Member not found.");
}

?>

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

<head>

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

<title>Fund Wallet</title>

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

</head>

<body>

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

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

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

<div class="main-content">

<div class="table-card">
<h2 class="page-heading">
    <i class="fas fa-wallet"></i>
    Fund Member Wallet
</h2>

<div class="wallet-user-card">

    <div class="wallet-avatar">

        <i class="fas fa-user-circle"></i>

    </div>

    <div class="wallet-user-info">

        <h3><?= htmlspecialchars($user['fullname']); ?></h3>

        <p><?= htmlspecialchars($user['phone']); ?></p>

    </div>

</div>

<div class="wallet-balance-card">

    <small>Current Wallet Balance</small>

    <h1>₦<?= number_format($user['wallet_balance'],2); ?></h1>

</div>

<form action="process_wallet.php" method="POST">

<input type="hidden" name="user_id" value="<?= $user['id']; ?>">

<div class="form-group">

<label>Amount to Credit</label>

<input
type="number"
id="amount"
name="amount"
step="0.01"
min="1"
required
class="form-control"
placeholder="Enter Amount">

</div>

<div class="quick-amounts">

<button type="button" class="quick-btn" onclick="setAmount(5000)">₦5,000</button>

<button type="button" class="quick-btn" onclick="setAmount(10000)">₦10,000</button>

<button type="button" class="quick-btn" onclick="setAmount(20000)">₦20,000</button>

<button type="button" class="quick-btn" onclick="setAmount(50000)">₦50,000</button>

</div>

<br>

<button class="fund-wallet-btn">

<i class="fas fa-money-bill-wave"></i>

Credit Wallet

</button>

</form>

</div>

</div>

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

<script>
function setAmount(amount){

document.getElementById("amount").value = amount;

}
</script>

</body>

</html>