import pytest
import time
from src.api_hook_client import ApiHookClient

def test_usage_analytics_popout(live_gui):
 client = ApiHookClient()
 
 # 1. Check initial state
 state = client.get_gui_state()
 assert state.get("ui_separate_usage_analytics") is False
 
 # 2. Enable popout and ensure window is shown
 client.set_value("ui_separate_usage_analytics", True)
 # Manually set show_windows["Usage Analytics"] as well
 show_windows = state.get("show_windows", {})
 show_windows["Usage Analytics"] = True
 client.set_value("show_windows", show_windows)
 time.sleep(1)
 
 # 3. Verify state
 state = client.get_gui_state()
 assert state.get("ui_separate_usage_analytics") is True
 assert state.get("show_windows", {}).get("Usage Analytics") is True
 
 # 4. Disable popout
 client.set_value("ui_separate_usage_analytics", False)
 time.sleep(1)
 
 state = client.get_gui_state()
 assert state.get("ui_separate_usage_analytics") is False
