{% extends "base.html" %}

{% block title %}OAuth Clients - NanoIDP{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-app me-2"></i>OAuth Clients</h2>
    <a href="{{ url_for('ui.client_create') }}" class="btn btn-primary">
        <i class="bi bi-plus-lg me-2"></i>New Client
    </a>
</div>

<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Client ID</th>
                        <th>Description</th>
                        <th>Secret (masked)</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for client in clients %}
                    <tr>
                        <td><code>{{ client.client_id }}</code></td>
                        <td>{{ client.description or '-' }}</td>
                        <td>
                            <code class="text-muted">{{ client.client_secret[:8] }}...{{ client.client_secret[-4:] }}</code>
                        </td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="{{ url_for('ui.client_edit', client_id=client.client_id) }}" class="btn btn-outline-primary">
                                    <i class="bi bi-pencil"></i>
                                </a>
                                <form action="{{ url_for('ui.client_regenerate_secret', client_id=client.client_id) }}" method="post" class="d-inline">
                                    <button type="submit" class="btn btn-outline-warning" title="Regenerate Secret" onclick="return confirm('Regenerate secret for {{ client.client_id }}? The old secret will stop working.')">
                                        <i class="bi bi-arrow-clockwise"></i>
                                    </button>
                                </form>
                                <form action="{{ url_for('ui.client_delete', client_id=client.client_id) }}" method="post" class="d-inline">
                                    <button type="submit" class="btn btn-outline-danger" onclick="return confirm('Delete client {{ client.client_id }}?')">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="4" class="text-center text-muted py-4">
                            <i class="bi bi-inbox fs-1 d-block mb-2"></i>
                            No OAuth clients configured
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- Usage Info -->
<div class="card mt-4">
    <div class="card-header">
        <i class="bi bi-terminal me-2"></i>Usage Example
    </div>
    <div class="card-body">
        <p class="mb-2">Request a token using client credentials:</p>
        <pre class="bg-dark text-light p-3 rounded"><code>curl -X POST '{{ request.url_root }}token' \
  -u 'CLIENT_ID:CLIENT_SECRET' \
  -d 'grant_type=password&username=USER&password=PASS'</code></pre>
    </div>
</div>
{% endblock %}
