<?php
session_start();
if (!isset($_SESSION['username'])) {
    $_SESSION['username'] = "Guest"; 
}
?>
<?php
 include 'includes/header.php';
 include 'includes/admin-sidebar.php';
include 'paystack_functions.php';
?>
<?php
require 'config.php'; 

if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'super-admin') {
    header("Location: login.php");
    exit();
}

// Fetch approved payouts
$query_approved_payouts = "SELECT p.id, u.username, p.amount, p.status, p.paystack_transfer_code, p.created_at
                           FROM tbl_payouts p
                           JOIN users u ON p.admin_id = u.id
                           WHERE p.status = 'Approved'
                           ORDER BY p.created_at DESC";

$result_approved_payouts = $conn->query($query_approved_payouts);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Approved Payouts</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="includes/css/style.css">
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="container-fluid">
    <div class="row">
        <div class="col-md-10 content">
            <div class="row">
<div class="container mt-4">
    <h4>Approved Payouts</h4>
    <table class="table table-bordered">
        <thead class="table-dark">
            <tr>
                <th>Username</th>
                <th>Amount</th>
                <th>Paystack Transfer Code</th>
                <th>Status</th>
                <th>Created At</th>
            </tr>
        </thead>
        <tbody>
            <?php while ($row = $result_approved_payouts->fetch_assoc()): ?>
                <tr>
                    <td><?php echo htmlspecialchars($row['username']); ?></td>
                    <td>GHS <?php echo number_format($row['amount'], 2); ?></td>
                    <td><?php echo htmlspecialchars($row['paystack_transfer_code']); ?></td>
                    <td><?php echo ucfirst($row['status']); ?></td>
                    <td><?php echo $row['created_at']; ?></td>
                </tr>
            <?php endwhile; ?>
        </tbody>
    </table>
</div>

</body>
</html>
