//
// Custom player theme. Rebuilt every frame so it adapts to the album-art
// palette automatically. Near-zero corner rounding throughout.
//

ui_theme_init :: () {}

player_theme :: () -> Overall_Theme {
    // Pull colours from the current palette, fall back to deep violet.
    surface: Vector4;
    border:  Vector4;
    interact: Vector4;

    if app.palette_ready {
        // bg  → widget surface (slightly lightened so it reads as a surface)
        p0 := app.palette[0];
        surface  = .{p0.x * 1.6 + 0.04, p0.y * 1.6 + 0.02, p0.z * 1.6 + 0.06, 1};
        // highlight → interact colour
        p1 := app.palette[1];
        interact = .{p1.x * 0.75, p1.y * 0.75, p1.z * 0.75, 1};
        // mid → border
        p2 := app.palette[2];
        border   = .{p2.x * 0.45, p2.y * 0.45, p2.z * 0.45, 1};
    } else {
        surface  = .{0.09, 0.05, 0.15, 1};
        border   = .{0.24, 0.09, 0.42, 1};
        interact = .{0.52, 0.13, 0.78, 1};
    }

    text_lo :: Vector4.{0.75, 0.72, 0.90, 1};  // used internally by set_theme_from_base_colors
    text_hi :: Vector4.{1.00, 1.00, 1.00, 1};

    ROUNDING :: 0.0;   // Fully squared off — hardware aesthetic.

    result: Overall_Theme;
    set_theme_from_base_colors(*result, surface, border, interact, text_lo, text_hi);

    // Override the bluish text that set_theme_from_base_colors produces.
    // Match the album-label style from now_playing_view: palette[3] lightened,
    // or a pure neutral off-white when no palette is loaded.
    body_text: Vector4;
    if app.palette_ready {
        p := app.palette[3];
        body_text = .{p.x * 0.55 + 0.40, p.y * 0.55 + 0.40, p.z * 0.55 + 0.40, 1};
    } else {
        body_text = .{0.94, 0.94, 0.94, 1};   // neutral — no blue tint
    }
    WHITE :: Vector4.{1, 1, 1, 1};
    result.label_theme.text_color       = body_text;
    result.text_color                   = body_text;
    result.button_theme.text_color      = body_text;
    result.button_theme.text_color_over = WHITE;

    result.background_color        = ifx app.palette_ready
        then Vector4.{app.palette[0].x * 0.9, app.palette[0].y * 0.9, app.palette[0].z * 0.9, 1}
        else Vector4.{0.04, 0.02, 0.08, 1};
    result.background_color_bright = surface;

    result.button_theme.rectangle_shape.roundedness = ROUNDING;

    {
        using result.scrollable_region_theme;
        region_background.shape.roundedness      = ROUNDING;
        scrollbar_background.shape.roundedness   = ROUNDING;
        scrollbar_background.color               = result.background_color;
        scrollbar_background.frame_color         = border;
        scrollbar_nib_theme.surface_color        = border;
        scrollbar_nib_theme.surface_color_over   = interact;
        scrollbar_nib_theme.surface_color_down   = interact;
        scrollbar_nib_theme.frame_color          = border;
        scrollbar_nib_theme.frame_color_over     = interact;
        scrollbar_nib_theme.rectangle_shape.roundedness = ROUNDING;
    }

    {
        using result.slider_theme;
        foreground.surface_color       = interact;
        foreground.surface_color_over  = .{min(interact.x+0.12,1), min(interact.y+0.12,1), min(interact.z+0.12,1), 1};
        foreground.surface_color_flash = foreground.surface_color_over;
        foreground.surface_color_down  = interact;
        foreground.frame_color         = .{interact.x*0.55, interact.y*0.55, interact.z*0.55, 1};
        foreground.frame_color_over    = interact;
        foreground.text_color          = text_hi;
        foreground.rectangle_shape.roundedness   = ROUNDING;

        background.surface_color       = result.background_color;
        background.surface_color_over  = result.background_color;
        background.frame_color         = border;
        background.frame_color_over    = border;
        background.rectangle_shape.roundedness   = ROUNDING;
    }

    {
        using result.text_input_theme;
        surface_color       = .{surface.x * 0.7, surface.y * 0.7, surface.z * 0.7, 1};
        surface_color_over  = surface;
        frame_color         = border;
        frame_color_over    = interact;
        rectangle_shape.roundedness = ROUNDING;
        text_color          = text_hi;
        text_color_over     = text_hi;
        selection_color     = interact;
    }

    return result;
}
