<?php
session_start();
$conn = new mysqli("localhost", "kkfxoaad", "Bitok@2025", "kkfxoaad_bella");

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$userId = $_SESSION['user_id'];

// Fetch current user info
$stmt = $conn->prepare("SELECT firstName, lastName, email, phone FROM users WHERE id=?");
$stmt->bind_param("i", $userId);
$stmt->execute();
$stmt->bind_result($firstName, $lastName, $email, $phone);
$stmt->fetch();
$stmt->close();
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Profile</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<style>
body { background:#000; color:#fff; font-family: 'Segoe UI', sans-serif; margin:0; }
.container { max-width:600px; margin:50px auto; background:#1a1a1a; padding:25px; border-radius:12px; }
h1 { text-align:center; color:#f0f0f0; }
input { width:100%; padding:12px; margin:8px 0; border-radius:6px; border:1px solid #555; background:#222; color:#fff; }
input:focus { border-color:#fff; outline:none; }
button { padding:12px; border:none; border-radius:6px; cursor:pointer; margin-top:10px; }
button.save { background:#fff; color:#000; }
button.save:hover { background:#ccc; }
button.cancel { background:#333; color:#fff; }
button.cancel:hover { background:#555; }
</style>
</head>
<body>

<div class="container">
<h1>Edit Profile</h1>

<?php
// Display errors if any
if (!empty($_SESSION['profile_errors'])) {
    echo '<ul style="color:red;">';
    foreach ($_SESSION['profile_errors'] as $err) echo "<li>$err</li>";
    echo '</ul>';
    unset($_SESSION['profile_errors']);
}
?>

<form action="save-profile.php" method="post">
    <input type="text" name="firstName" placeholder="First Name" value="<?= htmlspecialchars($firstName) ?>" required>
    <input type="text" name="lastName" placeholder="Last Name" value="<?= htmlspecialchars($lastName) ?>" required>
    <input type="email" name="email" placeholder="Email" value="<?= htmlspecialchars($email) ?>" required>
    <input type="tel" name="phone" placeholder="Phone" value="<?= htmlspecialchars($phone) ?>" required>
    <button type="submit" class="save">Save</button>
    <a href="profile.php"><button type="button" class="cancel">Cancel</button></a>
</form>
</div>
</body><?php include "footer.php"; ?>
</html>
