// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3
//
// Small shared text helpers used across the immediate-mode UI. Centralised here so the per-frame
// hot paths use one allocation-free implementation instead of several copies.

#pragma once

#include <cstdint>
#include <string>
#include <string_view>

namespace dragonx {
namespace util {

// App-wide clock format (24-hour vs 12-hour). Set once per frame by the App from the global
// `time_format` setting (setClock12h); the formatters below read it so a single preference drives
// every user-facing timestamp. The Chat tab resolves its own override separately.
void setClock12h(bool enabled);
bool clock12h();

// Format an epoch timestamp as a local wall-clock date+time honoring the app clock setting:
//   24h -> "YYYY-MM-DD HH:MM[:SS]",  12h -> "YYYY-MM-DD hh:MM[:SS] AM/PM". Empty when ts <= 0.
std::string formatClockDateTime(std::int64_t timestamp, bool withSeconds = false);

// Just the time-of-day portion honoring the clock setting: 24h "HH:MM[:SS]" / 12h "hh:MM[:SS] AM/PM".
std::string formatClockTime(std::int64_t timestamp, bool withSeconds = false);

// Localized relative time, e.g. "5 minutes ago" (via i18n). Empty when timestamp <= 0.
std::string formatTimeAgo(std::int64_t timestamp);

// Compact, non-localized relative time for tight UI: "5s ago" / "3m ago" / "2h ago" / "4d ago".
std::string formatTimeAgoShort(std::int64_t timestamp);

// Case-insensitive substring test that does NOT allocate (unlike lower-casing copies + find).
// An empty needle matches everything. Safe for per-frame filtering of large lists.
bool containsIgnoreCase(std::string_view haystack, std::string_view needle);

// Middle-ellipsis truncation, half/half form: "prefix...suffix" so the total (including "...")
// is at most maxLen. Guards maxLen <= 3 (returns s unchanged) to avoid unsigned underflow on the
// (maxLen - 3) split. Strings already at/under maxLen are returned unchanged.
std::string truncateMiddle(const std::string& s, int maxLen);

// Middle-ellipsis truncation with explicit prefix/suffix lengths: "<front chars>...<back chars>".
// Returns s unchanged when it is no longer than front + back + 3 (the "..." would not save space).
std::string truncateMiddle(const std::string& s, int front, int back);

} // namespace util
} // namespace dragonx
