#!/usr/bin/env python3
"""
Simple HTTP server to view the Order Flow Explorer UI.
"""

import http.server
import socketserver
import os
from pathlib import Path

PORT = 8080
DIRECTORY = Path("/home/ubuntu/.hermes/workspace/projects/ORDER_FLOW_GRAPH/outputs")

class Handler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory=str(DIRECTORY), **kwargs)

    def end_headers(self):
        # Enable CORS
        self.send_header('Access-Control-Allow-Origin', '*')
        super().end_headers()

def start_server():
    os.chdir(DIRECTORY)

    with socketserver.TCPServer(("", PORT), Handler) as httpd:
        print("="*80)
        print("ORDER FLOW EXPLORER UI")
        print("="*80)
        print(f"\n✓ Server started at http://localhost:{PORT}")
        print(f"  Serving files from: {DIRECTORY}")
        print(f"\nOpen your browser and navigate to:")
        print(f"  http://localhost:{PORT}/order_flow_explorer.html")
        print(f"\nPress Ctrl+C to stop the server\n")
        print("="*80)

        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            print("\n✓ Server stopped")

if __name__ == "__main__":
    start_server()
