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

using namespace std;

void
static printspace (int number)
{
    if (number < 10) cout << "  ";
    else if (number < 100) cout << " ";
}

void
show_histogram_text(const vector<size_t>& bins, size_t bin_count)
{
    size_t max_count = 0;
    for (int i = 0; i < bins.size(); i++)
    {
        if (bins[i] > max_count) max_count = bins[i];
    }
    if (max_count <= 76)
    {
        for (size_t i = 0; i < bin_count; i++)
        {
            printspace(bins[i]);
            cout << bins[i] << "|";
            for (size_t j = 0; j < bins[i]; j++)
            {
                cout << "*";
            }
            cout << endl;
        }
    }
    else
    {
        for (size_t i = 0; i < bin_count; i++)
            {
            size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
            printspace(bins[i]);
            cout << bins[i] << "|";
            for (size_t j = 0; j < height; j++)
            {
                cout << "*";
            }
            cout << endl;
            }
    }
}
