<?php
include '../config.php';
include 'common/header.php';

$empid = $_GET['id'];
$query = "SELECT * FROM register WHERE employee_id = '$empid'";
$result = mysqli_query($conn, $query);

if (mysqli_num_rows($result) > 0) {
    $row = mysqli_fetch_assoc($result);
} else {
    echo "<p style='color:red;'>No employee found with ID: $empid</p>";
    exit();
}
?>

<div style="max-width: 600px; margin: 30px auto; padding: 25px; background: #fff; border-radius: 10px; border: 1px solid #ccc;">
    <h3 style="text-align:center;">Edit Employee</h3>
    <form action="update_user.php" method="POST">
        <input type="hidden" name="employee_id" value="<?= $row['employee_id']; ?>">

        <label>First Name</label>
        <input type="text" name="fname" value="<?= $row['fname']; ?>" required style="width:100%;padding:8px;margin-bottom:10px;border: 1px solid grey;border-radius: 5px;">

        <label>Last Name</label>
        <input type="text" name="lname" value="<?= $row['lname']; ?>" required style="width:100%;padding:8px;margin-bottom:10px;border: 1px solid grey;border-radius: 5px;">

        <label>Email</label>
        <input type="email" name="email" value="<?= $row['email']; ?>" required style="width:100%;padding:8px;margin-bottom:10px;border: 1px solid grey;border-radius: 5px;">

        <label>Phone Number</label>
        <input type="text" name="number" value="<?= $row['number']; ?>" required style="width:100%;padding:8px;margin-bottom:10px;border: 1px solid grey;border-radius: 5px;">

        <label>Date of Birth</label>
        <input type="date" name="dob" value="<?= $row['dob']; ?>" required style="width:100%;padding:8px;margin-bottom:10px;border: 1px solid grey;border-radius: 5px;">

        <label>Reset Password <small>(leave blank to keep unchanged)</small></label>
        <input type="password" name="password" style="width:100%;padding:8px;margin-bottom:15px;border: 1px solid grey;border-radius: 5px;">

        <button type="submit" name="update" style="width:100%;padding:10px;background:#28a745;color:white;border:none;border-radius:5px;">Update</button>
    </form>
</div>
