import logging
import tkinter as tk
from tkinter.scrolledtext import ScrolledText

from tkinter_logger import TkinterLogger, get_logger


def test_tkinter_logger_integration(tmp_path):
    """Test that tkinter_logger from submodule works correctly."""
    try:
        root = tk.Tk()
        root.withdraw()
    except Exception:
        import pytest
        pytest.skip("Tk not available in this environment")
    
    text = ScrolledText(root, height=5, state=tk.DISABLED)
    
    try:
        # Setup logger system
        logger_system = TkinterLogger(root)
        logger_system.setup(enable_console=False)
        
        # Add tkinter handler
        logger_system.add_tkinter_handler(text, level_colors={logging.INFO: 'black'})
        
        # Get logger and log messages
        lg = get_logger('pyucc.test')
        lg.info('Hello logger')
        lg.error('Error here')
        
        # Wait for messages to be processed
        root.update_idletasks()
        root.after(300)  # Wait for processing
        root.update()
        
        # Check content
        content = text.get('1.0', 'end').strip()
        assert 'Hello logger' in content or 'Error here' in content
    finally:
        logger_system.shutdown()
        try:
            root.destroy()
        except Exception:
            pass


def test_get_logger_function():
    """Test that get_logger works correctly."""
    lg = get_logger('pyucc.test2')
    assert lg is not None
    assert lg.name == 'pyucc.test2'
