<?php
/**
 * Hyvä Themes - https://hyva.io
 * Copyright © Hyvä Themes. All rights reserved.
 * See COPYING.txt for license details.
 */

declare(strict_types=1);

use Hyva\Theme\ViewModel\HyvaCsp;
use Magento\Framework\View\Element\Template;

/** @var HyvaCsp $hyvaCsp */
/** @var Template $block */

// Dispatch event to load external scripts after the first user interaction
?>
<script>
    (events => {
        const dispatchUserInteractionEvent = () => {
            events.forEach(type => window.removeEventListener(type, dispatchUserInteractionEvent))
            window.dispatchEvent(new Event('init-external-scripts'))
        };
        events.forEach(type => window.addEventListener(type, dispatchUserInteractionEvent, {once: true, passive: true}))
    })(['touchstart', 'mousemove', 'wheel', 'scroll', 'keydown']);
    //# sourceURL=hyva-init-external-scripts.js
</script>
<?php $hyvaCsp->registerInlineScript() ?>
