// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3

#include "console_scroll_controller.h"

namespace dragonx {
namespace ui {

void ConsoleScrollController::setAutoScroll(bool on)
{
    auto_scroll_ = on;
    if (on) new_lines_ = 0;  // re-pinning to the bottom clears the backlog counter
}

void ConsoleScrollController::onUserScrolledUp()
{
    auto_scroll_ = false;
    cooldown_    = kScrollUpCooldownSeconds;
}

void ConsoleScrollController::tickCooldown(float dt)
{
    if (cooldown_ > 0.0f) cooldown_ -= dt;
}

void ConsoleScrollController::considerReenable(bool atBottom)
{
    if (!auto_scroll_ && cooldown_ <= 0.0f && atBottom)
        pinToBottom();
}

void ConsoleScrollController::onLinesAdded(int n)
{
    if (!auto_scroll_ && n > 0) new_lines_ += n;
}

} // namespace ui
} // namespace dragonx
