#pragma once

#include "vertex_engine/utils/utils.hpp" // IWYU pragma: keep
#include "icons.hpp" // IWYU pragma: keep
#include "fonts.hpp"
#include "vertex_engine/utils/func.hpp"
#include "vertex_engine/gui/plots/2d/implot.hpp"

namespace VE::style
{
  inline void set_style()
  {
    const ImVec4 bg_mid                 = func::color("#303446", 0.99f);
    const ImVec4 accent_dark            = func::color("#272B38", 0.99f);
    const ImVec4 accent_light           = func::color("#3d4153", 0.99f);

    const ImVec4 active                 = func::color("#414553", 0.99f);
    const ImVec4 attention              = func::color("#14172B", 0.99f);

    ImVec4* col = ImGui::GetStyle().Colors;
    col[ImGuiCol_Tab]                   = func::color("#34384A", 0.99f);
    col[ImGuiCol_TabActive]             = accent_dark;
    col[ImGuiCol_TabHovered]            = accent_light;
    col[ImGuiCol_Tab]                   = func::color("#34384A", 0.19f);
    col[ImGuiCol_TabUnfocusedActive]    = active;

    col[ImGuiCol_TitleBg]               = accent_dark;
    col[ImGuiCol_TitleBgActive]         = accent_dark;
    col[ImGuiCol_TitleBgCollapsed]      = accent_dark;

    col[ImGuiCol_Text]                  = func::color("#E1E1E9", 0.99f);
    col[ImGuiCol_TextDisabled]          = func::color("#5E6E9D", 0.99f);
    col[ImGuiCol_TextSelectedBg]        = accent_light;

    col[ImGuiCol_Border]                = func::color("#303446", 0.99f);
    col[ImGuiCol_BorderShadow]          = func::color("#303446", 0.49f);

    col[ImGuiCol_FrameBg]               = func::color("#34384A", 0.90f);
    col[ImGuiCol_FrameBgActive]         = active;
    col[ImGuiCol_FrameBgHovered]        = accent_light;

    col[ImGuiCol_ScrollbarBg]           = bg_mid;
    col[ImGuiCol_ScrollbarGrab]         = func::color("#606373", 0.99f);
    col[ImGuiCol_ScrollbarGrabActive]   = active;
    col[ImGuiCol_ScrollbarGrabHovered]  = accent_light;

    col[ImGuiCol_SliderGrab]            = accent_dark;
    col[ImGuiCol_SliderGrabActive]      = accent_light;

    col[ImGuiCol_Button]                = accent_dark;
    col[ImGuiCol_ButtonHovered]         = accent_light;
    col[ImGuiCol_ButtonActive]          = active;

    col[ImGuiCol_Header]                = accent_dark;
    col[ImGuiCol_HeaderActive]          = active;
    col[ImGuiCol_HeaderHovered]         = accent_light;

    col[ImGuiCol_Separator]             = accent_dark;
    col[ImGuiCol_SeparatorActive]       = active;
    col[ImGuiCol_SeparatorHovered]      = accent_light;

    col[ImGuiCol_ResizeGrip]            = accent_dark;
    col[ImGuiCol_ResizeGripActive]      = active;
    col[ImGuiCol_ResizeGripHovered]     = accent_light;

    col[ImGuiCol_PlotLines]             = accent_light;
    col[ImGuiCol_PlotHistogram]         = accent_light;
    col[ImGuiCol_PlotLinesHovered]      = active;
    col[ImGuiCol_PlotHistogramHovered]  = active;

    col[ImGuiCol_TableRowBg]            = func::color("#303445", 0.99f);
    col[ImGuiCol_TableHeaderBg]         = accent_dark;
    col[ImGuiCol_TableRowBgAlt]         = func::color("#343849", 0.99f);
    col[ImGuiCol_TableBorderLight]      = func::color("#343849", 0.91f);
    col[ImGuiCol_TableBorderStrong]     = func::color("#343849", 0.91f);

    col[ImGuiCol_NavHighlight]          = func::color("#343849", 0.70f);
    col[ImGuiCol_NavWindowingDimBg]     = func::color("#343849", 0.20f);
    col[ImGuiCol_NavWindowingHighlight] = func::color("#343849", 0.70f);
    // col[ImGuiCol_NavHighlight]          = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
    // col[ImGuiCol_NavWindowingDimBg]     = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
    // col[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);

    col[ImGuiCol_ChildBg]               = func::color("#303446", 0.f);
    col[ImGuiCol_PopupBg]               = bg_mid;
    col[ImGuiCol_WindowBg]              = bg_mid;
    col[ImGuiCol_MenuBarBg]             = accent_dark;
    col[ImGuiCol_ModalWindowDimBg]      = func::color("#303446", 0.5f);

    col[ImGuiCol_CheckMark]             = accent_dark;
    col[ImGuiCol_DragDropTarget]        = attention;

#ifdef IMGUI_HAS_DOCK
  colors[ImGuiCol_DockingPreview] = ImVec4(0.85f, 0.85f, 0.85f, 0.28f);
  colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
#endif

    ImPlot::StyleColorsAuto();

    ImVec4* pcol = ImPlot::GetStyle().Colors;
    pcol[ImPlotCol_PlotBg] = ImVec4(0, 0, 0, 0);
    pcol[ImPlotCol_PlotBorder] = ImVec4(0, 0, 0, 0);
    pcol[ImPlotCol_Selection] = attention;
    pcol[ImPlotCol_Crosshairs] = col[ImGuiCol_Text];

    ImPlot::GetStyle().DigitalPadding = 20;

    auto& st = ImPlot::GetStyle();
    st.PlotPadding = st.LegendPadding = {12, 12};
    st.LabelPadding = st.LegendInnerPadding = {6, 6};
    st.LegendSpacing = {10, 2};
    st.AnnotationPadding = {4,2};

    const ImU32 Dracula[]  = {4288967266, 4285315327, 4286315088, 4283782655, 4294546365, 4287429361, 4291197439, 4294830475, 4294113528, 4284106564                        };
    ImPlot::GetStyle().Colormap = ImPlot::AddColormap("Dracula",Dracula,10);
  }

