{#
 Define OptanonWrapper function on the global window object for consent tool to callback to
 This method is called when the page first loads and any time a users consent changes
#}

{% set consentScripts = consentGetScripts()|default([]) %}

{# Bolt loads the snippets before the scripts that is why we hvae load the script manually #}
<script src="{{ paths.root ~ "extensions/vendor/cnd/consent/js/cnconsent.js" }}"></script>

<script type="application/javascript">
    window.cnConsent = new CnConsent({
        scripts:  [
            {% for group, scripts in consentScripts %}
                {% for script in scripts %}
                    {
                        "url": "{{ script.uri|default }}",
                        "group": "{{ group|default }}",
                        "options": {{ script.options|default|json_encode|raw }}
                    },
                {% endfor %}
            {% endfor %}
        ]
    });

</script>