<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function() {
        document.querySelectorAll('[data-content-import-picker="microsoft"]').forEach(function (element) {
            let microsoftPicker = new MicrosoftPicker('{{ request.scheme }}://{{ request.get_host }}{% url 'wagtailcontentimport:wagtailcontentimport_microsoft:auth_view' %}', '{{ client_id|escapejs }}', element.dataset.createPageUrl, '{{ csrf_token|escapejs }}');

            element.addEventListener('click', function(e) {
                e.preventDefault();
                microsoftPicker.show();
            });
        });
    });
</script>
