<?php

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

$user_id = $_SESSION['user_id'];

/*
|--------------------------------------------------------------------------
| Get Member Information
|--------------------------------------------------------------------------
*/

$stmt = $pdo->prepare("
    SELECT
        id,
        fullname,
        email,
        phone,
        profile_picture,
        wallet_balance,
        virtual_account_number,
        savings_target,
        status,
        created_at
    FROM users
    WHERE id=?
    LIMIT 1
");

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

$user = $stmt->fetch(PDO::FETCH_ASSOC);

if(!$user){

    header("Location: dashboard.php");
    exit();

}

?>

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

<head>

<meta charset="UTF-8">

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

<title>My Profile</title>

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

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

<link rel="stylesheet" href="../assets/css/member.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">


<!-- PAGE HEADER -->

<div class="page-header">

<div>

<h1>

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

My Profile

</h1>

<p>

View your account information.

</p>

</div>

</div>



<!-- PROFILE HEADER -->

<div class="profile-card">


<div class="profile-avatar-large">

    <?php if(!empty($user['profile_picture'])): ?>

        <img
            src="../uploads/profile/<?= htmlspecialchars($user['profile_picture']); ?>"
            alt="Profile Picture"
        >

    <?php else: ?>

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

    <?php endif; ?>

</div>


<div class="profile-main-info">

<h2>

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

</h2>

<p>

<i class="fas fa-phone"></i>

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

</p>

<p>

<i class="fas fa-envelope"></i>

<?= htmlspecialchars($user['email']); ?>

</p>

</div>


</div>



<!-- ACCOUNT INFORMATION -->

<div class="activity-card">


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

<i class="fas fa-id-card"></i>

<h3>Account Information</h3>

</div>


<div class="profile-info-grid">


<div class="profile-info-item">

<span>Full Name</span>

<strong>

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

</strong>

</div>


<div class="profile-info-item">

<span>Email Address</span>

<strong>

<?= htmlspecialchars($user['email']); ?>

</strong>

</div>


<div class="profile-info-item">

<span>Phone Number</span>

<strong>

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

</strong>

</div>


<div class="profile-info-item">

<span>Account Status</span>

<strong>

<?php

if($user['status']=="active"){

    echo '<span class="badge success">Active</span>';

}elseif($user['status']=="pending"){

    echo '<span class="badge warning">Pending</span>';

}else{

    echo '<span class="badge danger">Suspended</span>';

}

?>

</strong>

</div>


<div class="profile-info-item">

<span>Wallet Balance</span>

<strong>

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

</strong>

</div>


<div class="profile-info-item">

<span>Savings Target</span>

<strong>

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

</strong>

</div>


<div class="profile-info-item">

<span>Virtual Account</span>

<strong>

<?php

if(empty($user['virtual_account_number'])){

    echo "Pending";

}else{

    echo htmlspecialchars(
        $user['virtual_account_number']
    );

}

?>

</strong>

</div>


<div class="profile-info-item">

<span>Member Since</span>

<strong>

<?= date(
    "d M Y",
    strtotime($user['created_at'])
); ?>

</strong>

</div>


</div>


</div>



<!-- EDIT PROFILE -->

<div class="activity-card">


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

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

<h3>Profile Settings</h3>

</div>


<p class="profile-note">

Need to change your personal information?

</p>


<a href="edit_profile.php" class="profile-edit-btn">

<i class="fas fa-pen"></i>

Edit Profile

</a>


</div>


</div>


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

</body>

</html>