// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3

#include "color_theme.h"
#include "../schema/ui_schema.h"
#include <algorithm>
#include <cmath>

namespace dragonx {
namespace ui {
namespace material {

// ============================================================================
// Color Utility Implementations
// ============================================================================

ImU32 BlendOverlay(ImU32 base, ImU32 overlay, float overlayOpacity)
{
    // Extract components
    float baseR = ((base >> IM_COL32_R_SHIFT) & 0xFF) / 255.0f;
    float baseG = ((base >> IM_COL32_G_SHIFT) & 0xFF) / 255.0f;
    float baseB = ((base >> IM_COL32_B_SHIFT) & 0xFF) / 255.0f;
    float baseA = ((base >> IM_COL32_A_SHIFT) & 0xFF) / 255.0f;
    
    float overlayR = ((overlay >> IM_COL32_R_SHIFT) & 0xFF) / 255.0f;
    float overlayG = ((overlay >> IM_COL32_G_SHIFT) & 0xFF) / 255.0f;
    float overlayB = ((overlay >> IM_COL32_B_SHIFT) & 0xFF) / 255.0f;
    
    // Blend
    float resultR = baseR + (overlayR - baseR) * overlayOpacity;
    float resultG = baseG + (overlayG - baseG) * overlayOpacity;
    float resultB = baseB + (overlayB - baseB) * overlayOpacity;
    
    return IM_COL32(
        static_cast<uint8_t>(resultR * 255.0f),
        static_cast<uint8_t>(resultG * 255.0f),
        static_cast<uint8_t>(resultB * 255.0f),
        static_cast<uint8_t>(baseA * 255.0f)
    );
}

ImU32 Lighten(ImU32 color, float amount)
{
    return BlendOverlay(color, IM_COL32(255, 255, 255, 255), amount);
}

ImU32 Darken(ImU32 color, float amount)
{
    return BlendOverlay(color, IM_COL32(0, 0, 0, 255), amount);
}

// ============================================================================
// Elevation System
// ============================================================================

// Material Design elevation overlay values for dark theme
// These values lighten the surface to indicate elevation
static const float kElevationOverlays[] = {
    0.00f,  // 0dp
    0.05f,  // 1dp
    0.07f,  // 2dp
    0.08f,  // 3dp
    0.09f,  // 4dp
    0.10f,  // 5dp
    0.11f,  // 6dp
    0.115f, // 7dp
    0.12f,  // 8dp
    0.125f, // 9dp
    0.13f,  // 10dp
    0.135f, // 11dp
    0.14f,  // 12dp
    0.14f,  // 13dp
    0.14f,  // 14dp
    0.14f,  // 15dp
    0.15f,  // 16dp
    0.15f,  // 17dp
    0.15f,  // 18dp
    0.15f,  // 19dp
    0.15f,  // 20dp
    0.15f,  // 21dp
    0.15f,  // 22dp
    0.15f,  // 23dp
    0.16f   // 24dp
};

float GetElevationOverlay(Elevation level)
{
    return GetElevationOverlay(static_cast<int>(level));
}

float GetElevationOverlay(int dp)
{
    if (dp < 0) return 0.0f;
    if (dp > 24) dp = 24;
    return kElevationOverlays[dp];
}

ImU32 GetElevatedSurface(const ColorTheme& theme, Elevation level)
{
    return GetElevatedSurface(theme, static_cast<int>(level));
}

ImU32 GetElevatedSurface(const ColorTheme& theme, int dp)
{
    float overlay = GetElevationOverlay(dp);
    if (overlay <= 0.0f) {
        return theme.surface;
    }
    return BlendOverlay(theme.surface, IM_COL32(255, 255, 255, 255), overlay);
}

// ============================================================================
// Theme State
// ============================================================================

static ColorTheme s_currentTheme;
static bool s_themeInitialized = false;
static bool s_isDarkTheme = true;
static bool s_backdropActive = false;

// ============================================================================
// DragonX Theme (Dark with Red Primary)
// ============================================================================

ColorTheme GetDragonXColorTheme()
{
    ColorTheme theme;
    
    // Primary: DragonX Red
    theme.primary           = Hex(0xF64740);  // Bright red accent
    theme.primaryVariant    = Hex(0x6F1A07);  // Dark maroon variant
    theme.primaryLight      = Hex(0xF87A75);  // Lighter red for highlights
    
    // Secondary: Blue-gray from text palette
    theme.secondary         = Hex(0xBFD1E5);  // Light blue-gray
    theme.secondaryVariant  = Hex(0x8BA3BD);  // Mid blue-gray
    theme.secondaryLight    = Hex(0xDAE5F0);  // Pale blue-gray
    
    // Surfaces (Dark navy palette)
    theme.background        = Hex(0x121420);  // Deep navy background
    theme.surface           = Hex(0x1B2432);  // Dark navy surface
    theme.surfaceVariant    = Hex(0x253345);  // Lighter navy variant
    
    // "On" colors — blue-gray text tones
    theme.onPrimary         = Hex(0xFFFFFF);  // White on red
    theme.onSecondary       = Hex(0x121420);  // Navy on blue-gray
    theme.onBackground      = Hex(0xE2EDF8);  // Bright blue-gray on dark
    theme.onSurface         = Hex(0xE2EDF8);  // Bright blue-gray on surface
    theme.onSurfaceMedium   = HexA(0xE2EDF8, 179);  // 70%
    theme.onSurfaceDisabled = HexA(0xE2EDF8, 97);   // 38%
    
    // Error
    theme.error             = Hex(0xF64740);  // Primary red
    theme.onError           = Hex(0xFFFFFF);  // White on error
    
    // Success/Warning (follow DragonX palette)
    theme.success           = Hex(0xBFD1E5);  // Blue-gray secondary
    theme.onSuccess         = Hex(0x121420);  // Dark on success
    theme.warning           = Hex(0xF64740);  // Primary red
    theme.onWarning         = Hex(0xFFFFFF);  // White on warning
    
    // State overlays (blue-gray tinted for dark navy theme)
    theme.stateHover        = HexA(0xBFD1E5, 10);   // 4%
    theme.stateFocus        = HexA(0xBFD1E5, 31);   // 12%
    theme.statePressed      = HexA(0xBFD1E5, 25);   // 10%
    theme.stateSelected     = HexA(0xBFD1E5, 20);   // 8%
    theme.stateDragged      = HexA(0xBFD1E5, 20);   // 8%
    
    // UI elements
    theme.divider           = HexA(0xBFD1E5, 31);   // 12% blue-gray
    theme.outline           = HexA(0xBFD1E5, 31);   // 12% blue-gray
    theme.scrim             = HexA(0x000000, 128);  // 50% black
    
    return theme;
}

// ============================================================================
// Material Dark Theme
// ============================================================================

ColorTheme GetMaterialDarkTheme()
{
    ColorTheme theme;
    
    // Primary: Deep Purple (Material baseline)
    theme.primary           = Hex(0xBB86FC);  // Purple 200
    theme.primaryVariant    = Hex(0x3700B3);  // Purple 700
    theme.primaryLight      = Hex(0xE1BEE7);  // Purple 100
    
    // Secondary: Teal
    theme.secondary         = Hex(0x03DAC6);  // Teal 200
    theme.secondaryVariant  = Hex(0x018786);  // Teal 700
    theme.secondaryLight    = Hex(0x64FFDA);  // Teal A200
    
    // Surfaces
    theme.background        = Hex(0x121212);
    theme.surface           = Hex(0x1E1E1E);
    theme.surfaceVariant    = Hex(0x2D2D2D);
    
    // "On" colors
    theme.onPrimary         = Hex(0x000000);
    theme.onSecondary       = Hex(0x000000);
    theme.onBackground      = Hex(0xFFFFFF);
    theme.onSurface         = Hex(0xFFFFFF);
    theme.onSurfaceMedium   = HexA(0xFFFFFF, 179);
    theme.onSurfaceDisabled = HexA(0xFFFFFF, 97);
    
    // Error
    theme.error             = Hex(0xF64740);
    theme.onError           = Hex(0xFFFFFF);
    
    // Success/Warning (follow DragonX palette)
    theme.success           = Hex(0xBFD1E5);
    theme.onSuccess         = Hex(0x121420);
    theme.warning           = Hex(0xF64740);
    theme.onWarning         = Hex(0xFFFFFF);
    
    // State overlays
    theme.stateHover        = HexA(0xFFFFFF, 10);
    theme.stateFocus        = HexA(0xFFFFFF, 31);
    theme.statePressed      = HexA(0xFFFFFF, 25);
    theme.stateSelected     = HexA(0xFFFFFF, 20);
    theme.stateDragged      = HexA(0xFFFFFF, 20);
    
    // UI elements
    theme.divider           = HexA(0xFFFFFF, 31);
    theme.outline           = HexA(0xFFFFFF, 31);
    theme.scrim             = HexA(0x000000, 128);
    
    return theme;
}

// ============================================================================
// Material Light Theme
// ============================================================================

ColorTheme GetMaterialLightTheme()
{
    ColorTheme theme;
    
    // Primary: Deep Purple
    theme.primary           = Hex(0x6200EE);  // Purple 500
    theme.primaryVariant    = Hex(0x3700B3);  // Purple 700
    theme.primaryLight      = Hex(0xBB86FC);  // Purple 200
    
    // Secondary: Teal
    theme.secondary         = Hex(0x03DAC6);  // Teal 200
    theme.secondaryVariant  = Hex(0x018786);  // Teal 700
    theme.secondaryLight    = Hex(0x64FFDA);
    
    // Surfaces (light)
    theme.background        = Hex(0xFFFFFF);
    theme.surface           = Hex(0xFFFFFF);
    theme.surfaceVariant    = Hex(0xF5F5F5);
    
    // "On" colors
    theme.onPrimary         = Hex(0xFFFFFF);
    theme.onSecondary       = Hex(0x000000);
    theme.onBackground      = Hex(0x000000);
    theme.onSurface         = Hex(0x000000);
    theme.onSurfaceMedium   = HexA(0x000000, 153);  // 60%
    theme.onSurfaceDisabled = HexA(0x000000, 97);   // 38%
    
    // Error
    theme.error             = Hex(0xF64740);
    theme.onError           = Hex(0xFFFFFF);
    
    // Success/Warning (follow DragonX palette)
    theme.success           = Hex(0xBFD1E5);  // Blue-gray
    theme.onSuccess         = Hex(0x121420);
    theme.warning           = Hex(0xF64740);  // Primary red
    theme.onWarning         = Hex(0xFFFFFF);
    
    // State overlays (black for light theme)
    theme.stateHover        = HexA(0x000000, 10);
    theme.stateFocus        = HexA(0x000000, 31);
    theme.statePressed      = HexA(0x000000, 25);
    theme.stateSelected     = HexA(0x000000, 20);
    theme.stateDragged      = HexA(0x000000, 20);
    
    // UI elements
    theme.divider           = HexA(0x000000, 31);
    theme.outline           = HexA(0x000000, 31);
    theme.scrim             = HexA(0x000000, 128);
    
    return theme;
}

// ============================================================================
// Theme Management
// ============================================================================

const ColorTheme& GetCurrentColorTheme()
{
    if (!s_themeInitialized) {
        s_currentTheme = GetDragonXColorTheme();
        s_themeInitialized = true;
        s_isDarkTheme = true;
    }
    return s_currentTheme;
}

void SetCurrentColorTheme(const ColorTheme& theme)
{
    s_currentTheme = theme;
    s_themeInitialized = true;
    
    // Detect if dark theme based on background luminance
    float bgR = ((theme.background >> IM_COL32_R_SHIFT) & 0xFF) / 255.0f;
    float bgG = ((theme.background >> IM_COL32_G_SHIFT) & 0xFF) / 255.0f;
    float bgB = ((theme.background >> IM_COL32_B_SHIFT) & 0xFF) / 255.0f;
    float luminance = 0.299f * bgR + 0.587f * bgG + 0.114f * bgB;
    s_isDarkTheme = (luminance < 0.5f);
}

bool IsDarkTheme()
{
    GetCurrentColorTheme();  // Ensure initialized
    return s_isDarkTheme;
}

void SetBackdropActive(bool active)
{
    s_backdropActive = active;
}

bool IsBackdropActive()
{
    return s_backdropActive;
}

// ============================================================================
// Apply Theme to ImGui
// ============================================================================

void ApplyColorThemeToImGui(const ColorTheme& theme)
{
    SetCurrentColorTheme(theme);
    
    ImGuiStyle& style = ImGui::GetStyle();
    ImVec4* colors = style.Colors;
    const auto& S = schema::UI();
    
    // Helper to convert ImU32 to ImVec4
    auto toVec4 = [](ImU32 col) -> ImVec4 {
        return ImGui::ColorConvertU32ToFloat4(col);
    };
    
    // Backdrop transparency: when DWM Acrylic is active, make backgrounds
    // semi-transparent so the blurred + noisy Acrylic material shows through.
    // A dark blue gradient is drawn on the background draw list (in app.cpp)
    // for a stylish tinted look while retaining blur + noise.
    auto bdElem = [&](const char* key, float fb) {
        float v = S.drawElement("backdrop", key).size;
        return v >= 0 ? v : fb;
    };
    const float bgAlpha = s_backdropActive ? bdElem("background-alpha", 0.40f) : 1.0f;
    // When acrylic is active, ChildBg must be fully transparent so the
    // sharp background doesn't bleed through behind acrylic cards.
    // DrawGlassPanel draws the blurred card fill directly.
    const float surfAlpha = s_backdropActive ? 0.0f : 1.0f;
    const float tabAlpha = s_backdropActive ? 0.75f : 1.0f;
    
    // Background colors
    colors[ImGuiCol_WindowBg]             = toVec4(WithAlphaF(theme.background, bgAlpha));
    colors[ImGuiCol_ChildBg]              = toVec4(WithAlphaF(GetElevatedSurface(theme, 1), surfAlpha));
    colors[ImGuiCol_PopupBg]              = toVec4(WithAlphaF(GetElevatedSurface(theme, 8), 0.95f));
    
    // Borders — dark themes use white outlines; light themes use dark outlines
    if (s_isDarkTheme) {
        colors[ImGuiCol_Border]               = ImVec4(1.0f, 1.0f, 1.0f, 0.15f);
        colors[ImGuiCol_BorderShadow]         = ImVec4(0, 0, 0, 0.08f);
    } else {
        colors[ImGuiCol_Border]               = ImVec4(0, 0, 0, 0.22f);
        colors[ImGuiCol_BorderShadow]         = ImVec4(0, 0, 0, 0.04f);
    }
    
    // Frame backgrounds (inputs, checkboxes) — glass-card in dark, subtle grey in light
    if (s_isDarkTheme) {
        colors[ImGuiCol_FrameBg]              = ImVec4(1.0f, 1.0f, 1.0f, 0.07f);
        colors[ImGuiCol_FrameBgHovered]       = ImVec4(1.0f, 1.0f, 1.0f, 0.10f);
        colors[ImGuiCol_FrameBgActive]        = ImVec4(1.0f, 1.0f, 1.0f, 0.15f);
    } else {
        // Light themes: the old 4/7/10% black fills were nearly invisible on a white surface (input
        // fields blended in). Darker fills + a 1px frame border (below) so inputs/dropdowns read as
        // defined boxes even on the pastel/gradient light skins (iridescent, color-pop-light).
        colors[ImGuiCol_FrameBg]              = ImVec4(0, 0, 0, 0.11f);
        colors[ImGuiCol_FrameBgHovered]       = ImVec4(0, 0, 0, 0.16f);
        colors[ImGuiCol_FrameBgActive]        = ImVec4(0, 0, 0, 0.20f);
    }
    
    // Title bar
    colors[ImGuiCol_TitleBg]              = toVec4(WithAlphaF(GetElevatedSurface(theme, 4), surfAlpha));
    colors[ImGuiCol_TitleBgActive]        = toVec4(theme.primary);
    colors[ImGuiCol_TitleBgCollapsed]     = toVec4(WithAlphaF(GetElevatedSurface(theme, 4), 0.75f));
    
    // Menu bar — fully transparent, no background
    colors[ImGuiCol_MenuBarBg]            = ImVec4(0, 0, 0, 0);
    
    // Scrollbar — minimal style (dark overlays for light, white overlays for dark)
    colors[ImGuiCol_ScrollbarBg]          = ImVec4(0, 0, 0, 0);
    if (s_isDarkTheme) {
        colors[ImGuiCol_ScrollbarGrab]        = ImVec4(1.0f, 1.0f, 1.0f, 15.0f / 255.0f);
        colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(1.0f, 1.0f, 1.0f, 30.0f / 255.0f);
        colors[ImGuiCol_ScrollbarGrabActive]  = ImVec4(1.0f, 1.0f, 1.0f, 45.0f / 255.0f);
    } else {
        colors[ImGuiCol_ScrollbarGrab]        = ImVec4(0, 0, 0, 0.10f);
        colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0, 0, 0, 0.18f);
        colors[ImGuiCol_ScrollbarGrabActive]  = ImVec4(0, 0, 0, 0.25f);
    }
    
