import pytest
from unittest.mock import MagicMock
from imgui_bundle import imgui
from src import theme_nerv

def test_apply_nerv_sets_rounding_and_colors(monkeypatch):
 # Mock imgui on the module level to intercept calls in apply_nerv
 mock_style = MagicMock()
 mock_imgui = MagicMock()
 mock_imgui.get_style.return_value = mock_style
 # Mock ImVec4 to return its arguments as a tuple to verify values
 mock_imgui.ImVec4.side_effect = lambda r, g, b, a=1.0: (r, g, b, a)
 
 monkeypatch.setattr(theme_nerv, "imgui", mock_imgui)

 # Call apply_nerv
 theme_nerv.apply_nerv()

 # Verify rounding styles (must be 0.0 for NERV theme)
 assert mock_style.window_rounding == 0.0
 assert mock_style.child_rounding == 0.0
 assert mock_style.frame_rounding == 0.0
 assert mock_style.popup_rounding == 0.0
 assert mock_style.scrollbar_rounding == 0.0
 assert mock_style.grab_rounding == 0.0
 assert mock_style.tab_rounding == 0.0

 # Verify borders
 assert mock_style.window_border_size == 1.0
 assert mock_style.frame_border_size == 1.0
 assert mock_style.popup_border_size == 1.0
 assert mock_style.child_border_size == 1.0
 assert mock_style.tab_border_size == 1.0

 # Verify key colors
 # window_bg should be BLACK (0, 0, 0, 1.0)
 # text should be STEEL (224/255.0, 224/255.0, 216/255.0, 1.0)
 # title_bg_active should be BLACK (0, 0, 0, 1.0)
 
 # Extract calls to set_color_
 # Using real imgui.Col_ values for keys because they are bound in NERV_PALETTE at import time
 color_calls = {call[0][0]: call[0][1] for call in mock_style.set_color_.call_args_list}
 
 assert imgui.Col_.window_bg in color_calls
 assert color_calls[imgui.Col_.window_bg] == (0.0, 0.0, 0.0, 1.0)
 
 assert imgui.Col_.text in color_calls
 assert color_calls[imgui.Col_.text] == (224/255.0, 224/255.0, 216/255.0, 1.0)

 assert imgui.Col_.title_bg_active in color_calls
 assert color_calls[imgui.Col_.title_bg_active] == (0.0, 0.0, 0.0, 1.0)
