<?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\Model\ViewModelRegistry;
use Hyva\Theme\ViewModel\ThemeLibrariesConfig;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/** @var Template $block */
/** @var Escaper $escaper */
/** @var ViewModelRegistry $viewModels */

$version = $viewModels->require(ThemeLibrariesConfig::class)->getVersionIdFor('alpine');

// Reason for the `crossorigin` attribute to be used:
//
// Normal script elements pass minimal information to the window.onerror for scripts which do not pass the standard CORS checks.
// To allow error logging for sites which use a separate domain for static media, the `crossorigin` attribute should be used.
//
// Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#crossorigin

?>

<?= $block->getChildHtml() ?>

<script type="module"
        src="<?= $escaper->escapeUrl($block->getViewFileUrl("Hyva_Theme::js/alpine{$version}.min.js")) ?>"
        defer
        crossorigin
></script>