    // Checkmarks, sliders
    colors[ImGuiCol_CheckMark]            = toVec4(theme.primary);
    colors[ImGuiCol_SliderGrab]           = toVec4(theme.primary);
    colors[ImGuiCol_SliderGrabActive]     = toVec4(theme.primaryLight);
    
    // Buttons — glass-style overlays (white on dark, dark on light)
    if (s_isDarkTheme) {
        colors[ImGuiCol_Button]           = ImVec4(1.0f, 1.0f, 1.0f, 15.0f / 255.0f);
        colors[ImGuiCol_ButtonHovered]    = ImVec4(1.0f, 1.0f, 1.0f, 30.0f / 255.0f);
        colors[ImGuiCol_ButtonActive]     = ImVec4(1.0f, 1.0f, 1.0f, 45.0f / 255.0f);
    } else {
        // Darker overlays on light themes — the old 5/8/12% were barely-there grey and washed out;
        // bumped again so the small/secondary buttons read as clearly as the main ones.
        colors[ImGuiCol_Button]           = ImVec4(0, 0, 0, 0.16f);
        colors[ImGuiCol_ButtonHovered]    = ImVec4(0, 0, 0, 0.23f);
        colors[ImGuiCol_ButtonActive]     = ImVec4(0, 0, 0, 0.30f);
    }
    
