#pragma once

#include <iostream>
#include <string>

namespace Logger {

    // Colores ANSI
    inline constexpr const char* RESET = "\033[0m";
    inline constexpr const char* RED = "\033[31m";
    inline constexpr const char* GREEN = "\033[32m";
    inline constexpr const char* YELLOW = "\033[33m";
    inline constexpr const char* BLUE = "\033[34m";
    inline constexpr const char* MAGENTA = "\033[35m";
    inline constexpr const char* CYAN = "\033[36m";
    inline constexpr const char* WHITE = "\033[37m";

    // Ancho total global para alineación
    inline constexpr size_t TOTAL_WIDTH = 52;

    // Sección
    inline void section(const std::string& title, const std::string& color = CYAN) {
        std::cout << "\n"
                  << color
                  << "========================================\n"
                  << "   " << title << "\n"
                  << "========================================"
                  << RESET << "\n";
    }

    // Info
    inline void info(const std::string& msg, const std::string& color = WHITE) {
        std::cout << "   " << color << msg << RESET << "\n";
    }

    // Put
    inline void put(const std::string& msg, const std::string& color = WHITE) {
        std::cout << color << msg << RESET << "\n";
    }

    // Error
    inline void error(const std::string& msg) {
        std::cout << RED << msg << RESET << "\n";
    }

    // CR
    inline void cr() {
        std::cout << "\n";
    }

    // Dots genérico
    inline void dots(const std::string& prefix,
        const std::string& middle,
        const std::string& suffix,
        const std::string& suffix_color = GREEN) {
        size_t field_width = TOTAL_WIDTH > (prefix.size() + suffix.size())
            ? TOTAL_WIDTH - prefix.size() - suffix.size()
            : 0;

        std::string field_text;
        if (middle.size() < field_width) {
            field_text = middle + std::string(field_width - middle.size(), '.');
        } else {
            field_text = middle.substr(0, field_width);
        }

        std::cout << "   " << prefix << field_text
                  << suffix_color << suffix << RESET
                  << "\n";
    }

    // Status con true/false, usando dots y sufijos fijos
    inline void status(const std::string& name, bool ok) {
        // Ambos sufijos tienen 9 caracteres → alineación perfecta
        constexpr const char* OK_LABEL = "[  OK   ]";
        constexpr const char* ERROR_LABEL = "[ ERROR ]";

        if (ok) {
            dots("   ", name, OK_LABEL, GREEN);
        } else {
            dots("   ", name, ERROR_LABEL, RED);
        }
    }

}  // namespace Logger
