{% extends "base.html" %}
{% block content %}
<div class="container mt-4">
    <h2>{{ company.name }} - Add User</h2>
    
    <div class="card">
        <div class="card-body">
            {% if users %}
            <form method="POST" action="{{ url_for('auth.add_company_user', company_id=company.id) }}">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <div class="mb-3">
                    <label for="user_id" class="form-label">Select User</label>
                    <select class="form-select" id="user_id" name="user_id" required>
                        <option value="" selected disabled>Choose a user</option>
                        {% for user in users %}
                        <option value="{{ user.id }}">{{ user.username }} ({{ user.email }})</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="mb-3">
                    <label for="role" class="form-label">Role</label>
                    <select class="form-select" id="role" name="role" required>
                        <option value="User">User</option>
                        {% if current_user.is_global_admin() %}
                        <option value="CompanyAdmin">Company Admin</option>
                        {% endif %}
                    </select>
                </div>
                <div class="mb-3">
                    <a href="{{ url_for('auth.company_users', company_id=company.id) }}" class="btn btn-secondary me-2">Cancel</a>
                    <button type="submit" class="btn btn-primary">Add User</button>
                </div>
            </form>
            {% else %}
            <div class="alert alert-info">
                <p>All users are already added to this company.</p>
                <a href="{{ url_for('auth.manage_users') }}" class="btn btn-primary mt-2">Create New User</a>
            </div>
            <div class="mt-3">
                <a href="{{ url_for('auth.company_users', company_id=company.id) }}" class="btn btn-secondary">Back to Company Users</a>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}