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

ServiceMenu::ServiceMenu() {
    // Inicializa los valores por defecto del menú de servicio
    is_active = false;
    selected_option = 0;
    options = {"Test de Sonido", "Test de Video", "Contadores", "Salir"};
}

void ServiceMenu::show() {
    is_active = true;
    while (is_active) {
        render();
        handle_input();
    }
}

void ServiceMenu::render() {
    std::cout << "=== MENÚ DE SERVICIO ===" << std::endl;
    for (size_t i = 0; i < options.size(); ++i) {
        if (i == selected_option)
            std::cout << "> ";
        else
            std::cout << "  ";
        std::cout << options[i] << std::endl;
    }
}

void ServiceMenu::handle_input() {
    char input;
    std::cin >> input;
    switch (input) {
        case 'w':
            if (selected_option > 0) selected_option--;
            break;
        case 's':
            if (selected_option < options.size() - 1) selected_option++;
            break;
        case '\n':
        case '\r':
        case 'e':
            execute_option(selected_option);
            break;
        case 'q':
            is_active = false;
            break;
        default:
            break;
    }
}

void ServiceMenu::execute_option(size_t option) {
    switch (option) {
        case 0:
            std::cout << "Ejecutando test de sonido..." << std::endl;
            break;
        case 1:
            std::cout << "Ejecutando test de video..." << std::endl;
            break;
        case 2:
            std::cout << "Mostrando contadores..." << std::endl;
            break;
        case 3:
            is_active = false;
            break;
        default:
            break;
    }
}