#pragma once

#include <array>

#include "imgui.h"
#include "imgui_impl_win32.h"
#include "imgui_impl_dx11.h"
#include "imgui_impl_dx12.h"

namespace menu
{
    float get_width();
    float get_height();
    float get_scale_factor();
    float get_hud_font_size();
    ImFont* get_hud_font();
    bool is_active();
    void setup();
    void draw();

    constexpr std::array<const char*, 165> KeyNames = {
        "Unknown",
        "LBUTTON",
        "RBUTTON",
        "CANCEL",
        "MBUTTON",
        "XBUTTON1",
        "XBUTTON2",
        "Unknown",
        "BACK",
        "TAB",
        "Unknown",
        "Unknown",
        "CLEAR",
        "RETURN",
        "Unknown",
        "Unknown",
        "SHIFT",
        "CONTROL",
        "MENU",
        "PAUSE",
        "CAPITAL",
        "KANA",
        "Unknown",
        "JUNJA",
        "FINAL",
        "KANJI",
        "Unknown",
        "ESCAPE",
        "CONVERT",
        "NONCONVERT",
        "ACCEPT",
        "MODECHANGE",
        "SPACE",
        "PRIOR",
        "NEXT",
        "END",
        "HOME",
        "LEFT",
        "UP",
        "RIGHT",
        "DOWN",
        "SELECT",
        "PRINT",
        "EXECUTE",
        "SNAPSHOT",
        "INSERT",
        "DELETE",
        "HELP",
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "LWIN",
        "RWIN",
        "APPS",
        "Unknown",
        "SLEEP",
        "NUMPAD0",
        "NUMPAD1",
        "NUMPAD2",
        "NUMPAD3",
        "NUMPAD4",
        "NUMPAD5",
        "NUMPAD6",
        "NUMPAD7",
        "NUMPAD8",
        "NUMPAD9",
        "MULTIPLY",
        "ADD",
        "SEPARATOR",
        "SUBTRACT",
        "DECIMAL",
        "DIVIDE",
        "F1",
        "F2",
        "F3",
        "F4",
        "F5",
        "F6",
        "F7",
        "F8",
        "F9",
        "F10",
        "F11",
        "F12",
        "F13",
        "F14",
        "F15",
        "F16",
        "F17",
        "F18",
        "F19",
        "F20",
        "F21",
        "F22",
        "F23",
        "F24",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "NUMLOCK",
        "SCROLL",
        "OEM_NEC_EQUAL",
        "OEM_FJ_MASSHOU",
        "OEM_FJ_TOUROKU",
        "OEM_FJ_LOYA",
        "OEM_FJ_ROYA",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "Unknown",
        "LSHIFT",
        "RSHIFT",
        "LCONTROL",
        "RCONTROL",
        "LMENU",
        "RMENU"
    };

