<form method="post" action="/settings/save-notification-account" class="mb-3" data-busy>
    <div class="mb-3">
        <label for="notification_account_phone" class="form-label">Аккаунт для уведомлений</label>
        <select id="notification_account_phone" name="notification_account_phone" class="form-select w-auto">
            <option value="" {{ 'selected' if not notification_selected_phone else '' }}>Primary (default)</option>
            {% for acc in accounts %}
            <option value="{{ acc.phone }}" {{ 'selected' if notification_selected_phone == acc.phone else '' }}>
                {{ acc.phone }}{% if acc.is_primary %} [primary]{% endif %}{% if not acc.is_active %} [отключён]{% endif %}{% if acc.phone not in connected_phones %} [не подключён]{% endif %}
            </option>
            {% endfor %}
            {% if notification_selected_phone and notification_selected_phone not in account_phones %}
            <option value="{{ notification_selected_phone }}" selected>{{ notification_selected_phone }} [удалён]</option>
            {% endif %}
        </select>
        <div class="form-text">Если значение пустое, используется текущий primary-аккаунт. Автоматического fallback на другие аккаунты нет.</div>
    </div>
    <div class="d-flex justify-content-end">
        <button type="submit" class="btn btn-primary">Сохранить выбор</button>
    </div>
</form>

{% if notification_target.state == "available" %}
<p><span class="badge text-bg-success">Активно</span> {{ notification_target.message }}</p>
{% else %}
<p><span class="badge text-bg-warning">Недоступно</span> {{ notification_target.message }}</p>
{% endif %}

{% if notification_bot %}
<p>
    Notification bot: <code>@{{ notification_bot.bot_username }}</code>
    {% if notification_bot.bot_id %}(ID {{ notification_bot.bot_id }}){% endif %}
</p>
<div class="d-flex gap-2">
    <form method="post" action="/settings/notifications/delete" data-busy>
        <button type="submit" class="btn btn-outline-danger btn-sm"><i class="bi bi-trash me-1"></i>Удалить bot</button>
    </form>
    {% if notification_target.state == "available" %}
    <form method="post" action="/settings/notifications/test" data-busy>
        <button type="submit" class="btn btn-outline-secondary btn-sm"><i class="bi bi-send me-1"></i>Тест</button>
    </form>
    {% endif %}
</div>
{% elif notification_bot_error %}
<p><small class="text-muted">{{ notification_bot_error }}</small></p>
{% else %}
<p>Для выбранного аккаунта notification bot ещё не настроен.</p>
<form method="post" action="/settings/notifications/setup" data-busy>
    <button type="submit" class="btn btn-outline-primary btn-sm"><i class="bi bi-robot me-1"></i>Создать notification bot</button>
</form>
{% endif %}
