#pragma once

#include "../Module.h"
#include "../ModuleCategory.h"
#include "../../config/CheckboxValue.h"
#include "../../config/ColorpickerValue.h"
#include "../../config/CompactTextboxValue.h"
#include "../../config/FloatSliderValue.h"
#include "../../config/IntSliderValue.h"
#include "../../config/MenuSectionValue.h"
#include "../../config/SelectValue.h"

class MinimapModule;

inline MinimapModule* minimap_module_self = nullptr;

class MinimapModule : Module
{
public:
    MinimapModule() : Module("Minimap", Minimap, "minimap_mod")
    {
        minimap_module_self = this;
    }

    MenuSectionValue* section_general_ = conf(new MenuSectionValue("general_sec"));
    CheckboxValue* radar = conf(new CheckboxValue(false, "minimap_cb"));
    CheckboxValue* radar_exfils = conf(new CheckboxValue(false, "extracts_transits_cb"));
    CheckboxValue* radar_minimap_quest_esp = conf(new CheckboxValue(false, "quest_esp_map_cb"));
    CheckboxValue* radar_minimap_quest_names = conf(new CheckboxValue(false, "quest_names_map_cb"));
    CheckboxValue* radar_minimap_bots = conf(new CheckboxValue(false, "bot_markers_cb"));
    CheckboxValue* radar_minimap_bot_names = conf(new CheckboxValue(false, "bot_names_cb"));
    CheckboxValue* radar_minimap_bot_corpses = conf(new CheckboxValue(false, "bot_corpse_markers_cb"));
    ColorpickerValue* radar_minimap_bot_corpse_color = conf(new ColorpickerValue(
        {0.55f, 0.55f, 0.55f, 1.f}, "bot_corpse_color_clr"));

    MenuSectionValue* section_map_ = conf(new MenuSectionValue("map_display_sec"));
    CheckboxValue* radar_minimap = conf(new CheckboxValue(false, "map_background_cb"));
    SelectValue* radar_minimap_style = conf(new SelectValue(0, {"abstract_sel", "satellite_sel"}, "map_style_sel"));
    CheckboxValue* radar_minimap_rotate = conf(new CheckboxValue(false, "rotate_cb"));
    CheckboxValue* radar_minimap_grid = conf(new CheckboxValue(false, "map_grid_cb"));
    FloatSliderValue* radar_minimap_grid_opacity = conf(new FloatSliderValue(100.f, 0.f, 100.f, "map_grid_opacity_itm"));
    CheckboxValue* radar_minimap_compass = conf(new CheckboxValue(false, "compass_frame_cb"));
    CheckboxValue* radar_minimap_backdrop = conf(new CheckboxValue(false, "map_backdrop_cb"));
    ColorpickerValue* radar_minimap_backdrop_color = conf(new ColorpickerValue(
        {8.f / 255.f, 12.f / 255.f, 14.f / 255.f, 120.f / 255.f}, "map_backdrop_color_clr"));
    FloatSliderValue* radar_minimap_opacity = conf(new FloatSliderValue(100.f, 0.f, 100.f, "opacity_itm"));

    MenuSectionValue* section_layout_ = conf(new MenuSectionValue("layout_sec"));
    SelectValue* radar_minimap_corner = conf(new SelectValue(0, {
        "bottom_right_sel", "top_right_sel"}, "position_sel"));
    FloatSliderValue* radar_size = conf(new FloatSliderValue(250.f, 100.f, 400.f, "size_itm"));
    FloatSliderValue* radar_range = conf(new FloatSliderValue(400.f, 5.f, 2000.f, "range_itm"));
    FloatSliderValue* radar_margin_x = conf(new FloatSliderValue(50.f, 0.f, 300.f, "margin_x_itm"));
    FloatSliderValue* radar_margin_y = conf(new FloatSliderValue(50.f, 0.f, 300.f, "margin_y_itm"));

    MenuSectionValue* section_text_ = conf(new MenuSectionValue("marker_text_sec"));
    IntSliderValue* minimap_text_font_size = conf(new IntSliderValue(9, 8, 36, "minimap_text_size_itm"));
    CheckboxValue* minimap_marker_outline = conf(new CheckboxValue(false, "marker_map_outline_cb"));

