{% extends "base.html" %}
{% block title %}My Pages — {{ config.BBS_NAME }}{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1><i class="bi bi-globe2"></i> My Personal Pages</h1>
</div>

{% if not enabled %}
<div class="alert alert-warning">
    <strong>Personal pages aren't enabled on this BBS.</strong>
    The sysop can turn them on by setting
    <code>PERSONAL_PAGES_ENABLED=true</code> in the .env and restarting
    <code>anetbbs-web</code>. Until then, files you upload here are
    saved but not served.
</div>
{% else %}
<p class="small text-muted">
    Files you upload here are served at
    <code>{{ request.url_root }}~{{ username }}/</code>
    (and individual files at <code>{{ request.url_root }}~{{ username }}/&lt;filename&gt;</code>).
    Drop in an <code>index.html</code> to make the root URL render.
</p>
{% endif %}

<form method="post" action="{{ url_for('personal_pages.upload') }}"
      enctype="multipart/form-data" class="card p-3 mb-3">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <div class="d-flex gap-2 align-items-center">
        <input type="file" name="file" required class="form-control">
        <button class="btn btn-primary"><i class="bi bi-upload"></i> Upload</button>
    </div>
</form>

<table class="table table-sm">
    <thead><tr><th>File</th><th>Size</th><th></th></tr></thead>
    <tbody>
    {% for f in files %}
    <tr>
        <td>
            <a href="/~{{ username }}/{{ f.name }}" target="_blank">{{ f.name }}</a>
            {% if f.is_index %}<span class="badge bg-success ms-1">index</span>{% endif %}
        </td>
        <td><small>{{ '%.1f'|format(f.size / 1024) }} KB</small></td>
        <td>
            <form method="post" action="{{ url_for('personal_pages.delete', filename=f.name) }}" class="d-inline" onsubmit="return confirm('Delete {{ f.name }}?');">
                <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>
    {% else %}
    <tr><td colspan="3" class="text-muted">No files yet — upload an index.html to get started.</td></tr>
    {% endfor %}
    </tbody>
</table>

<div class="card mt-3">
    <div class="card-header">Tips</div>
    <div class="card-body small">
        <ul class="mb-0">
            <li>Index file lookup tries: {{ index_files|join(', ') }}</li>
            <li>Sysop can also drop folders directly in <code>data/personal_pages/&lt;dir&gt;/</code>
                — they'll be served at <code>/&lt;dir&gt;/</code> top-level.</li>
            <li>Upload your own HTML, CSS, JS, images — full static-site freedom.</li>
        </ul>
    </div>
</div>
{% endblock %}
