{% extends "base.html" %}
{% block title %}New User Questionnaire{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-question-circle"></i> New User Questionnaire</h1>
    <p class="small text-muted">
        Questions shown to users on the telnet/SSH/rlogin BBS right after
        registration. Answers are stored per user.
    </p>
</div>

<form method="post" class="card p-3 mb-3">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <input type="hidden" name="action" value="add">
    <div class="row g-2">
        <div class="col-md-7">
            <label class="form-label small mb-0">Prompt</label>
            <input type="text" name="prompt" class="form-control" placeholder="Where did you hear about us?" required>
        </div>
        <div class="col-md-2">
            <label class="form-label small mb-0">Sort</label>
            <input type="number" name="sort_order" class="form-control" value="0">
        </div>
        <div class="col-md-2 form-check d-flex align-items-end">
            <input type="checkbox" id="req" name="is_required" class="form-check-input mt-0">
            <label class="form-check-label ms-2" for="req">Required</label>
        </div>
        <div class="col-md-1 d-flex align-items-end">
            <button class="btn btn-primary w-100"><i class="bi bi-plus"></i></button>
        </div>
    </div>
</form>

<table class="table table-sm">
    <thead><tr><th>#</th><th>Prompt</th><th>Required</th><th>Active</th><th></th></tr></thead>
    <tbody>
    {% for q in rows %}
    <tr>
        <td>{{ q.sort_order }}</td>
        <td>{{ q.prompt }}</td>
        <td>{% if q.is_required %}<i class="bi bi-check text-success"></i>{% endif %}</td>
        <td>
            <form method="post" class="d-inline">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <input type="hidden" name="action" value="toggle">
                <input type="hidden" name="qid" value="{{ q.id }}">
                <button class="btn btn-sm {% if q.is_active %}btn-success{% else %}btn-outline-secondary{% endif %}">
                    {% if q.is_active %}On{% else %}Off{% endif %}
                </button>
            </form>
        </td>
        <td>
            <form method="post" class="d-inline" onsubmit="return confirm('Delete?');">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <input type="hidden" name="action" value="delete">
                <input type="hidden" name="qid" value="{{ q.id }}">
                <button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
            </form>
        </td>
    </tr>
    {% else %}
    <tr><td colspan="5" class="text-muted">No questions defined.</td></tr>
    {% endfor %}
    </tbody>
</table>
{% endblock %}
