<?php

$id = Str::random(5);

$moduleHtml = '
    <div id="'.$id.'" class="review-summary"></div>

    <script>
        var '.$id.'_docReady = function (fn) {
            var stateCheck = setInterval(function () {
                if (document.readyState !== "complete") return;
                clearInterval(stateCheck);
                try {fn()} catch (e) {}
            }, 1000);
        };
        '.$id.'_docReady(function () {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState === XMLHttpRequest.DONE) {
                    if (xmlhttp.status === 200) {
                        let summaryContainer = document.getElementById("'.$id.'");
                        summaryContainer.innerHTML = xmlhttp.responseText;
                    }
                }
            };
            xmlhttp.open("GET", "/api/builder/review-summary", true);
            xmlhttp.send();
        });
    </script>
';

$moduleSettings = '{}';
?>

<div class="row clearfix border-0">
    <div class="col-12"
         data-noedit
         data-module="review-summary"
         data-module-desc="Review Summary"
         data-html="{{ encode_uri_component($moduleHtml) }}"
         data-settings="{{ encode_uri_component($moduleSettings) }}"
    >
    </div>
</div>
