@extends('layout')
@section('title', 'Add user')
@section('content')
<div class="page-header"><h1>Add user</h1></div>

<div class="card" style="max-width:480px;">
    <form method="POST" action="{{ route('users.store') }}">
        @csrf
        <label for="name">Name</label>
        <input type="text" id="name" name="name" value="{{ old('name') }}" required>

        <label for="email">Email</label>
        <input type="email" id="email" name="email" value="{{ old('email') }}" required>

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

        <label for="role">Role</label>
        <select name="role" id="role" required>
            <option value="admin" @selected(old('role') === 'admin')>Admin</option>
            <option value="hr" @selected(old('role') === 'hr')>HR</option>
            <option value="security" @selected(old('role') === 'security')>Security</option>
        </select>

        <label for="site_id">Site (security scope, optional for admin/hr)</label>
        <select name="site_id" id="site_id">
            <option value="">All sites</option>
            @foreach($sites as $site)
                <option value="{{ $site->id }}" @selected((string) old('site_id') === (string) $site->id)>{{ $site->name }}</option>
            @endforeach
        </select>

        <button type="submit" class="btn btn-primary btn-block">Create user</button>
    </form>
</div>
@endsection