    inline void theme()
    {
        ImGuiStyle& style = ImGui::GetStyle();

        // --- Spacing & rounding ---
        style.Alpha = 1.0f;
        style.DisabledAlpha = 0.5f;
        style.WindowPadding = ImVec2(10.0f, 10.0f);
        style.WindowRounding = 0.0f;
        style.WindowBorderSize = 1.0f;
        style.WindowMinSize = ImVec2(32.0f, 32.0f);
        style.WindowTitleAlign = ImVec2(0.5f, 0.5f);
        style.WindowMenuButtonPosition = ImGuiDir_Left;
        style.ChildRounding = 6.0f;
        style.ChildBorderSize = 0.0f;
        style.PopupRounding = 8.0f;
        style.PopupBorderSize = 0.0f;
        style.FramePadding = ImVec2(6.0f, 4.0f);
        style.FrameRounding = 4.0f;
        style.FrameBorderSize = 1.0f;
        style.ItemSpacing = ImVec2(8.0f, 5.0f);
        style.ItemInnerSpacing = ImVec2(5.0f, 5.0f);
        style.CellPadding = ImVec2(5.0f, 3.0f);
        style.IndentSpacing = 16.0f;
        style.ColumnsMinSpacing = 6.0f;
        style.ScrollbarSize = 10.0f;
        style.ScrollbarRounding = 5.0f;
        style.GrabMinSize = 10.0f;
        style.GrabRounding = 4.0f;
        style.TabRounding = 6.0f;
        style.TabBorderSize = 0.0f;
        style.TabCloseButtonMinWidthSelected = 0.0f;
        style.TabCloseButtonMinWidthUnselected = 0.0f;
        style.ColorButtonPosition = ImGuiDir_Right;
        style.ButtonTextAlign = ImVec2(0.5f, 0.5f);
        style.SelectableTextAlign = ImVec2(0.0f, 0.0f);

        constexpr ImVec4 accent       = ImVec4(0.15f, 0.85f, 0.15f, 1.00f);
        constexpr ImVec4 accentHover  = ImVec4(0.22f, 0.95f, 0.22f, 1.00f);
        constexpr ImVec4 accentActive = ImVec4(0.08f, 0.70f, 0.08f, 1.00f);

        style.Colors[ImGuiCol_Text]                  = ImVec4(0.95f, 0.95f, 0.95f, 1.00f);
        style.Colors[ImGuiCol_TextDisabled]          = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
        style.Colors[ImGuiCol_WindowBg]              = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
        style.Colors[ImGuiCol_ChildBg]               = ImVec4(0.03f, 0.03f, 0.03f, 1.00f);
        style.Colors[ImGuiCol_PopupBg]               = ImVec4(0.04f, 0.04f, 0.04f, 0.96f);
        style.Colors[ImGuiCol_Border]                = ImVec4(accent.x, accent.y, accent.z, 0.55f);
        style.Colors[ImGuiCol_BorderShadow]          = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
        style.Colors[ImGuiCol_FrameBg]               = ImVec4(0.04f, 0.10f, 0.04f, 0.80f);
        style.Colors[ImGuiCol_FrameBgHovered]        = ImVec4(0.06f, 0.16f, 0.06f, 0.90f);
        style.Colors[ImGuiCol_FrameBgActive]         = ImVec4(0.07f, 0.20f, 0.07f, 1.00f);
        style.Colors[ImGuiCol_TitleBg]               = ImVec4(0.01f, 0.05f, 0.01f, 1.00f);
        style.Colors[ImGuiCol_TitleBgActive]         = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
        style.Colors[ImGuiCol_TitleBgCollapsed]      = ImVec4(0.03f, 0.03f, 0.03f, 1.00f);
        style.Colors[ImGuiCol_MenuBarBg]             = ImVec4(0.02f, 0.06f, 0.02f, 1.00f);
        style.Colors[ImGuiCol_ScrollbarBg]           = ImVec4(0.02f, 0.02f, 0.02f, 0.60f);
        style.Colors[ImGuiCol_ScrollbarGrab]         = accent;
        style.Colors[ImGuiCol_ScrollbarGrabHovered]  = accentHover;
        style.Colors[ImGuiCol_ScrollbarGrabActive]   = accentActive;
        style.Colors[ImGuiCol_CheckMark]             = accent;
        style.Colors[ImGuiCol_SliderGrab]            = accent;
        style.Colors[ImGuiCol_SliderGrabActive]      = accentHover;
        style.Colors[ImGuiCol_Button]                = ImVec4(0.04f, 0.10f, 0.04f, 0.80f);
        style.Colors[ImGuiCol_ButtonHovered]         = accent;
        style.Colors[ImGuiCol_ButtonActive]          = accentActive;
        style.Colors[ImGuiCol_Header]                = ImVec4(0.04f, 0.10f, 0.04f, 0.80f);
        style.Colors[ImGuiCol_HeaderHovered]         = accent;
        style.Colors[ImGuiCol_HeaderActive]          = accentActive;
        style.Colors[ImGuiCol_Separator]             = ImVec4(0.06f, 0.15f, 0.06f, 0.60f);
        style.Colors[ImGuiCol_SeparatorHovered]      = accent;
        style.Colors[ImGuiCol_SeparatorActive]       = accentHover;
        style.Colors[ImGuiCol_ResizeGrip]            = ImVec4(accent.x, accent.y, accent.z, 0.25f);
        style.Colors[ImGuiCol_ResizeGripHovered]     = ImVec4(accent.x, accent.y, accent.z, 0.45f);
        style.Colors[ImGuiCol_ResizeGripActive]      = ImVec4(accent.x, accent.y, accent.z, 0.65f);
        style.Colors[ImGuiCol_Tab]                   = ImVec4(0.02f, 0.08f, 0.02f, 1.00f);
        style.Colors[ImGuiCol_TabHovered]            = accent;
        style.Colors[ImGuiCol_TabActive]             = accent;
        style.Colors[ImGuiCol_TabUnfocused]          = ImVec4(0.02f, 0.06f, 0.02f, 1.00f);
        style.Colors[ImGuiCol_TabUnfocusedActive]    = ImVec4(0.04f, 0.10f, 0.04f, 1.00f);
        style.Colors[ImGuiCol_PlotLines]             = accent;
        style.Colors[ImGuiCol_PlotLinesHovered]      = accentHover;
        style.Colors[ImGuiCol_PlotHistogram]         = accent;
        style.Colors[ImGuiCol_PlotHistogramHovered]  = accentHover;
        style.Colors[ImGuiCol_TableHeaderBg]         = ImVec4(0.02f, 0.08f, 0.02f, 1.00f);
        style.Colors[ImGuiCol_TableBorderStrong]     = ImVec4(accent.x, accent.y, accent.z, 0.55f);
        style.Colors[ImGuiCol_TableBorderLight]      = ImVec4(0.06f, 0.15f, 0.06f, 0.50f);
        style.Colors[ImGuiCol_TableRowBg]            = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
        style.Colors[ImGuiCol_TableRowBgAlt]         = ImVec4(1.00f, 1.00f, 1.00f, 0.02f);
        style.Colors[ImGuiCol_TextSelectedBg]        = ImVec4(accent.x, accent.y, accent.z, 0.45f);
        style.Colors[ImGuiCol_DragDropTarget]        = accent;
        style.Colors[ImGuiCol_NavHighlight]          = accent;
        style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
        style.Colors[ImGuiCol_NavWindowingDimBg]     = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
        style.Colors[ImGuiCol_ModalWindowDimBg]      = ImVec4(0.00f, 0.00f, 0.00f, 0.65f);
    }
}
