{% extends "base.html" %}
{% block title %}Source Drop Box — SooSeF{% endblock %}
{% block content %}
<h2><i class="bi bi-inbox me-2"></i>Source Drop Box</h2>
<p class="text-muted">Create time-limited upload links for sources who cannot install SooSeF.</p>

<div class="card bg-dark mb-4">
    <div class="card-body">
        <h5 class="card-title">Create Upload Token</h5>
        <form method="POST">
              <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
            <input type="hidden" name="action" value="create">
            <div class="row g-3">
                <div class="col-md-4">
                    <label class="form-label">Label (internal only)</label>
                    <input type="text" name="label" class="form-control bg-dark text-light"
                           placeholder="e.g., Gulf Ministry Source">
                </div>
                <div class="col-md-3">
                    <label class="form-label">Expires in (hours)</label>
                    <input type="number" name="hours" value="24" min="1" max="168"
                           class="form-control bg-dark text-light">
                </div>
                <div class="col-md-3">
                    <label class="form-label">Max files</label>
                    <input type="number" name="max_files" value="10" min="1" max="100"
                           class="form-control bg-dark text-light">
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary w-100">Create</button>
                </div>
            </div>
        </form>
    </div>
</div>

{% if tokens %}
<h5>Active Tokens</h5>
<table class="table table-dark table-sm">
    <thead>
        <tr>
            <th>Label</th>
            <th>Token</th>
            <th>Used / Max</th>
            <th>Expires</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        {% for token, data in tokens.items() %}
        <tr>
            <td>{{ data.label }}</td>
            <td><code>{{ token[:12] }}...</code></td>
            <td>{{ data.used }} / {{ data.max_files }}</td>
            <td>{{ data.expires_at[:16] }}</td>
            <td>
                <form method="POST" class="d-inline">
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                    <input type="hidden" name="action" value="revoke">
                    <input type="hidden" name="token" value="{{ token }}">
                    <button type="submit" class="btn btn-sm btn-outline-danger">Revoke</button>
                </form>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<p class="text-muted">No active upload tokens.</p>
{% endif %}
{% endblock %}
