# target_simulator/__main__.py

"""
Main entry point for the Target Simulator application.

This script initializes the logging system, creates the main application
window, and starts the Tkinter event loop.
"""

import sys
import os

# Add the project root to the Python path to allow absolute imports
project_root = os.path.dirname(os.path.abspath(__file__))
if project_root not in sys.path:
    sys.path.insert(0, project_root)

from target_simulator.gui.main_view import MainView
from utils.logger import setup_basic_logging, get_logger, add_tkinter_handler

from config import LOGGING_CONFIG


def main():
    """Initializes and runs the application."""
    import logging

    logging.getLogger("matplotlib").setLevel(logging.WARNING)

    app = MainView()

    # Setup the global logging system, connecting it to the GUI's main loop
    setup_basic_logging(app, LOGGING_CONFIG)

    # Now that the logging system is active, add the handler for the GUI widget
    add_tkinter_handler(app.log_text_widget, LOGGING_CONFIG)

    logger = get_logger(__name__)
    logger.info("Application starting up.")

    app.mainloop()


if __name__ == "__main__":
    main()
