#include "torlinkc/ui/move.hpp"

#include <algorithm>

namespace torlinkc::ui {

int wrapStep(int current, int delta, int length) {
  if (length <= 0) return 0;
  return ((current + delta) % length + length) % length;
}

int windowStart(int cursor, int total, int height) {
  if (total <= height) return 0;
  const int half = height / 2;
  return std::max(0, std::min(cursor - half, total - height));
}

}  // namespace torlinkc::ui
