<?php
include 'includes/db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $full_name = $_POST['full_name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $department = $_POST['department'];
    $date = $_POST['appointment_date'];
    $time = $_POST['appointment_time'];
    $message = $_POST['message'];

    $stmt = $conn->prepare(
        "INSERT INTO appointments 
        (full_name, phone, email, department, appointment_date, appointment_time, message)
        VALUES (?,?,?,?,?,?,?)"
    );
    $stmt->bind_param("sssssss",
        $full_name, $phone, $email, $department, $date, $time, $message
    );
    $stmt->execute();

    $success = "Your appointment request has been submitted successfully.";
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Appointment | Sigal Laboratories</title>
<style>
form {
    max-width: 600px;
    margin: 40px auto;
    background: #fff;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
input, select, textarea {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border-radius: 6px;
    border: 1px solid #ccc;
}
button {
    background: #25A9C2;
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
}
button:hover { background: #1e8ea3; }
.success { color: green; margin-top: 10px; }
</style>
</head>
<body>
<?php include 'includes/header.php'; ?>

<h2 style="text-align:center;">Book an Appointment</h2>

<form method="POST">
    <input type="text" name="full_name" placeholder="Full Name" required>
    <input type="text" name="phone" placeholder="Phone Number" required>
    <input type="email" name="email" placeholder="Email (optional)">

    <select name="department" required>
        <option value="">Select Department</option>
        <option>Hematology</option>
        <option>Microbiology</option>
        <option>Histopathology</option>
        <option>Molecular Biology</option>
        <option>Biochemistry</option>
    </select>

    <input type="date" name="appointment_date" required>
    <input type="time" name="appointment_time" required>

    <textarea name="message" rows="4" placeholder="Message (optional)"></textarea>

    <button type="submit">Submit Appointment</button>

    <?php if(isset($success)) echo "<p class='success'>$success</p>"; ?>
</form>

</body>
</html>
