<?php
session_start();
if (!isset($_SESSION['role_id']) || $_SESSION['role_id'] != 1) {
    header("Location: ../../index.php");
    exit();
}

include('../../includes/config.php');
include('../../includes/header.php');
include('../../includes/footer.php');

// Fetch roles and stores
$roles = $conn->query("SELECT id, role_name FROM roles")->fetch_all(MYSQLI_ASSOC);
$stores = $conn->query("SELECT id, store_name FROM stores")->fetch_all(MYSQLI_ASSOC);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Add New User - Digital POS</title>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', sans-serif;
            background: url('../../images/bg.jpg') no-repeat center center fixed;
            background-size: cover;
            min-height: 100vh;
            color: white;
        }

        .overlay {
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            background: rgba(0,0,0,0.6);
            z-index: -1;
        }

        .form-container {
            margin: 100px auto;
            width: 600px;
            padding: 30px 40px;
            border-radius: 20px;
            background: rgba(255,255,255,0.07);
            backdrop-filter: blur(12px);
            box-shadow: 0 8px 32px rgba(0,0,0,0.5);
        }

        h2 {
            text-align: center;
            margin-bottom: 30px;
            color: #fff;
        }

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

        input, select {
            width: 100%;
            padding: 12px;
            margin-top: 6px;
            border-radius: 10px;
            border: none;
            background: rgba(255,255,255,0.2);
            color: white;
            font-size: 1rem;
        }

        input::placeholder {
            color: #ddd;
        }

        button {
            margin-top: 25px;
            width: 100%;
            background: #ff6f00;
            color: white;
            padding: 14px;
            border: none;
            border-radius: 25px;
            font-size: 1rem;
            font-weight: bold;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        button:hover {
            background: #e65c00;
        }

        @media (max-width: 700px) {
            .form-container {
                width: 90%;
                padding: 25px;
            }
        }
    </style>
</head>
<body>

<div class="overlay"></div>

<div class="form-container">
    <h2>Add New User</h2>
    <form method="POST" action="create_user.php">
        <label>First Name</label>
        <input type="text" name="first_name" placeholder="Enter first name" required>

        <label>Last Name</label>
        <input type="text" name="last_name" placeholder="Enter last name" required>

        <label>Username</label>
        <input type="text" name="username" placeholder="Choose a username" required>

        <label>Email</label>
        <input type="email" name="email" placeholder="example@email.com">

        <label>Phone Number</label>
        <input type="text" name="phone_number" placeholder="+265...">

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

        <label>Role</label>
        <select name="role_id" required>
            <option value="">-- Select Role --</option>
            <?php foreach ($roles as $role): ?>
                <option value="<?= $role['id'] ?>"><?= $role['role_name'] ?></option>
            <?php endforeach; ?>
        </select>

        <label>Store</label>
        <select name="store_id" required>
            <option value="">-- Select Store --</option>
            <?php foreach ($stores as $store): ?>
                <option value="<?= $store['id'] ?>"><?= $store['store_name'] ?></option>
            <?php endforeach; ?>
        </select>

        <button type="submit">➕ Create User</button>
    </form>
</div>

</body>
</html>