    // Headers (collapsing headers, tree nodes, selectable, menu items)
    colors[ImGuiCol_Header]               = toVec4(WithAlphaF(theme.primary, 0.6f));
    colors[ImGuiCol_HeaderHovered]        = toVec4(WithAlphaF(theme.primary, 0.8f));
    colors[ImGuiCol_HeaderActive]         = toVec4(theme.primary);
    
    // Separator
    colors[ImGuiCol_Separator]            = toVec4(theme.divider);
    colors[ImGuiCol_SeparatorHovered]     = toVec4(theme.primaryLight);
    colors[ImGuiCol_SeparatorActive]      = toVec4(theme.primary);
    
    // Resize grip
    colors[ImGuiCol_ResizeGrip]           = toVec4(WithAlphaF(theme.primary, 0.25f));
    colors[ImGuiCol_ResizeGripHovered]    = toVec4(WithAlphaF(theme.primary, 0.67f));
    colors[ImGuiCol_ResizeGripActive]     = toVec4(WithAlphaF(theme.primary, 0.95f));
    
    // Tabs
    ImU32 tabBg = GetElevatedSurface(theme, 4);
    colors[ImGuiCol_Tab]                  = toVec4(WithAlphaF(tabBg, tabAlpha));
    colors[ImGuiCol_TabHovered]           = toVec4(WithAlphaF(Lighten(theme.primary, 0.15f), tabAlpha));
    colors[ImGuiCol_TabSelected]          = toVec4(WithAlphaF(theme.primary, tabAlpha));
    colors[ImGuiCol_TabSelectedOverline]  = toVec4(theme.secondary);
    colors[ImGuiCol_TabDimmed]            = toVec4(WithAlphaF(Darken(tabBg, 0.2f), tabAlpha));
    colors[ImGuiCol_TabDimmedSelected]    = toVec4(WithAlphaF(theme.primary, tabAlpha * 0.7f));
    