    MenuSectionValue* section_symbols_ = conf(new MenuSectionValue("marker_symbols_sec"));
    CompactTextboxValue* minimap_sym_player = conf(new CompactTextboxValue("\xE2\x88\x86", "player_symbol_txt", 3));
    IntSliderValue* minimap_sym_player_size = conf(new IntSliderValue(10, 6, 36, "player_symbol_size_itm"));
    CompactTextboxValue* minimap_sym_entity = conf(new CompactTextboxValue("\xE2\x96\xA0", "entity_symbol_txt", 3));
    IntSliderValue* minimap_sym_entity_size = conf(new IntSliderValue(7, 6, 36, "entity_symbol_size_itm"));
    CompactTextboxValue* minimap_sym_quest = conf(new CompactTextboxValue("\xC3\x97", "quest_symbol_txt", 3));
    IntSliderValue* minimap_sym_quest_size = conf(new IntSliderValue(13, 6, 36, "quest_symbol_size_itm"));
    CompactTextboxValue* minimap_sym_exfil = conf(new CompactTextboxValue("\xE2\x97\x89", "exfil_symbol_txt", 3));
    IntSliderValue* minimap_sym_exfil_size = conf(new IntSliderValue(10, 6, 36, "exfil_symbol_size_itm"));
    CompactTextboxValue* minimap_sym_transit = conf(new CompactTextboxValue("\xE2\x97\x88", "transit_symbol_txt", 3));
    IntSliderValue* minimap_sym_transit_size = conf(new IntSliderValue(10, 6, 36, "transit_symbol_size_itm"));
    CompactTextboxValue* minimap_sym_height_up = conf(new CompactTextboxValue("\xE2\x96\xB2", "height_up_symbol_txt", 3));
    IntSliderValue* minimap_sym_height_up_size = conf(new IntSliderValue(7, 6, 36, "height_up_symbol_size_itm"));
    CompactTextboxValue* minimap_sym_height_down = conf(new CompactTextboxValue("\xE2\x96\xBC", "height_down_symbol_txt", 3));
    IntSliderValue* minimap_sym_height_down_size = conf(new IntSliderValue(7, 6, 36, "height_down_symbol_size_itm"));

    void init() override
    {
        radar->set_master_toggle(true);
    }

    void prepare_menu_draw() override
    {
        const auto dis = [](ConfigValue* v, const bool disabled) { v->set_disabled(disabled); };
        const bool radar_on = radar->get_value();

        section_general_->set_section_active(radar_on);
        dis(radar_exfils, !radar_on);
        dis(radar_minimap_quest_esp, !radar_on);
        dis(radar_minimap_quest_names, !radar_on || !radar_minimap_quest_esp->get_value());
        dis(radar_minimap_bots, !radar_on);
        dis(radar_minimap_bot_names, !radar_on || !radar_minimap_bots->get_value());
        dis(radar_minimap_bot_corpses, !radar_on);
        dis(radar_minimap_bot_corpse_color, !radar_on || !radar_minimap_bot_corpses->get_value());

        section_map_->set_section_active(radar_on);
        dis(radar_minimap, !radar_on);
        dis(radar_minimap_style, !radar_on);
        dis(radar_minimap_rotate, !radar_on);
        dis(radar_minimap_grid, !radar_on);
        dis(radar_minimap_grid_opacity, !radar_on || !radar_minimap_grid->get_value());
        dis(radar_minimap_compass, !radar_on);
        dis(radar_minimap_backdrop, !radar_on);
        dis(radar_minimap_backdrop_color, !radar_on || !radar_minimap_backdrop->get_value());
        dis(radar_minimap_opacity, !radar_on);

        section_layout_->set_section_active(radar_on);
        dis(radar_minimap_corner, !radar_on);
        dis(radar_size, !radar_on);
        dis(radar_range, !radar_on);
        dis(radar_margin_x, !radar_on);
        dis(radar_margin_y, !radar_on);

        section_text_->set_section_active(radar_on);
        dis(minimap_text_font_size, !radar_on);
        dis(minimap_marker_outline, !radar_on);

        section_symbols_->set_section_active(radar_on);
        dis(minimap_sym_player, !radar_on);
        dis(minimap_sym_player_size, !radar_on);
        dis(minimap_sym_entity, !radar_on);
        dis(minimap_sym_entity_size, !radar_on);
        dis(minimap_sym_quest, !radar_on);
        dis(minimap_sym_quest_size, !radar_on);
        dis(minimap_sym_exfil, !radar_on);
        dis(minimap_sym_exfil_size, !radar_on);
        dis(minimap_sym_transit, !radar_on);
        dis(minimap_sym_transit_size, !radar_on);
        dis(minimap_sym_height_up, !radar_on);
        dis(minimap_sym_height_up_size, !radar_on);
        dis(minimap_sym_height_down, !radar_on);
        dis(minimap_sym_height_down_size, !radar_on);
    }

    void draw_overlay(ImDrawList* /*draw_list*/) override
    {
    }

    void application_update() override
    {
    }

    void gameworld_update(const Il2CppClass* /*game_world_class*/, Il2CppObjectInstance /*game_world_instance*/,
                          Il2CppObjectInstance /*main_player*/) override
    {
    }
};