<?php
// File: /customer/profile.php
include 'header.php';

// Fetch current user's data
$user_id = $_SESSION['user_id'];
$user_data = null;

$stmt = $conn->prepare("SELECT username, email FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
    $user_data = $result->fetch_assoc();
}
$stmt->close();
?>

<div class="p-6 md:p-8">
    <h1 class="text-3xl font-bold text-ucf-charcoal mb-6">My Profile</h1>

    <div class="max-w-lg mx-auto bg-white p-8 rounded-lg shadow-md">
        <h2 class="text-2xl font-bold text-ucf-charcoal mb-4">Account Details</h2>

        <?php if(isset($_GET['status']) && $_GET['status'] == 'success'): ?>
             <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-6" role="alert">
                <p class="font-bold">Success!</p>
                <p>Your profile has been updated.</p>
            </div>
        <?php endif; ?>
        
        <form action="profile_handler.php" method="POST" class="space-y-6">
            <div>
                <label for="username" class="block text-sm font-medium text-gray-700">Username</label>
                <input type="text" name="username" id="username" readonly disabled class="mt-1 block w-full rounded-md border-gray-300 shadow-sm bg-gray-100" value="<?php echo htmlspecialchars($user_data['username']); ?>">
                <p class="text-xs text-gray-500 mt-1">Username cannot be changed.</p>
            </div>
             <div>
                <label for="email" class="block text-sm font-medium text-gray-700">Email Address</label>
                <input type="email" name="email" id="email" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm" value="<?php echo htmlspecialchars($user_data['email']); ?>">
            </div>

            <div class="border-t border-gray-200 pt-6">
                <h3 class="text-lg font-medium text-ucf-charcoal">Change Password</h3>
                 <p class="text-sm text-gray-500 mt-1">Leave blank if you don't want to change your password.</p>
                <div class="space-y-4 mt-4">
                    <div>
                        <label for="new_password" class="block text-sm font-medium text-gray-700">New Password</label>
                        <input type="password" name="new_password" id="new_password" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm">
                    </div>
                     <div>
                        <label for="confirm_password" class="block text-sm font-medium text-gray-700">Confirm New Password</label>
                        <input type="password" name="confirm_password" id="confirm_password" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm">
                    </div>
                </div>
            </div>

            <div class="flex justify-end pt-4">
                <button type="submit" class="bg-ucf-green text-white font-bold py-2 px-4 rounded-lg hover:bg-ucf-green-dark transition-colors">
                    Save Changes
                </button>
            </div>
        </form>
    </div>
</div>

<?php include 'footer.php'; ?>
