<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Lazy Load for Magento 2 (System)
 */-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Amasty\PageSpeedTools\Model\Output\ProcessorsResolver">
        <arguments>
            <argument name="defaultProcessors" xsi:type="array">
                <item name="lazyLoad_image_parser" xsi:type="array">
                    <item name="processor" xsi:type="object">Amasty\LazyLoad\Model\Output\LazyLoadImageParserProcessor</item>
                    <item name="sortOrder" xsi:type="number">2</item>
                </item>
                <item name="lazyLoad" xsi:type="array">
                    <item name="processor" xsi:type="object">Amasty\LazyLoad\Model\Output\LazyLoadProcessor</item>
                    <item name="sortOrder" xsi:type="number">40</item>
                </item>
            </argument>
            <argument name="customProcessors" xsi:type="array">
                <item name="esiProcessors" xsi:type="array">
                    <item name="checker" xsi:type="object">Amasty\PageSpeedTools\Model\Output\RequestChecker\EsiBlocksChecker\Proxy</item>
                    <item name="processors" xsi:type="array">
                        <item name="lazyLoad_image_parser" xsi:type="array">
                            <item name="processor" xsi:type="object">Amasty\LazyLoad\Model\Output\LazyLoadImageParserProcessor</item>
                            <item name="sortOrder" xsi:type="number">2</item>
                        </item>
                        <item name="lazyLoad" xsi:type="array">
                            <item name="processor" xsi:type="object">Amasty\LazyLoad\Model\Output\LazyLoadProcessor</item>
                            <item name="sortOrder" xsi:type="number">40</item>
                        </item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>

    <!-- Image Replace Configuration Start -->
    <!-- Patterns Config -->
    <virtualType name="Amasty\LazyLoad\Model\Image\ReplacePatterns\Gallery" type="Amasty\PageSpeedTools\Model\Image\ReplacePatterns\Common">
        <arguments>
            <argument name="name" xsi:type="string">lazyload_gallery</argument>
            <argument name="pattern" xsi:type="string"><![CDATA[\.(jpg|jpeg|png|gif$(?<any>[a-z\-_]+\s*\=\s*[\'\"](.*?)[\'\"].*?\s*))+.*?]]></argument>
            <argument name="groupByName" xsi:type="array"/>
            <argument name="baseAlgorithm" xsi:type="const">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\ImageFormatReplaceAlgorithm::ALGORITHM_NAME</argument>
            <argument name="replaceAllAttrs" xsi:type="boolean">false</argument>
        </arguments>
    </virtualType>
    <type name="Amasty\PageSpeedTools\Model\Image\ReplacePatternGroupsPool">
        <arguments>
            <argument name="replacePatternGroups" xsi:type="array">
                <item name="lazy_load" xsi:type="array">
                    <item name="img" sortOrder="10" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplacePatterns\Img</item>
                    <item name="background_image" sortOrder="20" xsi:type="object">Amasty\PageSpeedTools\Model\Image\ReplacePatterns\BackgroundImage</item>
                    <item name="page_builder" sortOrder="30" xsi:type="object">Amasty\PageSpeedTools\Model\Image\ReplacePatterns\PageBuilder</item>
                    <item name="background" sortOrder="40" xsi:type="object">Amasty\PageSpeedTools\Model\Image\ReplacePatterns\Background</item>
                </item>
                <item name="lazyload_gallery" xsi:type="array">
                    <item name="img" sortOrder="10" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplacePatterns\Gallery</item>
                </item>
            </argument>
        </arguments>
    </type>

    <!-- Algorithms Config -->
    <virtualType name="Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\BestReplaceAlgorithm" type="Amasty\PageSpeedTools\Model\Image\ReplaceAlgorithm\BestReplaceAlgorithm">
        <arguments>
            <argument name="checker" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\Checker\ReplaceBestChecker</argument>
        </arguments>
    </virtualType>
    <virtualType name="Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\PictureTagReplaceAlgorithm" type="Amasty\PageSpeedTools\Model\Image\ReplaceAlgorithm\PictureTagReplaceAlgorithm">
        <arguments>
            <argument name="checker" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\Checker\ReplacePictureChecker</argument>
        </arguments>
    </virtualType>
    <type name="Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\ImageFormatReplaceAlgorithm">
        <arguments>
            <argument name="checker" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\Checker\ReplaceBestChecker</argument>
        </arguments>
    </type>
    <type name="Amasty\PageSpeedTools\Model\Image\ReplaceAlgorithmResolver">
        <arguments>
            <argument name="replaceAlgorithms" xsi:type="array">
                <item name="lazyload_replace_with_best" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\BestReplaceAlgorithm</item>
                <item name="lazyload_replace_with_picture" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\PictureTagReplaceAlgorithm</item>
                <item name="lazyload_replace_with_image_format" xsi:type="object">Amasty\LazyLoad\Model\Image\ReplaceAlgorithm\ImageFormatReplaceAlgorithm</item>
            </argument>
        </arguments>
    </type>
    <!-- Image Replace Configuration End -->

    <type name="Amasty\LazyLoad\Model\LazyScript\LazyScriptProvider">
        <arguments>
            <argument name="lazyScripts" xsi:type="array">
                <item name="jquery" xsi:type="object">Amasty\LazyLoad\Model\LazyScript\Jquery</item>
                <item name="native" xsi:type="object">Amasty\LazyLoad\Model\LazyScript\NativeJs</item>
                <item name="vanilla" xsi:type="object">Amasty\LazyLoad\Model\LazyScript\Vanilla</item>
                <item name="lozad" xsi:type="object">Amasty\LazyLoad\Model\LazyScript\Lozad</item>
            </argument>
        </arguments>
    </type>

    <virtualType name="AmastyLazyLoadConfigPath" type="Amasty\PageSpeedTools\Model\Output\PageType\GetConfigPathByPageType">
        <arguments>
            <argument name="configPathsByPageType" xsi:type="array">
                <item name="cms_index_index" xsi:type="string">lazy_load_home</item>
                <item name="catalog_category_view" xsi:type="string">lazy_load_categories</item>
                <item name="catalog_product_view" xsi:type="string">lazy_load_products</item>
                <item name="cms_page_view" xsi:type="string">lazy_load_cms</item>
                <item name="general" xsi:type="string">lazy_load_general</item>
            </argument>
            <argument name="defaultConfigPath" xsi:type="string">lazy_load_general</argument>
        </arguments>
    </virtualType>

    <type name="Amasty\LazyLoad\Model\Output\LazyConfig\LazyConfig">
        <arguments>
            <argument name="getConfigPathByPageType" xsi:type="object">AmastyLazyLoadConfigPath</argument>
        </arguments>
    </type>

    <type name="Amasty\PageSpeedOptimizer\Model\OptionSource\ServerPushAssetTypes">
        <arguments>
            <argument name="assetTypes" xsi:type="array">
                <item name="preload_image" translatable="true" xsi:type="string">Preloaded Images</item>
            </argument>
        </arguments>
    </type>
    <type name="Amasty\PageSpeedOptimizer\Model\Asset\CollectorAdapter">
        <arguments>
            <argument name="collectors" xsi:type="array">
                <item name="preload_image" xsi:type="object">Amasty\LazyLoad\Model\Asset\Collector\PreloadImageCollector</item>
            </argument>
        </arguments>
    </type>
    <type name="Amasty\Fpc\Model\Queue\Combination\Provider">
        <arguments>
            <argument name="combinationSources" xsi:type="array">
                <item name="webp_and_device" xsi:type="object">Amasty\LazyLoad\Model\Crawler\Combination\WebpAndDeviceCombination</item>
            </argument>
        </arguments>
    </type>

    <type name="Amasty\MegaMenuLite\ViewModel\Tree">
        <plugin name="Amasty_LazyLoad::ProcessMegamenuContent" type="Amasty\LazyLoad\Plugin\MegaMenuLite\ViewModel\ProcessMegamenuContent"/>
    </type>
</config>
