<?php
require_once "../include/db.php";

$message = "";

// FORM SUBMIT হলে…
if ($_SERVER['REQUEST_METHOD'] == "POST") {

    $name     = $_POST['name'];
    $phone    = $_POST['phone'] ?? null;
    $active   = $_POST['active'];
    $password = password_hash($_POST['password'], PASSWORD_DEFAULT);

    $sql = "INSERT INTO delivery_men (name, phone, password, active) 
            VALUES (?, ?,  ?, ?)";

    $stmt = $conn->prepare($sql);
    $stmt->bind_param("sssi", $name, $phone, $password, $active);

    if ($stmt->execute()) {
        $message = "<div class='success'>✔ Delivery man added successfully!</div>";
    } else {
        $message = "<div class='error'>⚠ Error: " . $conn->error . "</div>";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Add Delivery Man</title>

<style>
body {
    background: #eef1f5;
    font-family: Arial;
    margin: 0;
    padding: 30px;
}

.container {
    max-width: 550px;
    background: #fff;
    padding: 25px 30px;
    margin: auto;
    border-radius: 14px;
    box-shadow: 0px 6px 25px rgba(0,0,0,0.1);
}

h2 {
    margin: 0 0 20px 0;
    color: #333;
    text-align: center;
    font-size: 24px;
}

label {
    font-weight: bold;
    margin-top: 12px;
    display: block;
}

input, select {
    width: 100%;
    padding: 11px 13px;
    border-radius: 8px;
    border: 1px solid #cfcfcf;
    margin-top: 5px;
    font-size: 15px;
}

input:focus, select:focus {
    border-color: #007bff;
    outline: none;
    box-shadow: 0 0 0 2px #007bff33;
}

button {
    background: #007bff;
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 8px;
    width: 100%;
    font-size: 16px;
    margin-top: 20px;
    cursor: pointer;
}

button:hover {
    background: #0069d9;
}

/* Messages */
.success {
    background: #2ecc71;
    padding: 12px;
    color: white;
    margin-bottom: 15px;
    border-radius: 6px;
    text-align: center;
}

.error {
    background: #e74c3c;
    padding: 12px;
    color: white;
    margin-bottom: 15px;
    border-radius: 6px;
    text-align: center;
}

</style>

</head>
<body>

<div class="container">

    <h2>Add Delivery Man</h2>

    <?= $message ?>

    <form method="POST">

        <label>Name</label>
        <input type="text" name="name" required>

        <label>Phone</label>
        <input type="text" name="phone">

       

        <label>Password</label>
        <input type="password" name="password" required>

        <label>Status</label>
        <select name="active">
            <option value="1">Active</option>
            <option value="0">Inactive</option>
        </select>

        <button type="submit">Save Delivery Man</button>
    </form>

</div>

</body>
</html>
