from imgui_bundle import imgui

def draw_soft_shadow(draw_list: imgui.ImDrawList, p_min: imgui.ImVec2, p_max: imgui.ImVec2, color: imgui.ImVec4, shadow_size: float = 10.0, rounding: float = 0.0) -> None:
    """
    Simulates a soft shadow effect by drawing multiple concentric rounded rectangles
    with decreasing alpha values. This is a faux-shader effect using primitive batching.
    """
    r, g, b, a = color.x, color.y, color.z, color.w
    steps = int(shadow_size)
    if steps <= 0:
        return
        
    alpha_step = a / steps
    
    for i in range(steps):
        current_alpha = a - (i * alpha_step)
        # Apply an easing function (e.g., cubic) for a smoother shadow falloff
        current_alpha = current_alpha * (1.0 - (i / steps)**2) 
        
        if current_alpha <= 0.01:
            continue
            
        expand = float(i)
        
        c_min = imgui.ImVec2(p_min.x - expand, p_min.y - expand)
        c_max = imgui.ImVec2(p_max.x + expand, p_max.y + expand)
        
        u32_color = imgui.get_color_u32(imgui.ImVec4(r, g, b, current_alpha))
        
        draw_list.add_rect(
            c_min, 
            c_max, 
            u32_color, 
            rounding + expand if rounding > 0 else 0.0, 
            flags=imgui.ImDrawFlags_.round_corners_all if rounding > 0 else imgui.ImDrawFlags_.none,
            thickness=1.0
        )

def apply_faux_acrylic_glass(draw_list: imgui.ImDrawList, p_min: imgui.ImVec2, p_max: imgui.ImVec2, base_color: imgui.ImVec4, rounding: float = 0.0) -> None:
    """
    Simulates a faux acrylic/glass effect by drawing a semi-transparent base,
    a gradient overlay for 'shine', and a subtle inner border for 'edge glow'.
    """
    r, g, b, a = base_color.x, base_color.y, base_color.z, base_color.w
    
    # 1. Base tinted semi-transparent fill (fake blur base)
    fill_color = imgui.get_color_u32(imgui.ImVec4(r, g, b, a * 0.7))
    draw_list.add_rect_filled(
        p_min, p_max, fill_color, rounding,
        flags=imgui.ImDrawFlags_.round_corners_all if rounding > 0 else imgui.ImDrawFlags_.none
    )
    
    # 2. Gradient overlay to simulate light scattering (acrylic reflection)
    shine_top = imgui.get_color_u32(imgui.ImVec4(1.0, 1.0, 1.0, 0.15))
    shine_bot = imgui.get_color_u32(imgui.ImVec4(1.0, 1.0, 1.0, 0.0))
    # We can't do rounded corners with add_rect_filled_multicolor easily, but we can do it with clip rects or just draw it directly if rounding=0
    # For now, we'll just draw a subtle overlay in the upper half
    if rounding == 0:
        draw_list.add_rect_filled_multicolor(
            p_min, imgui.ImVec2(p_max.x, p_min.y + (p_max.y - p_min.y) * 0.5),
            shine_top, shine_top, shine_bot, shine_bot
        )
    
    # 3. Inner bright border to simulate "glass edge" refraction
    inner_glow = imgui.get_color_u32(imgui.ImVec4(1.0, 1.0, 1.0, 0.2))
    draw_list.add_rect(
        imgui.ImVec2(p_min.x + 1, p_min.y + 1),
        imgui.ImVec2(p_max.x - 1, p_max.y - 1),
        inner_glow, rounding,
        flags=imgui.ImDrawFlags_.round_corners_all if rounding > 0 else imgui.ImDrawFlags_.none,
        thickness=1.0
    )

