<html>

<head>
    <link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
    <link type="text/css" href="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.css"
        rel="stylesheet" />
    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
    <script type="text/javascript"
        src="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.js"></script>
</head>

<body>
    {{ user_html }}
    <div id="form"></div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#form").alpaca({
                "data": {{ data }},
                "schema": {{ schema }},
                "options": {
                    "form": {
                        "buttons": {
                            "submit": {
                                "click": function() {
                                    var value = this.getValue();
                                    let data = JSON.stringify(value, null, "  ");
                                    // Post the data to {{ post_url }}
                                    fetch("{{ post_url }}", {
                                        method: "POST",
                                        body: data,
                                        headers: {
                                            "Content-Type": "application/json"
                                        }
                                    }).then(function(response) {
                                        console.log(response);
                                        location.reload();
                                    }).then(function(data) {
                                        console.log(data);
                                    });
                                }
                            }
                        }
                    },
                    "helper": "{{ helper }}",
                },
                "view": "bootstrap-edit"
            });
        });
    </script>
    
</body>

</html>