"""
Atomizer Dashboard Launcher

Simple script to start the dashboard server and open the browser.
"""

import sys
import webbrowser
import time
from pathlib import Path
import subprocess

def main():
    dashboard_dir = Path(__file__).parent
    api_script = dashboard_dir / 'api' / 'app.py'

    print("="*60)
    print("ATOMIZER DASHBOARD LAUNCHER")
    print("="*60)
    print(f"\nStarting dashboard server...")
    print(f"Dashboard will open at: http://localhost:8080")
    print("\nPress Ctrl+C to stop the server")
    print("="*60)

    # Give user a moment to read
    time.sleep(2)

    # Open browser after a short delay
    def open_browser():
        time.sleep(3)  # Wait for server to start
        webbrowser.open('http://localhost:8080')

    import threading
    browser_thread = threading.Thread(target=open_browser, daemon=True)
    browser_thread.start()

    # Start the Flask server
    try:
        subprocess.run([sys.executable, str(api_script)], cwd=str(dashboard_dir))
    except KeyboardInterrupt:
        print("\n\nShutting down dashboard server...")
        print("Goodbye!")

if __name__ == '__main__':
    main()
