#include "text.h"
#include <iostream>
#include <vector>

void show_histogram_text(const std::vector<size_t>& bins) {
    const size_t SCREEN_WIDTH = 80;
    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
    size_t max_bin = 0;
    for (size_t bin : bins) {
        if (bin > max_bin) {
            max_bin = bin;
        }

    for (size_t bin_value : bins) {
        if (bin_value < 100) std::cout << " ";
        if (bin_value < 10) std::cout << " ";
        std::cout << bin_value << " |";
        size_t height = bin_value;
        if (max_bin > MAX_ASTERISK) {
            height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin_value) / max_bin));
        }
        for (size_t i = 0; i < height; ++i) {
            std::cout << "*";
        }
        std::cout << "\n";
    }
};
