#!/usr/bin/env python3
"""Launch a local web GUI to build SeQUeNCe topology JSON files."""

from __future__ import annotations

import http.server
import socketserver
import webbrowser
from functools import partial
from pathlib import Path


PORT = 8765


def main() -> None:
    base_dir = Path(__file__).resolve().parent
    html_file = base_dir / "sequence_topology_builder.html"
    if not html_file.exists():
        raise SystemExit(f"Builder HTML not found: {html_file}")

    handler = partial(http.server.SimpleHTTPRequestHandler, directory=str(base_dir))
    with socketserver.TCPServer(("", PORT), handler) as httpd:
        print(f"SeQUeNCe Topology Builder running at http://127.0.0.1:{PORT}/sequence_topology_builder.html")
        print("Press Ctrl+C to stop.")
        webbrowser.open(f"http://127.0.0.1:{PORT}/sequence_topology_builder.html")
        httpd.serve_forever()


if __name__ == "__main__":
    main()
