<?xml version="1.0"?>
<!--
/**
 * Hyvä Themes - https://hyva.io
 * Copyright © Hyvä Themes. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <!-- Defer CSP hash calculation for inline scripts until after minification -->
    <type name="Hyva\Theme\ViewModel\HyvaCsp">
        <plugin name="hyva_minification_register_inline_script"
                type="Hyva\Minification\Plugin\RegisterInlineScriptPlugin"/>
    </type>

    <!-- Compute SHA-256 hashes from minified script content before CSP headers are written -->
    <type name="Magento\Csp\Api\CspRendererInterface">
        <plugin name="hyva_minification_csp_renderer"
                type="Hyva\Minification\Plugin\CspRendererPlugin"/>
    </type>

    <!-- Capture scripts from ESI-eligible blocks before they are replaced with <esi:include> tags.
         A before plugin on the PageCache ESI observer ensures we see the original block output
         before replacement, regardless of module loading order.
         Frontend-scoped because data-hyva-minification attributes only exist in storefront responses. -->
    <type name="Magento\PageCache\Observer\ProcessLayoutRenderElement">
        <plugin name="hyva_minification_capture_esi_scripts"
                type="Hyva\Minification\Plugin\CaptureEsiBlockScriptsPlugin"/>
    </type>

</config>
