// ModalButtonHelper.h
#pragma once
#include "../../lib/input_manager.h"
#include "../../display/low_level_render.h"

class ModalButtonHelper {
public:
    /**
     * @brief Sets the standard Monopoly virtual button regions
     */
    static void set_monopoly_regions(InputManager* input_manager, uint16_t width, uint16_t height) {
        if (!input_manager) return;
        
        if (width < 480) {
            // Sidebar mode for 480x320 screen (Buttons at 400-480)
            int sidebar_x = width;
            int sidebar_w = 480 - width;
            int btn_h = height / 2;
            input_manager->set_virtual_button_regions(
                sidebar_x, 0, sidebar_w, btn_h,       // Button A (Top half)
                sidebar_x, btn_h, sidebar_w, btn_h    // Button B (Bottom half)
            );
        } else {
            // Inner dashboard mode (fallback)
            int btn_w = 60;
            int btn_h = 60;
            int margin_right = 135; // Positioned for the inner board area (W - 135 = 345)
            int start_y = 80;       // Vertical start position
            int spacing = 30;       // Gap between buttons
            
            int btn_x = width - margin_right;
            int btn_a_y = start_y;
            int btn_b_y = btn_a_y + btn_h + spacing;

            input_manager->set_virtual_button_regions(
                btn_x, btn_a_y, btn_w, btn_h,
                btn_x, btn_b_y, btn_w, btn_h
            );
        }
    }

    /**
     * @brief Draws virtual A and B buttons at consistent screen locations
     */
    static void draw_virtual_buttons(LowLevelRenderer* renderer, InputManager* input_manager) {
        if (!renderer || !input_manager) return;

        int a[4], b[4];
        input_manager->get_virtual_button_regions(a, b);

        // Save current color
        bool original_color = renderer->get_current_text_color();

        // Draw Button A
        renderer->draw_filled_rectangle(a[0], a[1], a[2], a[3], false, 0); // White back
        renderer->draw_rectangle(a[0], a[1], a[2], a[3], true, 2); // Black border
        renderer->set_text_color(true);
        // Use larger font scaling if buttons are big (sidebar mode)
        int scale_a = (a[3] > 100) ? 4 : 2;
        renderer->draw_string_scaled(a[0] + (a[2] - 6 * scale_a) / 2, a[1] + (a[3] - 8 * scale_a) / 2, "A", scale_a);

        // Draw Button B
        renderer->draw_filled_rectangle(b[0], b[1], b[2], b[3], false, 0); // White back
        renderer->draw_rectangle(b[0], b[1], b[2], b[3], true, 2); // Black border
        renderer->set_text_color(true);
        int scale_b = (b[3] > 100) ? 4 : 2;
        renderer->draw_string_scaled(b[0] + (b[2] - 6 * scale_b) / 2, b[1] + (b[3] - 8 * scale_b) / 2, "B", scale_b);

        // Restore color
        renderer->set_text_color(original_color);
    }
};