    // Plot colors
    colors[ImGuiCol_PlotLines]            = toVec4(theme.primary);
    colors[ImGuiCol_PlotLinesHovered]     = toVec4(theme.secondary);
    colors[ImGuiCol_PlotHistogram]        = toVec4(theme.primary);
    colors[ImGuiCol_PlotHistogramHovered] = toVec4(theme.secondary);
    
    // Tables
    colors[ImGuiCol_TableHeaderBg]        = toVec4(WithAlphaF(GetElevatedSurface(theme, 2), surfAlpha));
    colors[ImGuiCol_TableBorderStrong]    = toVec4(theme.outline);
    colors[ImGuiCol_TableBorderLight]     = toVec4(theme.divider);
    colors[ImGuiCol_TableRowBg]           = ImVec4(0, 0, 0, 0);
    colors[ImGuiCol_TableRowBgAlt]        = toVec4(WithAlphaF(theme.onSurface, 0.03f));
    
    // Text
    colors[ImGuiCol_Text]                 = toVec4(theme.onSurface);
    colors[ImGuiCol_TextDisabled]         = toVec4(theme.onSurfaceDisabled);
    colors[ImGuiCol_TextSelectedBg]       = toVec4(WithAlphaF(theme.primary, 0.43f));
    
    // Drag/drop
    colors[ImGuiCol_DragDropTarget]       = toVec4(WithAlphaF(theme.secondary, 0.9f));
    
