"""Serve cmux-ctl as a web application."""

from __future__ import annotations

import sys


def main() -> None:
    try:
        from textual_serve.server import Server
    except ImportError:
        print("textual-serve is required. Install with:")
        print("  pip install cmux-ctl[web]")
        sys.exit(1)

    import argparse

    parser = argparse.ArgumentParser(description="Serve cmux-ctl in the browser")
    parser.add_argument("--host", default="localhost", help="Host to bind to (default: localhost)")
    parser.add_argument("--port", type=int, default=8000, help="Port to bind to (default: 8000)")
    args = parser.parse_args()

    server = Server(
        f"{sys.executable} -m cmux_ctl",
        host=args.host,
        port=args.port,
        title="cmux-ctl",
    )
    server.serve()


if __name__ == "__main__":
    main()
