from __future__ import annotations

import html
import json
import sys
from pathlib import Path
from typing import Any


def render(call: dict[str, Any]) -> str:
    if call["tool"] != "component_render":
        raise ValueError("expected component_render")

    args = call["args"]
    if args["kind"] != "confirm":
        raise ValueError("expected confirm component")

    props = args["props"]
    escape = lambda value: html.escape(str(value), quote=True)
    return "\n".join(
        [
            f'<section data-component="confirm" data-variant="{escape(props["variant"])}" data-id="{escape(args["id"])}">',
            f"  <h3>{escape(props['title'])}</h3>",
            f"  <p>{escape(props['body'])}</p>",
            "  <footer>",
            f'    <button data-action="cancel">{escape(props["cancel_label"])}</button>',
            f'    <button data-action="confirm">{escape(props["confirm_label"])}</button>',
            "  </footer>",
            "</section>",
        ]
    )


path = Path(sys.argv[1] if len(sys.argv) > 1 else "tool-call.json")
print(render(json.loads(path.read_text())))