    // Navigation highlight
    colors[ImGuiCol_NavCursor]            = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
    colors[ImGuiCol_NavWindowingHighlight]= ImVec4(1, 1, 1, 0.7f);
    colors[ImGuiCol_NavWindowingDimBg]    = ImVec4(0.8f, 0.8f, 0.8f, 0.2f);
    
    // Modal window dim
    colors[ImGuiCol_ModalWindowDimBg]     = toVec4(theme.scrim);
    
    // Style adjustments (from UISchema)
    auto brElem = S.drawElement("style", "border-radius");
    style.WindowRounding    = brElem.extraFloats.count("window")    ? brElem.extraFloats.at("window")    : 6.0f;
    style.ChildRounding     = brElem.extraFloats.count("child")     ? brElem.extraFloats.at("child")     : 4.0f;
    style.FrameRounding     = brElem.extraFloats.count("frame")     ? brElem.extraFloats.at("frame")     : 4.0f;
    style.PopupRounding     = brElem.extraFloats.count("popup")     ? brElem.extraFloats.at("popup")     : 4.0f;
    style.ScrollbarRounding = brElem.extraFloats.count("scrollbar") ? brElem.extraFloats.at("scrollbar") : 4.0f;
    style.GrabRounding      = brElem.extraFloats.count("grab")      ? brElem.extraFloats.at("grab")      : 4.0f;
    style.TabRounding       = brElem.extraFloats.count("tab")       ? brElem.extraFloats.at("tab")       : 4.0f;
    
