{% extends "base.html" %}
{% block title %}{% if node %}Edit{% else %}Register{% endif %} QWK Node — {{ config.BBS_NAME }}{% endblock %}

{% block content %}
<div class="bbs-header d-flex justify-content-between align-items-center flex-wrap gap-2">
    <h1><i class="bi bi-archive"></i> {% if node %}Edit QWK Node — {{ node.packet_id }}{% else %}Register QWK Node{% endif %}</h1>
    <a href="{{ url_for('hub_admin.qwk_nodes') }}" class="btn btn-secondary">
        <i class="bi bi-arrow-left"></i> Back to QWK Nodes
    </a>
</div>

{% with messages = get_flashed_messages(with_categories=true) %}
{% for cat, msg in messages %}
<div class="alert alert-{{ cat }} alert-dismissible fade show">{{ msg }}
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>{% endfor %}{% endwith %}

<div class="card" style="max-width:560px;">
    <div class="card-body">
        <form method="POST">
            {{ form.hidden_tag() }}
            <div class="mb-3">
                {{ form.packet_id.label(class="form-label") }}
                {{ form.packet_id(class="form-control text-uppercase", placeholder="MYNODE") }}
                <div class="form-text">Short unique ID (up to 8 chars). Automatically uppercased. This becomes the node's identity on the network.</div>
            </div>
            <div class="mb-3">
                {{ form.name.label(class="form-label") }}
                {{ form.name(class="form-control") }}
            </div>
            <div class="row">
                <div class="col-md-6 mb-3">
                    {{ form.sysop.label(class="form-label") }}
                    {{ form.sysop(class="form-control") }}
                </div>
                <div class="col-md-6 mb-3">
                    {{ form.email.label(class="form-label") }}
                    {{ form.email(class="form-control") }}
                </div>
            </div>
            {% if form.hub_identity_id.choices|length > 1 %}
            <div class="mb-3">
                {{ form.hub_identity_id.label(class="form-label") }}
                {{ form.hub_identity_id(class="form-select") }}
            </div>
            {% endif %}
            <div class="mb-3">
                {{ form.password.label(class="form-label") }}
                {{ form.password(class="form-control", autocomplete="new-password") }}
                {% if node %}<div class="form-text">Leave blank to keep current password.</div>{% endif %}
                <div class="form-text">Used for HTTP Basic Auth and FTP login when the node polls for packets.</div>
            </div>
            <div class="mb-3">
                {{ form.notes.label(class="form-label") }}
                {{ form.notes(class="form-control", rows=3) }}
            </div>
            <div class="mb-3">
                <div class="form-check">
                    {{ form.is_active(class="form-check-input") }}
                    {{ form.is_active.label(class="form-check-label") }}
                </div>
            </div>
            <div class="d-flex gap-2">
                {{ form.submit(class="btn btn-primary") }}
                <a href="{{ url_for('hub_admin.qwk_nodes') }}" class="btn btn-secondary">Cancel</a>
            </div>
        </form>
    </div>
</div>

{% if node %}
<div class="card mt-4 border-danger" style="max-width:560px;">
    <div class="card-header text-danger">Danger Zone</div>
    <div class="card-body">
        <p>Deleting this node removes all subscription and high-water mark data.</p>
        <form method="POST" action="{{ url_for('hub_admin.delete_qwk_node', node_id=node.id) }}"
              onsubmit="return confirm('Delete QWK node {{ node.packet_id }}?');">
            {{ form.hidden_tag() }}
            <button type="submit" class="btn btn-danger btn-sm">Delete Node</button>
        </form>
    </div>
</div>
{% endif %}
{% endblock %}