  inline void init()
  {
    /* use this - https://www.unknowncheats.me/forum/c-and-c-/189635-imgui-style-settings.html */
    ImGuiStyle& st = ImGui::GetStyle();

    st.WindowRounding                   = st.ChildRounding = st.PopupRounding = st.ScrollbarRounding = st.GrabRounding = st.TabRounding = 1.f;
    st.WindowBorderSize                 = st.ChildBorderSize = st.PopupBorderSize = st.TabBorderSize = 0.f;
    st.WindowMenuButtonPosition         = ImGuiDir_None;
    st.WindowPadding                    = ImVec2(5.f, 5.f);

    st.FramePadding                     = ImVec2{ 6.f, 3.f };
    st.FramePadding                     = ImVec2(5.f, 5.f);
    st.FrameBorderSize                  = 1;
    st.FrameRounding                    = 0.f;

    st.ItemSpacing                      = ImVec2(8.f, 8.f);
    st.ItemInnerSpacing                 = ImVec2(8.f, 6.f);

    st.ScrollbarSize                    = 12.f;
    st.ScrollbarRounding                = 0.f;

    st.GrabMinSize                      = 5.f;
    st.GrabRounding                     = 0.f;

    st.PopupRounding                    = 0.f;
    st.PopupBorderSize                  = 0.f;

    st.IndentSpacing                    = 25.f;
    st.TabRounding                      = 0.f;
    st.ChildRounding                    = 0.f;
    st.CellPadding                      = ImVec2{ 6.f, 3.f };

    set_style();
    fonts::init();
  };
};
