{% extends "base.html" %}
{% block title %}ANSI Screens{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-tv"></i> Login / Logoff ANSI Screens</h1>
    <p class="small text-muted">
        These are the raw CP437/ANSI screens shown by the telnet/SSH/rlogin
        BBS at lifecycle events. Welcome is shown to telnet visitors before
        they log in; auto-login SSH/rlogin clients skip it. Goodbye appears
        on logoff for everyone.
    </p>
</div>

<div class="mb-3 d-flex gap-2">
    <a href="{{ url_for('menu_admin.edit_screen') }}" class="btn btn-primary">
        <i class="bi bi-plus"></i> New screen / slot
    </a>
    <a href="{{ url_for('menu_admin.list_menus') }}" class="btn btn-secondary">
        <i class="bi bi-arrow-left"></i> Back to menus
    </a>
</div>

{% if missing_builtins %}
<div class="card mb-3">
    <div class="card-header">
        <i class="bi bi-exclamation-triangle"></i> Built-in slots not yet configured
    </div>
    <ul class="list-group list-group-flush">
    {% for slot, desc in missing_builtins %}
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <span><strong><code>{{ slot }}</code></strong> &mdash; {{ desc }}</span>
            <a href="{{ url_for('menu_admin.edit_screen', slot=slot) }}" class="btn btn-sm btn-outline-primary">Create</a>
        </li>
    {% endfor %}
    </ul>
</div>
{% endif %}

{% if rows %}
<table class="table table-sm">
    <thead>
        <tr><th>Slot</th><th>Title</th><th>Active</th><th>Pause</th><th>Updated</th><th></th></tr>
    </thead>
    <tbody>
    {% for r in rows %}
    <tr>
        <td><code>{{ r.slot }}</code>
            {% if r.slot in ('welcome','goodbye','newuser') %}
              <span class="badge bg-secondary ms-1">built-in</span>
            {% endif %}
        </td>
        <td>{{ r.title or '' }}</td>
        <td>{% if r.is_active %}<i class="bi bi-check-lg text-success"></i>{% else %}<i class="bi bi-x text-muted"></i>{% endif %}</td>
        <td>{% if r.pause_after %}<span class="badge bg-warning">wait Enter</span>{% endif %}</td>
        <td><small>{{ r.updated_at.strftime('%Y-%m-%d %H:%M') if r.updated_at else '' }}</small></td>
        <td>
            <a href="{{ url_for('menu_admin.edit_screen', screen_id=r.id) }}" class="btn btn-sm btn-primary"><i class="bi bi-pencil"></i></a>
            <form method="post" action="{{ url_for('menu_admin.delete_screen', screen_id=r.id) }}" class="d-inline" onsubmit="return confirm('Delete this screen?');">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
            </form>
        </td>
    </tr>
    {% endfor %}
    </tbody>
</table>
{% else %}
<p class="text-muted">No screens defined yet.</p>
{% endif %}
{% endblock %}
