<?php
session_start();
include('../includes/config.php');

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

$sql = "SELECT * FROM users WHERE id = $id";
$result = mysqli_query($conn, $sql);

if ($row = mysqli_fetch_assoc($result)) {
    $username = htmlspecialchars($row['username']);
    $email = htmlspecialchars($row['email']);
    $first_name = htmlspecialchars($row['first_name']);
    $last_name = htmlspecialchars($row['last_name']);
    $phone = htmlspecialchars($row['phone']);
    $status = $row['status'];
    $fund_balance = number_format($row['fund_balance'], 2);
    $available_balance = number_format($row['available_balance'], 2);
    $total_profit = number_format($row['total_profit'], 2);
    $registration_date = date('F d, Y', strtotime($row['registration_date']));
    
    echo "<input type='hidden' id='userStatus' value='$status'>";
    
    echo "<div class='row'>";
    echo "<div class='col-md-6'>";
    echo "<h6>Personal Information</h6>";
    echo "<table class='table table-sm'>";
    echo "<tr><td><strong>Username:</strong></td><td>$username</td></tr>";
    echo "<tr><td><strong>Email:</strong></td><td>$email</td></tr>";
    echo "<tr><td><strong>Full Name:</strong></td><td>$first_name $last_name</td></tr>";
    echo "<tr><td><strong>Phone:</strong></td><td>$phone</td></tr>";
    echo "<tr><td><strong>Status:</strong></td><td><span class='badge bg-" . ($status == 'verified' ? 'success' : 'warning') . "'>$status</span></td></tr>";
    echo "</table>";
    echo "</div>";
    
    echo "<div class='col-md-6'>";
    echo "<h6>Financial Information</h6>";
    echo "<table class='table table-sm'>";
    echo "<tr><td><strong>Fund Balance:</strong></td><td>$$fund_balance</td></tr>";
    echo "<tr><td><strong>Available Balance:</strong></td><td>$$available_balance</td></tr>";
    echo "<tr><td><strong>Total Profit:</strong></td><td>$$total_profit</td></tr>";
    echo "<tr><td><strong>Joined Date:</strong></td><td>$registration_date</td></tr>";
    echo "</table>";
    echo "</div>";
    echo "</div>";
} else {
    echo "<div class='alert alert-danger'>User not found</div>";
}
?>