<?php
session_start();
include("config.php");

// Fetch session username
$admin_username = $_SESSION['admin_username'] ?? '';

if (!$admin_username) {
    header("Location: login.php");
    exit;
}

// Fetch admin info
$stmt = $dbh->prepare("SELECT * FROM admins WHERE username = ?");
$stmt->execute([$admin_username]);
$admin = $stmt->fetch(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Profile</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .profile-card {
            max-width: 600px;
            margin: auto;
        }
        .card-header {
            font-size: 20px;
            font-weight: 600;
        }
        .profile-icon {
            width: 80px;
            height: 80px;
            background-color: #0d6efd;
            border-radius: 50%;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 36px;
            margin: auto;
        }
    </style>
</head>
<body>

<?php include "includes/header.php"; ?>
<div class="container py-5">
    <div class="card profile-card shadow-sm">
        <div class="card-header text-white text-center" style="background-color:grey;">
            Admin Profile
        </div>
        <div class="card-body">
            <div class="text-center mb-4">
                <div class="profile-icon">
                    <i class="fas fa-user-shield"></i>
                </div>
                <h4 class="mt-2"><?= htmlentities($admin['username'] ?? 'Unknown') ?></h4>
                <p class="text-muted">Administrator</p>
            </div>
            <?php if ($admin): ?>
                <table class="table table-hover">
                    <tr>
                        <th>Username</th>
                        <td><?= htmlentities($admin['username']) ?></td>
                    </tr>
                    <tr>
                        <th>Email</th>
                        <td><?= htmlentities($admin['email']) ?></td>
                    </tr>
                    <tr>
                        <th>Created At</th>
                        <td><?= htmlentities($admin['created_at']) ?></td>
                    </tr>
                </table>
            <?php else: ?>
                <div class="alert alert-warning">Admin not found.</div>
            <?php endif; ?>
            <div class="text-end">
                <a href="admin-change-password.php" class="btn btn-outline-primary mt-3">Change Password</a>
            </div>
        </div>
    </div>
</div>
<?php include "includes/footer.php"; ?>
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
</body>
</html>
