{% extends "base.html" %}

{% block title %}Bulk Import Nodelists{% endblock %}

{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-cloud-arrow-down"></i> Bulk Import Nodelists</h1>
    <p class="text-muted mb-0">Scan a directory for nodelist files / ZIP archives and import the ones you want. Inspired by Codefenix's NetLister for Synchronet.</p>
</div>

<form method="GET" class="mb-3">
    <div class="input-group">
        <span class="input-group-text">Scan directory</span>
        <input type="text" name="scan_dir" class="form-control" value="{{ scan_dir }}" placeholder="/path/to/nodelist/archive/dir">
        <button class="btn btn-outline-secondary">Scan</button>
    </div>
    <small class="text-muted">Defaults to <code>NODELIST_SCAN_DIR</code> from app config, or <code>data/nodelists</code>.</small>
</form>

{% if candidates %}
<form method="POST">
    <input type="hidden" name="scan_dir" value="{{ scan_dir }}">
    <input type="hidden" name="action" value="import">
    {% if csrf_token is defined %}<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">{% endif %}

    <div class="card">
        <div class="card-header">
            <i class="bi bi-files"></i> {{ candidates|length }} candidate file{{ '' if candidates|length == 1 else 's' }} in <code>{{ scan_dir }}</code>
        </div>
        <div class="card-body p-0">
            <table class="table table-sm table-hover mb-0">
                <thead>
                    <tr>
                        <th>File</th>
                        <th>Size</th>
                        <th style="width:30%;">Domain (leave blank to skip)</th>
                    </tr>
                </thead>
                <tbody>
                {% for c in candidates %}
                    <tr>
                        <td><code>{{ c.name }}</code></td>
                        <td><small>{{ '{:,}'.format(c.size) }} bytes</small></td>
                        <td>
                            <input type="text" name="domain__{{ c.name }}" class="form-control form-control-sm"
                                   placeholder="e.g. fidonet, tqwnet, fsxnet, sp00knet">
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="mt-3">
        <button class="btn btn-primary">Import selected</button>
        <a href="{{ url_for('nodelist.browse') }}" class="btn btn-outline-secondary">Cancel</a>
    </div>
</form>
{% elif scan_dir %}
<div class="alert alert-warning">
    No nodelist-shaped files found in <code>{{ scan_dir }}</code>. Try a different path, or upload one directly via
    <a href="{{ url_for('nodelist.admin_upload') }}">single upload</a>.
</div>
{% endif %}

{% endblock %}
