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

#pragma once

namespace dragonx {
namespace util {

// Default "taking longer than expected" threshold (seconds) for the daemon connect loop,
// overridable via ui.toml [screens.loading].stall-timeout-sec. Kept as a free function with
// no ImGui/App dependency so it is directly unit-testable from tests/test_phase4.cpp.
constexpr float kConnectStallDefaultSeconds = 45.0f;

// True once a daemon that is reachable-but-not-ready has stayed that way past the threshold.
//   stallSince : timestamp (same clock as `now`) when the stall began; <= 0 means "not stalling".
//   now        : current time in the same units as stallSince.
//   thresholdSec: how long to wait before considering it stalled; <= 0 disables the feature.
inline bool connectHasStalled(double stallSince, double now, float thresholdSec)
{
    if (stallSince <= 0.0) return false;        // not currently in a stall-tracked state
    if (thresholdSec <= 0.0f) return false;     // 0/negative disables the notice defensively
    return (now - stallSince) >= static_cast<double>(thresholdSec);
}

} // namespace util
} // namespace dragonx