    style.WindowTitleAlign  = ImVec2(0.0f, 0.5f);  // Left-aligned titles (Material)
    auto sElem = [&](const char* key, float fb) {
        float v = S.drawElement("style", key).size;
        return v >= 0 ? v : fb;
    };
    style.WindowPadding     = ImVec2(sElem("window-padding-x", 10.0f), sElem("window-padding-y", 10.0f));
    style.FramePadding      = ImVec2(sElem("frame-padding-x", 8.0f), sElem("frame-padding-y", 4.0f));
    style.ItemSpacing       = ImVec2(sElem("item-spacing-x", 8.0f), sElem("item-spacing-y", 6.0f));
    style.ItemInnerSpacing  = ImVec2(sElem("item-inner-spacing-x", 6.0f), sElem("item-inner-spacing-y", 4.0f));
    style.IndentSpacing     = sElem("indent-spacing", 20.0f);
    
    style.ScrollbarSize     = sElem("scrollbar-size", 6.0f);
    style.GrabMinSize       = sElem("grab-min-size", 8.0f);
    
    auto bwElem = S.drawElement("style", "border-width");
    style.WindowBorderSize  = bwElem.extraFloats.count("window") ? bwElem.extraFloats.at("window") : 1.0f;
    style.ChildBorderSize   = bwElem.extraFloats.count("child")  ? bwElem.extraFloats.at("child")  : 1.0f;
    style.PopupBorderSize   = bwElem.extraFloats.count("popup")  ? bwElem.extraFloats.at("popup")  : 1.0f;
    // Light themes get a 1px frame border so inputs have a defined boundary on white/pastel surfaces;
    // dark themes stay borderless (their translucent glass FrameBg is enough). Schema can override.
    style.FrameBorderSize   = bwElem.extraFloats.count("frame")  ? bwElem.extraFloats.at("frame")
                              : (s_isDarkTheme ? 0.0f : 1.0f);
    style.TabBorderSize     = 0.0f;
    
    style.AntiAliasedLines  = true;
    style.AntiAliasedFill   = true;
}

} // namespace material
} // namespace ui
} // namespace dragonx
