<!DOCTYPE html>
<div>
    <div class="d-flex align-items-center mb-3">
        <div class="rounded-circle bg-secondary bg-opacity-10 p-2 me-3 d-flex align-items-center justify-content-center"
            style="width: 2.5rem; height: 2.5rem;">
            <i class="bi bi-key-fill text-secondary"></i>
        </div>
        <div>
            <h6 class="mb-0 fw-semibold">Authentication</h6>
            <small class="text-muted">TextGrid-{{ instance|capitalize }} Session ID</small>
        </div>
        {% if tg_session_id and is_valid_session %}
        <span class="badge bg-success ms-auto">Connected</span>
        {% elif tg_session_id %}
        <span class="badge bg-warning text-dark ms-auto">Invalid
            Session</span>
        {% else %}
        <span class="badge bg-secondary ms-auto">Not Connected</span>
        {% endif %}
    </div>
    <form class="js-tab-submit" method="POST"
        action="{{ url_for('publication.save_session_id', projectname=project.path, action=action, instance=instance) }}">
        <div class="input-group">
            <span class="input-group-text bg-light border-end-0">
                <i class="bi bi-shield-lock text-muted"></i>
            </span>
            <input type="text" class="form-control border-start-0" name="tg_auth_session_id"
                id="tg_auth_session_id_{{instance}}" placeholder="Paste your TgAuth Session ID here..."
                value="{{ tg_session_id if tg_session_id }}">
            <button type="submit" class="btn btn-primary px-4">
                <i class="bi bi-check2 me-1"></i> Save
                <span class="spinner-border spinner-border-sm ms-1" style="display:none;" role="status"
                    aria-hidden="true"></span>
            </button>
            {% if tg_session_id %}
            <button type="button" class="btn btn-outline-secondary" onclick="
                this.closest('form').querySelector('input[type=text]').value = '';
                this.closest('form').querySelector('button[type=submit]').click();
            " title="Clear Session ID">
                <i class="bi bi-x-lg"></i>
            </button>
            {% endif %}
        </div>
    </form>
</div>