{% extends "base.html" %}
{% block title %}汽水账号管理 - AutoMusic{% endblock %}
{% block content %}
<div class="page-header">
    <h1>汽水账号管理</h1>
</div>

<div class="card-form">
    <h3>添加汽水账号</h3>
    <form method="post" action="{{ url_for('accounts.create') }}" class="form-inline">
        <input type="text" name="name" placeholder="账号名称 (如: account1)" required>
        <input type="text" name="notes" placeholder="备注 (可选)">
        <button type="submit" class="btn btn-primary">添加</button>
    </form>
</div>

{% if accounts %}
<table>
    <thead>
        <tr><th>ID</th><th>名称</th><th>状态</th><th>创建时间</th><th>最后使用</th><th>备注</th><th>操作</th></tr>
    </thead>
    <tbody>
        {% for a in accounts %}
        <tr>
            <td>{{ a.id }}</td>
            <td>{{ a.name }}</td>
            <td>
                {% if a.is_logged_in %}
                <span class="badge badge-completed">已登录</span>
                {% else %}
                <span class="badge badge-pending">未登录</span>
                {% endif %}
            </td>
            <td>{{ a.created_at[:16] }}</td>
            <td>{{ (a.last_used_at or '-')[:16] }}</td>
            <td>{{ a.notes or '-' }}</td>
            <td class="actions">
                <form method="post" action="{{ url_for('accounts.login', account_id=a.id) }}" class="inline">
                    <button type="submit" class="btn btn-sm">打开登录</button>
                </form>
                <form method="post" action="{{ url_for('accounts.confirm_login', account_id=a.id) }}" class="inline">
                    <button type="submit" class="btn btn-sm btn-success">确认已登录</button>
                </form>
                <form method="post" action="{{ url_for('accounts.delete', account_id=a.id) }}" class="inline"
                      onsubmit="return confirm('确定删除账号 {{ a.name }}? 将同时删除浏览器数据。')">
                    <button type="submit" class="btn btn-sm btn-danger">删除</button>
                </form>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<p class="empty">暂无汽水账号，请先添加。</p>
{% endif %}
{% endblock %}
