<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>NodeKit Preview Page</title>
    <link rel="shortcut icon" href="">

    <!-- NodeKit -->
    <script src="{{ nodekit_javascript_link }}"></script>
    <link href="{{ nodekit_css_link }}" rel="stylesheet">

    <script>
        const graph = {{ graph | tojson(indent=4) | indent(8, first=False) }};
        const eventSubmitUrl = "{{ submit_event_url }}";

        async function sendEvent(ev) {
            console.log(ev)
            try {
                await fetch(eventSubmitUrl, {
                    method: "POST",
                    headers: { "Content-Type": "application/json" },
                    body: JSON.stringify(ev),
                });
            } catch (err) {
                console.error("Failed to send event", err);
            }
        }

        window.onload = async () => {
            await NodeKit.play(
                graph,
                sendEvent
            );
        };
    </script>
</head>
<body></body>
</html>